| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -10,13 +10,13 @@ module Submitters
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    module_function
 | 
					 | 
					 | 
					 | 
					    module_function
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def call(submitter)
 | 
					 | 
					 | 
					 | 
					    def call(submitter, expires_at: Accounts.link_expires_at(Account.new(id: submitter.account_id)))
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      ActiveRecord::Associations::Preloader.new(
 | 
					 | 
					 | 
					 | 
					      ActiveRecord::Associations::Preloader.new(
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        records: [submitter], associations: [documents_attachments: :blob, attachments_attachments: :blob]
 | 
					 | 
					 | 
					 | 
					        records: [submitter], associations: [documents_attachments: :blob, attachments_attachments: :blob]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      ).call
 | 
					 | 
					 | 
					 | 
					      ).call
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      values = build_values_array(submitter)
 | 
					 | 
					 | 
					 | 
					      values = build_values_array(submitter, expires_at:)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      documents = build_documents_array(submitter)
 | 
					 | 
					 | 
					 | 
					      documents = build_documents_array(submitter, expires_at:)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      submission = submitter.submission
 | 
					 | 
					 | 
					 | 
					      submission = submitter.submission
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -32,7 +32,7 @@ module Submitters
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                      'preferences' => submitter.preferences.except('default_values'),
 | 
					 | 
					 | 
					 | 
					                      'preferences' => submitter.preferences.except('default_values'),
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                      'values' => values,
 | 
					 | 
					 | 
					 | 
					                      'values' => values,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                      'documents' => documents,
 | 
					 | 
					 | 
					 | 
					                      '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),
 | 
					 | 
					 | 
					 | 
					                      'submission_url' => r.submissions_preview_url(submission.slug, **Docuseal.default_url_options),
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                      'template' => submission.template.as_json(
 | 
					 | 
					 | 
					 | 
					                      'template' => submission.template.as_json(
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        only: %i[id name external_id created_at updated_at],
 | 
					 | 
					 | 
					 | 
					                        only: %i[id name external_id created_at updated_at],
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -40,15 +40,15 @@ module Submitters
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                      ),
 | 
					 | 
					 | 
					 | 
					                      ),
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                      'submission' => {
 | 
					 | 
					 | 
					 | 
					                      'submission' => {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        'id' => submission.id,
 | 
					 | 
					 | 
					 | 
					                        'id' => submission.id,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        'audit_log_url' => submission.audit_log_url,
 | 
					 | 
					 | 
					 | 
					                        'audit_log_url' => submission.audit_log_url(expires_at:),
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        'combined_document_url' => submission.combined_document_url,
 | 
					 | 
					 | 
					 | 
					                        'combined_document_url' => submission.combined_document_url(expires_at:),
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        'status' => build_submission_status(submission),
 | 
					 | 
					 | 
					 | 
					                        'status' => build_submission_status(submission),
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        'url' => r.submissions_preview_url(submission.slug, **Docuseal.default_url_options),
 | 
					 | 
					 | 
					 | 
					                        'url' => r.submissions_preview_url(submission.slug, **Docuseal.default_url_options),
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        'created_at' => submission.created_at.as_json
 | 
					 | 
					 | 
					 | 
					                        'created_at' => submission.created_at.as_json
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                      })
 | 
					 | 
					 | 
					 | 
					                      })
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    end
 | 
					 | 
					 | 
					 | 
					    end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def build_values_array(submitter)
 | 
					 | 
					 | 
					 | 
					    def build_values_array(submitter, expires_at: nil)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      fields = submitter.submission.template_fields.presence || submitter.submission&.template&.fields || []
 | 
					 | 
					 | 
					 | 
					      fields = submitter.submission.template_fields.presence || submitter.submission&.template&.fields || []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      attachments_index = submitter.attachments.index_by(&:uuid)
 | 
					 | 
					 | 
					 | 
					      attachments_index = submitter.attachments.index_by(&:uuid)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      submitter_field_counters = Hash.new { 0 }
 | 
					 | 
					 | 
					 | 
					      submitter_field_counters = Hash.new { 0 }
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -64,13 +64,13 @@ module Submitters
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        next if !submitter.values.key?(field['uuid']) && !submitter.completed_at?
 | 
					 | 
					 | 
					 | 
					        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 }
 | 
					 | 
					 | 
					 | 
					        { 'field' => field_name, 'value' => value }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end
 | 
					 | 
					 | 
					 | 
					      end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    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 || []
 | 
					 | 
					 | 
					 | 
					      fields = submitter.submission.template_fields.presence || submitter.submission&.template&.fields || []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      attachments_index = submitter.attachments.index_by(&:uuid)
 | 
					 | 
					 | 
					 | 
					      attachments_index = submitter.attachments.index_by(&:uuid)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      submitter_field_counters = Hash.new { 0 }
 | 
					 | 
					 | 
					 | 
					      submitter_field_counters = Hash.new { 0 }
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -86,7 +86,7 @@ module Submitters
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        next if !submitter.values.key?(field['uuid']) && !submitter.completed_at?
 | 
					 | 
					 | 
					 | 
					        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 }
 | 
					 | 
					 | 
					 | 
					        { 'name' => field_name, 'uuid' => field['uuid'], 'value' => value, 'readonly' => field['readonly'] == true }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end
 | 
					 | 
					 | 
					 | 
					      end
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -104,26 +104,26 @@ module Submitters
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end
 | 
					 | 
					 | 
					 | 
					      end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    end
 | 
					 | 
					 | 
					 | 
					    end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def build_documents_array(submitter)
 | 
					 | 
					 | 
					 | 
					    def build_documents_array(submitter, expires_at: nil)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      submitter.documents.map do |attachment|
 | 
					 | 
					 | 
					 | 
					      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
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    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])
 | 
					 | 
					 | 
					 | 
					      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'
 | 
					 | 
					 | 
					 | 
					      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
 | 
					 | 
					 | 
					 | 
					      else
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        value
 | 
					 | 
					 | 
					 | 
					        value
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      end
 | 
					 | 
					 | 
					 | 
					      end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    end
 | 
					 | 
					 | 
					 | 
					    end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def rails_storage_proxy_url(attachment)
 | 
					 | 
					 | 
					 | 
					    def rails_storage_proxy_url(attachment, expires_at: nil)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      return if attachment.blank?
 | 
					 | 
					 | 
					 | 
					      return if attachment.blank?
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					      ActiveStorage::Blob.proxy_url(attachment.blob)
 | 
					 | 
					 | 
					 | 
					      ActiveStorage::Blob.proxy_url(attachment.blob, expires_at:)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    end
 | 
					 | 
					 | 
					 | 
					    end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def r
 | 
					 | 
					 | 
					 | 
					    def r
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |