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.

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