expire download links
This commit is contained in:
@@ -11,7 +11,7 @@ module Submitters
|
||||
module_function
|
||||
|
||||
def call(submitter, with_template: false, with_events: false, with_documents: true, with_urls: false,
|
||||
with_values: true, params: {})
|
||||
with_values: true, params: {}, expires_at: Accounts.link_expires_at(Account.new(id: submitter.account_id)))
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [submitter],
|
||||
associations: if with_documents
|
||||
@@ -24,15 +24,19 @@ module Submitters
|
||||
additional_attrs = {}
|
||||
|
||||
if params[:include].to_s.include?('fields')
|
||||
additional_attrs['fields'] = SerializeForWebhook.build_fields_array(submitter)
|
||||
additional_attrs['fields'] = SerializeForWebhook.build_fields_array(submitter, expires_at:)
|
||||
end
|
||||
|
||||
if with_template
|
||||
additional_attrs['template'] = submitter.submission.template.as_json(only: %i[id name created_at updated_at])
|
||||
end
|
||||
|
||||
additional_attrs['values'] = SerializeForWebhook.build_values_array(submitter) if with_values
|
||||
additional_attrs['documents'] = SerializeForWebhook.build_documents_array(submitter) if with_documents
|
||||
additional_attrs['values'] = SerializeForWebhook.build_values_array(submitter, expires_at:) if with_values
|
||||
|
||||
if with_documents
|
||||
additional_attrs['documents'] = SerializeForWebhook.build_documents_array(submitter, expires_at:)
|
||||
end
|
||||
|
||||
additional_attrs['preferences'] = submitter.preferences.except('default_values')
|
||||
additional_attrs['submission_events'] = serialize_events(submitter.submission_events) if with_events
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ module Submitters
|
||||
|
||||
module_function
|
||||
|
||||
def call(submitter)
|
||||
def call(submitter, expires_at: Accounts.link_expires_at(Account.new(id: submitter.account_id)))
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [submitter], associations: [documents_attachments: :blob, attachments_attachments: :blob]
|
||||
).call
|
||||
|
||||
values = build_values_array(submitter)
|
||||
documents = build_documents_array(submitter)
|
||||
values = build_values_array(submitter, expires_at:)
|
||||
documents = build_documents_array(submitter, expires_at:)
|
||||
|
||||
submission = submitter.submission
|
||||
|
||||
@@ -32,7 +32,7 @@ module Submitters
|
||||
'preferences' => submitter.preferences.except('default_values'),
|
||||
'values' => values,
|
||||
'documents' => documents,
|
||||
'audit_log_url' => submitter.submission.audit_log_url,
|
||||
'audit_log_url' => submitter.submission.audit_log_url(expires_at:),
|
||||
'submission_url' => r.submissions_preview_url(submission.slug, **Docuseal.default_url_options),
|
||||
'template' => submission.template.as_json(
|
||||
only: %i[id name external_id created_at updated_at],
|
||||
@@ -40,15 +40,15 @@ module Submitters
|
||||
),
|
||||
'submission' => {
|
||||
'id' => submission.id,
|
||||
'audit_log_url' => submission.audit_log_url,
|
||||
'combined_document_url' => submission.combined_document_url,
|
||||
'audit_log_url' => submission.audit_log_url(expires_at:),
|
||||
'combined_document_url' => submission.combined_document_url(expires_at:),
|
||||
'status' => build_submission_status(submission),
|
||||
'url' => r.submissions_preview_url(submission.slug, **Docuseal.default_url_options),
|
||||
'created_at' => submission.created_at.as_json
|
||||
})
|
||||
end
|
||||
|
||||
def build_values_array(submitter)
|
||||
def build_values_array(submitter, expires_at: nil)
|
||||
fields = submitter.submission.template_fields.presence || submitter.submission&.template&.fields || []
|
||||
attachments_index = submitter.attachments.index_by(&:uuid)
|
||||
submitter_field_counters = Hash.new { 0 }
|
||||
@@ -64,13 +64,13 @@ module Submitters
|
||||
|
||||
next if !submitter.values.key?(field['uuid']) && !submitter.completed_at?
|
||||
|
||||
value = fetch_field_value(field, submitter.values[field['uuid']], attachments_index)
|
||||
value = fetch_field_value(field, submitter.values[field['uuid']], attachments_index, expires_at:)
|
||||
|
||||
{ 'field' => field_name, 'value' => value }
|
||||
end
|
||||
end
|
||||
|
||||
def build_fields_array(submitter)
|
||||
def build_fields_array(submitter, expires_at: nil)
|
||||
fields = submitter.submission.template_fields.presence || submitter.submission&.template&.fields || []
|
||||
attachments_index = submitter.attachments.index_by(&:uuid)
|
||||
submitter_field_counters = Hash.new { 0 }
|
||||
@@ -86,7 +86,7 @@ module Submitters
|
||||
|
||||
next if !submitter.values.key?(field['uuid']) && !submitter.completed_at?
|
||||
|
||||
value = fetch_field_value(field, submitter.values[field['uuid']], attachments_index)
|
||||
value = fetch_field_value(field, submitter.values[field['uuid']], attachments_index, expires_at:)
|
||||
|
||||
{ 'name' => field_name, 'uuid' => field['uuid'], 'value' => value, 'readonly' => field['readonly'] == true }
|
||||
end
|
||||
@@ -104,26 +104,26 @@ module Submitters
|
||||
end
|
||||
end
|
||||
|
||||
def build_documents_array(submitter)
|
||||
def build_documents_array(submitter, expires_at: nil)
|
||||
submitter.documents.map do |attachment|
|
||||
{ 'name' => attachment.filename.base, 'url' => rails_storage_proxy_url(attachment) }
|
||||
{ 'name' => attachment.filename.base, 'url' => rails_storage_proxy_url(attachment, expires_at:) }
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_field_value(field, value, attachments_index)
|
||||
def fetch_field_value(field, value, attachments_index, expires_at: nil)
|
||||
if field['type'].in?(%w[image signature initials stamp payment])
|
||||
rails_storage_proxy_url(attachments_index[value])
|
||||
rails_storage_proxy_url(attachments_index[value], expires_at:)
|
||||
elsif field['type'] == 'file'
|
||||
Array.wrap(value).compact_blank.filter_map { |e| rails_storage_proxy_url(attachments_index[e]) }
|
||||
Array.wrap(value).compact_blank.filter_map { |e| rails_storage_proxy_url(attachments_index[e], expires_at:) }
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
def rails_storage_proxy_url(attachment)
|
||||
def rails_storage_proxy_url(attachment, expires_at: nil)
|
||||
return if attachment.blank?
|
||||
|
||||
ActiveStorage::Blob.proxy_url(attachment.blob)
|
||||
ActiveStorage::Blob.proxy_url(attachment.blob, expires_at:)
|
||||
end
|
||||
|
||||
def r
|
||||
|
||||
Reference in New Issue
Block a user