mirror of
https://github.com/docusealco/docuseal
synced 2026-11-04 14:42:32 -05:00
refactor prefill
This commit is contained in:
1 parent
439f95d87e
commit
2d6f4c521e
13 files changed
+247
-128
No files matched your search
@@ -129,6 +129,13 @@ module Submitters
|
||||
ActiveStorage::Attachment.create!(blob:, name: 'attachments', record: submitter)
|
||||
end
|
||||
|
||||
def build_prefill_attachment_data(submitter, attachment)
|
||||
token = ApplicationRecord.signed_id_verifier.generate([attachment.uuid, submitter.slug],
|
||||
purpose: :prefill_attachment)
|
||||
|
||||
{ token:, url: attachment.url }
|
||||
end
|
||||
|
||||
def normalize_preferences(account, user, params)
|
||||
preferences = {}
|
||||
|
||||
|
||||
+13
-21
@@ -1,30 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Submitters
|
||||
module MaybeAssignDefaultBrowserSignature
|
||||
SIGNED_UUID_PURPPOSE = 'signature'
|
||||
module FindRememberedSignature
|
||||
SIGNED_UUID_PURPOSE = 'signature'
|
||||
|
||||
module_function
|
||||
|
||||
def call(submitter, params, cookies = nil, attachments = [])
|
||||
attachments = attachments.select { |e| e.record_id == submitter.id && e.record_type == 'Submitter' }
|
||||
|
||||
def call(submitter, params, cookies = nil)
|
||||
if params[:signed_signature_uuids].present?
|
||||
find_storage_signature(submitter, params[:signed_signature_uuids], attachments)
|
||||
find_storage_signature(submitter, params[:signed_signature_uuids])
|
||||
elsif cookies
|
||||
find_session_signature(submitter, cookies, attachments)
|
||||
find_session_signature(submitter, cookies)
|
||||
end
|
||||
end
|
||||
|
||||
def sign_signature_uuid(uuid)
|
||||
ApplicationRecord.signed_id_verifier.generate(uuid, purpose: SIGNED_UUID_PURPPOSE)
|
||||
ApplicationRecord.signed_id_verifier.generate(uuid, purpose: SIGNED_UUID_PURPOSE)
|
||||
end
|
||||
|
||||
def verify_signature_uuid(signed_uuid)
|
||||
ApplicationRecord.signed_id_verifier.verified(signed_uuid, purpose: SIGNED_UUID_PURPPOSE)
|
||||
ApplicationRecord.signed_id_verifier.verified(signed_uuid, purpose: SIGNED_UUID_PURPOSE)
|
||||
end
|
||||
|
||||
def find_storage_signature(submitter, signed_uuids, attachments)
|
||||
def find_storage_signature(submitter, signed_uuids)
|
||||
signed_uuid = signed_uuids[submitter.email]
|
||||
|
||||
return if signed_uuid.blank?
|
||||
@@ -33,10 +31,10 @@ module Submitters
|
||||
|
||||
return if uuid.blank?
|
||||
|
||||
find_signature_from_uuid(submitter, uuid, attachments)
|
||||
find_signature_from_uuid(submitter, uuid)
|
||||
end
|
||||
|
||||
def find_session_signature(submitter, cookies, attachments)
|
||||
def find_session_signature(submitter, cookies)
|
||||
values =
|
||||
begin
|
||||
JSON.parse(cookies.encrypted[:signature_uuids].presence || '{}')
|
||||
@@ -50,23 +48,17 @@ module Submitters
|
||||
|
||||
return if uuid.blank?
|
||||
|
||||
find_signature_from_uuid(submitter, uuid, attachments)
|
||||
find_signature_from_uuid(submitter, uuid)
|
||||
end
|
||||
|
||||
def find_signature_from_uuid(submitter, uuid, attachments)
|
||||
def find_signature_from_uuid(submitter, uuid)
|
||||
signature_attachment = ActiveStorage::Attachment.find_by(uuid:)
|
||||
|
||||
return unless signature_attachment
|
||||
|
||||
return if signature_attachment.record.email != submitter.email
|
||||
|
||||
existing_attachment = attachments.find do |a|
|
||||
a.blob_id == signature_attachment.blob_id && submitter.id == a.record_id
|
||||
end
|
||||
|
||||
return existing_attachment if existing_attachment
|
||||
|
||||
submitter.attachments_attachments.create_or_find_by!(blob_id: signature_attachment.blob_id)
|
||||
signature_attachment
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,45 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Submitters
|
||||
module MaybeUpdateDefaultValues
|
||||
module_function
|
||||
|
||||
def call(submitter, current_user)
|
||||
return if current_user.blank? || current_user.email != submitter.email
|
||||
|
||||
user = current_user
|
||||
|
||||
fields = submitter.submission.template_fields || submitter.submission.template.fields
|
||||
|
||||
fields.each do |field|
|
||||
next if field['submitter_uuid'] != submitter.uuid
|
||||
|
||||
default_value = get_default_value_for_field(field, user, submitter)
|
||||
|
||||
submitter.values[field['uuid']] ||= default_value if default_value.present?
|
||||
end
|
||||
|
||||
submitter.save!
|
||||
end
|
||||
|
||||
def get_default_value_for_field(field, user, submitter)
|
||||
field_name = field['name'].to_s.downcase
|
||||
|
||||
if field_name.in?(['full name', 'legal name'])
|
||||
user.full_name
|
||||
elsif field_name == 'first name'
|
||||
user.first_name
|
||||
elsif field_name == 'last name'
|
||||
user.last_name
|
||||
elsif field['type'] == 'initials' && (initials = UserConfigs.load_initials(user))
|
||||
attachment = ActiveStorage::Attachment.find_or_create_by!(
|
||||
blob_id: initials.blob_id,
|
||||
name: 'attachments',
|
||||
record: submitter
|
||||
)
|
||||
|
||||
attachment.uuid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -54,10 +54,6 @@ module Submitters
|
||||
reason_field = maybe_set_signature_reason!(values, submitter, params)
|
||||
validate_values!(reason_field ? values.except(reason_field['uuid']) : values, submitter, params, request)
|
||||
|
||||
if (touch_attachment_uuid = params[:touch_attachment_uuid].presence)
|
||||
ActiveStorage::Attachment.where(uuid: touch_attachment_uuid, record: submitter).touch_all(:created_at)
|
||||
end
|
||||
|
||||
if params[:completed] == 'true'
|
||||
maybe_invite_via_field(submitter, request)
|
||||
|
||||
|
||||
Reference in new issue
Block a user