Co-authored-by: Michael Kohl <citizen428@forem.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Suzanne Aitchison <suzanne@forem.com> Co-authored-by: Mac Siri <mac@forem.com> Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
Ruby
module Admin
|
|
module Settings
|
|
class GeneralSettingsController < Admin::Settings::BaseController
|
|
after_action :bust_content_change_caches, only: %i[create]
|
|
|
|
SPECIAL_PARAMS_TO_ADD = %w[
|
|
credit_prices_in_cents
|
|
meta_keywords
|
|
logo
|
|
].freeze
|
|
|
|
def create
|
|
result = ::Settings::General::Upsert.call(settings_params)
|
|
if result.success?
|
|
Audit::Logger.log(:internal, current_user, params.dup)
|
|
render json: { message: "Successfully updated settings." }, status: :ok
|
|
else
|
|
render json: { error: result.errors.to_sentence }, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
# NOTE: we need to override this since the controller name doesn't reflect
|
|
# the model name
|
|
def authorization_resource
|
|
::Settings::General
|
|
end
|
|
|
|
def settings_params
|
|
params.require(:settings_general)&.permit(
|
|
settings_keys.map(&:to_sym),
|
|
social_media_handles: ::Settings::General.social_media_handles.keys,
|
|
meta_keywords: ::Settings::General.meta_keywords.keys,
|
|
credit_prices_in_cents: ::Settings::General.credit_prices_in_cents.keys,
|
|
)
|
|
end
|
|
|
|
def settings_keys
|
|
::Settings::General.keys + SPECIAL_PARAMS_TO_ADD
|
|
end
|
|
end
|
|
end
|
|
end
|