docbrown/app/controllers/admin/settings/user_experiences_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

34 lines
922 B
Ruby

module Admin
module Settings
class UserExperiencesController < Admin::ApplicationController
def create
errors = upsert_config(settings_params)
if errors.none?
Audit::Logger.log(:internal, current_user, params.dup)
redirect_to admin_config_path, notice: "Successfully updated settings."
else
redirect_to admin_config_path, alert: "😭 #{errors.to_sentence}"
end
end
def settings_params
params
.require(:settings_user_experience)
.permit(*::Settings::UserExperience.keys)
end
def upsert_config(configs)
errors = []
configs.each do |key, value|
::Settings::UserExperience.public_send("#{key}=", value) if value.present?
rescue ActiveRecord::RecordInvalid => e
errors << e.message
next
end
errors
end
end
end
end