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.

66 lines
1.5 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. bootstrap_timeline_accounts
  16. thumbnail
  17. ).freeze
  18. BOOLEAN_SETTINGS = %w(
  19. open_registrations
  20. open_deletion
  21. timeline_preview
  22. ).freeze
  23. UPLOAD_SETTINGS = %w(
  24. thumbnail
  25. ).freeze
  26. def edit
  27. authorize :settings, :show?
  28. @admin_settings = Form::AdminSettings.new
  29. end
  30. def update
  31. authorize :settings, :update?
  32. settings_params.each do |key, value|
  33. if UPLOAD_SETTINGS.include?(key)
  34. upload = SiteUpload.where(var: key).first_or_initialize(var: key)
  35. upload.update(file: value)
  36. else
  37. setting = Setting.where(var: key).first_or_initialize(var: key)
  38. setting.update(value: value_for_update(key, value))
  39. end
  40. end
  41. flash[:notice] = I18n.t('generic.changes_saved_msg')
  42. redirect_to edit_admin_settings_path
  43. end
  44. private
  45. def settings_params
  46. params.require(:form_admin_settings).permit(ADMIN_SETTINGS)
  47. end
  48. def value_for_update(key, value)
  49. if BOOLEAN_SETTINGS.include?(key)
  50. value == '1'
  51. else
  52. value
  53. end
  54. end
  55. end
  56. end