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.

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