docbrown/app/controllers/api/v0/admin/configs_controller.rb
Michael Kohl 6dfabd578f
Rename SiteConfig to Settings::General (#13573)
* Rename SiteConfig

* More renaming

* Update spec

* Update mandatory settings mapping

* More renaming

* e2e test fixes

* You have a rename, and you have a rename

* Spec fix

* More changes

* Temporarily disable specs

* After-merge update

* Undo rename for migration

* undo rename of DUS

* Fix DUS

* Fix merge problem

* Remove redundant DUS

* Fix specs

* Remove unused code

* Change wrong class name

* More cleanup

* Re-add missing values to constant

* Fix constant

* Fix spec

* Remove obsolete fields

* Add accidentally removed field

* Update spec

* Move methods from Settings::General to ForemInstance

* Remove unneeded model

* Change mentions of 'site config'
2021-05-21 14:45:37 +02:00

50 lines
1.7 KiB
Ruby

module Api
module V0
module Admin
class ConfigsController < ApiController
include SettingsParams
before_action :authenticate_with_api_key_or_current_user!
before_action :authorize_super_admin
skip_before_action :verify_authenticity_token, only: %i[update]
def show
@settings =
Settings::Authentication.all +
Settings::Campaign.all +
Settings::Community.all +
Settings::General.all +
Settings::Mascot.all +
Settings::RateLimit.all +
Settings::UserExperience.all
end
def update
# NOTE: citizen428 - this is not going to scale but I want to wait
# until we extract at least one more settings model before deciding
# how to change this.
settings_result = ::Settings::Upsert.call(settings_params)
auth_settings_result = ::Authentication::SettingsUpsert.call(auth_settings_params)
if settings_result.success? && auth_settings_result.success?
@settings = Settings::General.all + Settings::Authentication.all
Audit::Logger.log(:internal, @user, params.dup)
bust_content_change_caches
render "show"
else
errors = settings_result.errors + auth_settings_result.errors
render json: { error: errors.to_sentence, status: 422 }, status: :unprocessable_entity
end
end
private
def auth_settings_params
params
.require(:site_config)
.permit(*::Settings::Authentication.keys, :providers_to_enable)
end
end
end
end
end