Files
docuseal/app/controllers/account_configs_controller.rb
T

70 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class AccountConfigsController < ApplicationController
2025-05-20 22:41:47 +03:00
before_action :load_account_config, only: :create
authorize_resource :account_config, only: :create
load_and_authorize_resource :account_config, only: :destroy
ALLOWED_KEYS = [
AccountConfig::ALLOW_TYPED_SIGNATURE,
2023-12-21 23:29:06 +02:00
AccountConfig::FORCE_MFA,
2024-01-30 17:03:58 +02:00
AccountConfig::ALLOW_TO_RESUBMIT,
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,
2024-06-15 15:55:09 +03:00
AccountConfig::FORM_PREFILL_SIGNATURE_KEY,
2024-03-09 23:29:59 +02:00
AccountConfig::ESIGNING_PREFERENCE_KEY,
2024-04-15 19:58:24 +03:00
AccountConfig::FORM_WITH_CONFETTI_KEY,
2024-04-19 02:04:35 +03:00
AccountConfig::DOWNLOAD_LINKS_AUTH_KEY,
2025-08-31 16:40:18 +03:00
AccountConfig::DOWNLOAD_LINKS_EXPIRE_KEY,
2024-04-22 21:34:55 +03:00
AccountConfig::FORCE_SSO_AUTH_KEY,
2024-07-24 20:55:35 +03:00
AccountConfig::FLATTEN_RESULT_PDF_KEY,
2025-03-27 18:29:02 +02:00
AccountConfig::ENFORCE_SIGNING_ORDER_KEY,
2025-09-22 17:52:24 +03:00
AccountConfig::WITH_FILE_LINKS_KEY,
2024-08-06 00:19:33 +03:00
AccountConfig::WITH_SIGNATURE_ID,
2024-08-23 23:46:22 +03:00
AccountConfig::COMBINE_PDF_RESULT_KEY,
2024-11-20 01:12:26 +02:00
AccountConfig::REQUIRE_SIGNING_REASON_KEY,
2026-03-05 12:17:14 +02:00
AccountConfig::DOCUMENT_FILENAME_FORMAT_KEY,
AccountConfig::ENABLE_MCP_KEY
].freeze
2024-02-29 23:59:49 +02:00
InvalidKey = Class.new(StandardError)
def create
@account_config.update!(account_config_params)
head :ok
end
2025-05-20 22:41:47 +03:00
def destroy
2026-07-28 19:27:25 +03:00
raise InvalidKey unless allowed_destroy_keys.include?(@account_config.key)
2025-05-20 22:41:47 +03:00
@account_config.destroy!
redirect_back(fallback_location: root_path)
end
private
2026-03-27 12:56:52 +02:00
def allowed_keys
ALLOWED_KEYS
end
2026-07-28 19:27:25 +03:00
def allowed_destroy_keys
ALLOWED_KEYS
end
def load_account_config
2026-03-27 12:56:52 +02:00
raise InvalidKey unless allowed_keys.include?(account_config_params[:key])
@account_config =
AccountConfig.find_or_initialize_by(account: current_account, key: account_config_params[:key])
end
def account_config_params
2025-02-24 23:59:30 +02:00
params.required(:account_config).permit(:key, :value, { value: {} }, { value: [] }).tap do |attrs|
attrs[:value] = attrs[:value] == '1' if attrs[:value].in?(%w[1 0])
end
end
end