2023-12-02 16:26:34 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
module Submitters
|
|
|
|
|
module FormConfigs
|
2024-03-09 23:29:59 +02:00
|
|
|
DEFAULT_KEYS = [AccountConfig::FORM_COMPLETED_BUTTON_KEY,
|
2024-04-05 16:16:30 +03:00
|
|
|
AccountConfig::FORM_COMPLETED_MESSAGE_KEY,
|
2024-03-09 23:29:59 +02:00
|
|
|
AccountConfig::FORM_WITH_CONFETTI_KEY,
|
2024-06-15 15:55:09 +03:00
|
|
|
AccountConfig::FORM_PREFILL_SIGNATURE_KEY,
|
2024-07-24 20:55:35 +03:00
|
|
|
AccountConfig::WITH_SIGNATURE_ID,
|
2024-10-24 12:15:32 +03:00
|
|
|
AccountConfig::ALLOW_TO_DECLINE_KEY,
|
2026-03-27 12:56:52 +02:00
|
|
|
AccountConfig::ALLOW_TO_DELEGATE_KEY,
|
2025-03-27 18:29:02 +02:00
|
|
|
AccountConfig::ENFORCE_SIGNING_ORDER_KEY,
|
2024-08-06 00:19:33 +03:00
|
|
|
AccountConfig::REQUIRE_SIGNING_REASON_KEY,
|
2024-10-10 13:14:49 +03:00
|
|
|
AccountConfig::REUSE_SIGNATURE_KEY,
|
2025-12-16 11:38:37 +02:00
|
|
|
AccountConfig::WITH_FIELD_LABELS_KEY,
|
2025-06-06 16:23:44 +03:00
|
|
|
AccountConfig::ALLOW_TO_PARTIAL_DOWNLOAD_KEY,
|
2024-11-29 19:49:44 +02:00
|
|
|
AccountConfig::ALLOW_TYPED_SIGNATURE,
|
2025-07-18 10:30:37 +03:00
|
|
|
AccountConfig::WITH_SUBMITTER_TIMEZONE_KEY,
|
2026-02-17 17:45:46 +02:00
|
|
|
AccountConfig::WITH_TIMESTAMP_SECONDS_KEY,
|
2025-07-18 10:30:37 +03:00
|
|
|
AccountConfig::WITH_SIGNATURE_ID_REASON_KEY,
|
2026-07-14 12:47:38 +03:00
|
|
|
AccountConfig::WITH_SIGNATURE_ID_COMPLETED_AT_KEY,
|
2024-11-29 19:49:44 +02:00
|
|
|
*(Docuseal.multitenant? ? [] : [AccountConfig::POLICY_LINKS_KEY])].freeze
|
2024-03-09 23:29:59 +02:00
|
|
|
|
2023-12-02 16:26:34 +02:00
|
|
|
module_function
|
|
|
|
|
|
2024-03-09 23:29:59 +02:00
|
|
|
def call(submitter, keys = [])
|
2024-06-15 15:55:09 +03:00
|
|
|
configs = submitter.submission.account.account_configs.where(key: DEFAULT_KEYS + keys)
|
2023-12-02 16:26:34 +02:00
|
|
|
|
2024-06-15 15:55:09 +03:00
|
|
|
completed_button = find_safe_value(configs, AccountConfig::FORM_COMPLETED_BUTTON_KEY) || {}
|
|
|
|
|
completed_message = find_safe_value(configs, AccountConfig::FORM_COMPLETED_MESSAGE_KEY) || {}
|
|
|
|
|
with_typed_signature = find_safe_value(configs, AccountConfig::ALLOW_TYPED_SIGNATURE) != false
|
2026-03-28 16:33:21 +02:00
|
|
|
with_confetti = find_safe_value(configs, AccountConfig::FORM_WITH_CONFETTI_KEY) == true
|
2024-06-15 15:55:09 +03:00
|
|
|
prefill_signature = find_safe_value(configs, AccountConfig::FORM_PREFILL_SIGNATURE_KEY) != false
|
2024-10-10 13:14:49 +03:00
|
|
|
reuse_signature = find_safe_value(configs, AccountConfig::REUSE_SIGNATURE_KEY) != false
|
2024-10-24 12:15:32 +03:00
|
|
|
with_decline = find_safe_value(configs, AccountConfig::ALLOW_TO_DECLINE_KEY) != false
|
2026-03-27 12:56:52 +02:00
|
|
|
with_delegate = find_safe_value(configs, AccountConfig::ALLOW_TO_DELEGATE_KEY) == true
|
2025-06-06 16:23:44 +03:00
|
|
|
with_partial_download = find_safe_value(configs, AccountConfig::ALLOW_TO_PARTIAL_DOWNLOAD_KEY) != false
|
2024-07-24 20:55:35 +03:00
|
|
|
with_signature_id = find_safe_value(configs, AccountConfig::WITH_SIGNATURE_ID) == true
|
2024-08-06 00:19:33 +03:00
|
|
|
require_signing_reason = find_safe_value(configs, AccountConfig::REQUIRE_SIGNING_REASON_KEY) == true
|
2025-03-27 18:29:02 +02:00
|
|
|
enforce_signing_order = find_safe_value(configs, AccountConfig::ENFORCE_SIGNING_ORDER_KEY) == true
|
2025-07-18 10:30:37 +03:00
|
|
|
with_submitter_timezone = find_safe_value(configs, AccountConfig::WITH_SUBMITTER_TIMEZONE_KEY) == true
|
2026-02-17 17:45:46 +02:00
|
|
|
with_timestamp_seconds = find_safe_value(configs, AccountConfig::WITH_TIMESTAMP_SECONDS_KEY) == true
|
2025-07-18 10:30:37 +03:00
|
|
|
with_signature_id_reason = find_safe_value(configs, AccountConfig::WITH_SIGNATURE_ID_REASON_KEY) != false
|
2026-07-14 12:47:38 +03:00
|
|
|
with_signature_id_completed_at =
|
|
|
|
|
find_safe_value(configs, AccountConfig::WITH_SIGNATURE_ID_COMPLETED_AT_KEY) == true
|
2025-12-16 11:38:37 +02:00
|
|
|
with_field_labels = find_safe_value(configs, AccountConfig::WITH_FIELD_LABELS_KEY) != false
|
2024-11-29 19:49:44 +02:00
|
|
|
policy_links = find_safe_value(configs, AccountConfig::POLICY_LINKS_KEY)
|
2024-07-24 20:55:35 +03:00
|
|
|
|
2025-07-18 10:30:37 +03:00
|
|
|
attrs = { completed_button:, with_typed_signature:, with_confetti:,
|
2026-03-27 12:56:52 +02:00
|
|
|
reuse_signature:, with_decline:, with_delegate:, with_partial_download:,
|
2025-07-18 10:30:37 +03:00
|
|
|
policy_links:, enforce_signing_order:, completed_message:,
|
|
|
|
|
require_signing_reason:, prefill_signature:, with_submitter_timezone:,
|
2026-07-14 12:47:38 +03:00
|
|
|
with_signature_id_reason:, with_signature_id:, with_field_labels:, with_timestamp_seconds:,
|
|
|
|
|
with_signature_id_completed_at: }
|
2024-03-09 23:29:59 +02:00
|
|
|
|
|
|
|
|
keys.each do |key|
|
|
|
|
|
attrs[key.to_sym] = configs.find { |e| e.key == key.to_s }&.value
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
attrs
|
2023-12-02 16:26:34 +02:00
|
|
|
end
|
2024-06-15 15:55:09 +03:00
|
|
|
|
|
|
|
|
def find_safe_value(configs, key)
|
|
|
|
|
configs.find { |e| e.key == key }&.value
|
|
|
|
|
end
|
2023-12-02 16:26:34 +02:00
|
|
|
end
|
|
|
|
|
end
|