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.

83 lines
1.8 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_short_description
  9. site_description
  10. site_extended_description
  11. site_terms
  12. open_registrations
  13. closed_registrations_message
  14. open_deletion
  15. timeline_preview
  16. show_staff_badge
  17. bootstrap_timeline_accounts
  18. flavour
  19. skin
  20. thumbnail
  21. hero
  22. min_invite_role
  23. activity_api_enabled
  24. peers_api_enabled
  25. show_known_fediverse_at_about_page
  26. preview_sensitive_media
  27. custom_css
  28. ).freeze
  29. BOOLEAN_SETTINGS = %w(
  30. open_registrations
  31. open_deletion
  32. timeline_preview
  33. show_staff_badge
  34. activity_api_enabled
  35. peers_api_enabled
  36. show_known_fediverse_at_about_page
  37. preview_sensitive_media
  38. ).freeze
  39. UPLOAD_SETTINGS = %w(
  40. thumbnail
  41. hero
  42. ).freeze
  43. def edit
  44. authorize :settings, :show?
  45. @admin_settings = Form::AdminSettings.new
  46. end
  47. def update
  48. authorize :settings, :update?
  49. settings_params.each do |key, value|
  50. if UPLOAD_SETTINGS.include?(key)
  51. upload = SiteUpload.where(var: key).first_or_initialize(var: key)
  52. upload.update(file: value)
  53. else
  54. setting = Setting.where(var: key).first_or_initialize(var: key)
  55. setting.update(value: value_for_update(key, value))
  56. end
  57. end
  58. flash[:notice] = I18n.t('generic.changes_saved_msg')
  59. redirect_to edit_admin_settings_path
  60. end
  61. private
  62. def settings_params
  63. params.require(:form_admin_settings).permit(ADMIN_SETTINGS)
  64. end
  65. def value_for_update(key, value)
  66. if BOOLEAN_SETTINGS.include?(key)
  67. value == '1'
  68. else
  69. value
  70. end
  71. end
  72. end
  73. end