闭社主体 forked from https://github.com/tootsuite/mastodon
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.

39 lines
864 B

  1. # frozen_string_literal: true
  2. module Admin
  3. class SettingsController < BaseController
  4. BOOLEAN_SETTINGS = %w(open_registrations).freeze
  5. def index
  6. @settings = Setting.all_as_records
  7. end
  8. def update
  9. @setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
  10. @setting.update(value: value_for_update)
  11. respond_to do |format|
  12. format.html { redirect_to admin_settings_path }
  13. format.json { respond_with_bip(@setting) }
  14. end
  15. end
  16. private
  17. def settings_params
  18. params.require(:setting).permit(:value)
  19. end
  20. def value_for_update
  21. if updating_boolean_setting?
  22. settings_params[:value] == 'true'
  23. else
  24. settings_params[:value]
  25. end
  26. end
  27. def updating_boolean_setting?
  28. BOOLEAN_SETTINGS.include?(params[:id])
  29. end
  30. end
  31. end