validate account config keys

pull/220/head^2
Pete Matsyburka 2 years ago
parent 8432bec3d6
commit c743cc689d

@ -11,6 +11,8 @@ class AccountConfigsController < ApplicationController
AccountConfig::ESIGNING_PREFERENCE_KEY AccountConfig::ESIGNING_PREFERENCE_KEY
].freeze ].freeze
InvalidKey = Class.new(StandardError)
def create def create
@account_config.update!(account_config_params) @account_config.update!(account_config_params)
@ -20,7 +22,7 @@ class AccountConfigsController < ApplicationController
private private
def load_account_config def load_account_config
return head :not_found unless ALLOWED_KEYS.include?(account_config_params[:key]) raise InvalidKey unless ALLOWED_KEYS.include?(account_config_params[:key])
@account_config = @account_config =
AccountConfig.find_or_initialize_by(account: current_account, key: account_config_params[:key]) AccountConfig.find_or_initialize_by(account: current_account, key: account_config_params[:key])

@ -1,23 +1,42 @@
# frozen_string_literal: true # frozen_string_literal: true
class PersonalizationSettingsController < ApplicationController class PersonalizationSettingsController < ApplicationController
ALLOWED_KEYS = [
AccountConfig::FORM_COMPLETED_BUTTON_KEY,
AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY,
AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY,
AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY
].freeze
InvalidKey = Class.new(StandardError)
before_action :load_and_authorize_account_config, only: :create
def show def show
authorize!(:read, AccountConfig) authorize!(:read, AccountConfig)
end end
def create def create
account_config = @account_config.save!
current_account.account_configs.find_or_initialize_by(key: account_config_params[:key])
authorize!(:create, account_config)
account_config.update!(account_config_params)
redirect_back(fallback_location: settings_personalization_path, notice: 'Settings have been saved.') redirect_back(fallback_location: settings_personalization_path, notice: 'Settings have been saved.')
end end
private private
def load_and_authorize_account_config
@account_config =
current_account.account_configs.find_or_initialize_by(key: account_config_params[:key])
@account_config.assign_attributes(account_config_params)
authorize!(:create, @account_config)
raise InvalidKey unless ALLOWED_KEYS.include?(@account_config.key)
@account_config
end
def account_config_params def account_config_params
attrs = params.require(:account_config).permit! attrs = params.require(:account_config).permit!

@ -8,6 +8,8 @@ class UserConfigsController < ApplicationController
UserConfig::RECEIVE_COMPLETED_EMAIL UserConfig::RECEIVE_COMPLETED_EMAIL
].freeze ].freeze
InvalidKey = Class.new(StandardError)
def create def create
@user_config.update!(user_config_params) @user_config.update!(user_config_params)
@ -17,7 +19,7 @@ class UserConfigsController < ApplicationController
private private
def load_user_config def load_user_config
return head :not_found unless ALLOWED_KEYS.include?(user_config_params[:key]) raise InvalidKey unless ALLOWED_KEYS.include?(user_config_params[:key])
@user_config = @user_config =
UserConfig.find_or_initialize_by(user: current_user, key: user_config_params[:key]) UserConfig.find_or_initialize_by(user: current_user, key: user_config_params[:key])

@ -38,7 +38,7 @@ module ReplaceEmailVariables
text = text.gsub(DOCUMENTS_LINKS, build_documents_links_text(submitter, sig)) text = text.gsub(DOCUMENTS_LINKS, build_documents_links_text(submitter, sig))
text = text.gsub(DOCUMENTS_LINK, build_documents_links_text(submitter, sig)) text = text.gsub(DOCUMENTS_LINK, build_documents_links_text(submitter, sig))
text = text.gsub(ACCOUNT_NAME, submitter.template.account.name) if submitter.template text = text.gsub(ACCOUNT_NAME, submitter.account.name) if submitter.account
text text
end end

Loading…
Cancel
Save