Files
docuseal/lib/submitters/form_configs.rb
T

51 lines
1.9 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-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-03-09 23:29:59 +02:00
AccountConfig::ALLOW_TYPED_SIGNATURE].freeze
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-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
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:,
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