You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class SettingsController < BaseController
  4. ADMIN_SETTINGS = %w(
  5. site_contact_username
  6. site_contact_email
  7. site_title
  8. site_description
  9. site_extended_description
  10. site_terms
  11. open_registrations
  12. closed_registrations_message
  13. open_deletion
  14. timeline_preview
  15. ).freeze
  16. BOOLEAN_SETTINGS = %w(
  17. open_registrations
  18. open_deletion
  19. timeline_preview
  20. ).freeze
  21. def edit
  22. @admin_settings = Form::AdminSettings.new
  23. end
  24. def update
  25. settings_params.each do |key, value|
  26. setting = Setting.where(var: key).first_or_initialize(var: key)
  27. setting.update(value: value_for_update(key, value))
  28. end
  29. flash[:notice] = I18n.t('generic.changes_saved_msg')
  30. redirect_to edit_admin_settings_path
  31. end
  32. private
  33. def settings_params
  34. params.require(:form_admin_settings).permit(ADMIN_SETTINGS)
  35. end
  36. def value_for_update(key, value)
  37. if BOOLEAN_SETTINGS.include?(key)
  38. value == '1'
  39. else
  40. value
  41. end
  42. end
  43. end
  44. end