Files
docuseal/lib/submitters/form_configs.rb
T

60 lines
2.5 KiB
Ruby
Raw Normal View History

# 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,
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,
2024-11-29 19:49:44 +02:00
AccountConfig::ALLOW_TYPED_SIGNATURE,
*(Docuseal.multitenant? ? [] : [AccountConfig::POLICY_LINKS_KEY])].freeze
2024-03-09 23:29:59 +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)
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
with_confetti = find_safe_value(configs, AccountConfig::FORM_WITH_CONFETTI_KEY) != false
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
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
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
2024-10-10 13:14:49 +03:00
attrs = {
completed_button:,
with_typed_signature:,
with_confetti:,
reuse_signature:,
2024-10-24 12:15:32 +03:00
with_decline:,
2024-11-29 19:49:44 +02:00
policy_links:,
2025-03-27 18:29:02 +02:00
enforce_signing_order:,
2024-10-10 13:14:49 +03:00
completed_message:,
require_signing_reason:,
prefill_signature:,
with_signature_id:
}
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
end
2024-06-15 15:55:09 +03:00
def find_safe_value(configs, key)
configs.find { |e| e.key == key }&.value
end
end
end