|
|
|
|
@ -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
|
|
|
|
|
|