Files
docuseal/app/controllers/submissions_download_controller.rb
T

53 lines
1.3 KiB
Ruby
Raw Normal View History

2023-05-21 17:59:36 +03:00
# frozen_string_literal: true
class SubmissionsDownloadController < ApplicationController
skip_before_action :authenticate_user!
2023-09-17 00:45:57 +03:00
skip_authorization_check
2023-05-21 17:59:36 +03:00
2024-02-25 02:00:18 +02:00
TTL = 40.minutes
2024-02-18 19:29:14 +02:00
2023-05-21 17:59:36 +03:00
def index
2026-04-10 11:07:19 +03:00
@submission = Submission.find_by!(slug: params[:submission_slug] || params[:submissions_preview_slug])
2024-02-25 02:00:18 +02:00
2026-04-10 11:07:19 +03:00
last_submitter = @submission.submitters.where.not(completed_at: nil).order(:completed_at).last
2025-03-25 15:34:37 +02:00
Submissions::EnsureResultGenerated.call(last_submitter)
2024-02-18 19:29:14 +02:00
2026-04-10 11:07:19 +03:00
unless current_user_submitter?(last_submitter)
unless Submitters::AuthorizedForForm.call(last_submitter, current_user, request)
Rollbar.info("2FA download error: #{last_submitter.id}") if defined?(Rollbar)
return head :not_found
end
2024-02-18 19:29:14 +02:00
2026-02-14 16:31:34 +02:00
if last_submitter.completed_at < TTL.ago
Rollbar.info("TTL: #{last_submitter.id}") if defined?(Rollbar)
return head :not_found
end
2024-02-18 19:29:14 +02:00
end
2024-08-23 23:46:22 +03:00
if params[:combined] == 'true'
2026-02-14 16:31:34 +02:00
respond_with_combined(last_submitter)
2024-05-25 20:57:36 +03:00
else
2026-04-10 11:07:19 +03:00
render json: Submitters.build_document_urls(last_submitter)
2024-05-25 20:57:36 +03:00
end
2024-02-25 02:00:18 +02:00
end
2023-06-22 01:31:39 +03:00
2024-02-25 02:00:18 +02:00
private
2026-02-14 16:31:34 +02:00
def respond_with_combined(submitter)
2026-04-10 11:07:19 +03:00
url = Submitters.build_combined_url(submitter)
2026-02-14 16:31:34 +02:00
if url
render json: [url]
else
head :not_found
end
end
2024-02-25 02:00:18 +02:00
def current_user_submitter?(submitter)
2026-02-14 19:13:05 +02:00
current_user && current_ability.can?(:read, submitter)
2024-02-25 02:00:18 +02:00
end
2023-05-21 17:59:36 +03:00
end