闭社主体 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.

40 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. class Settings::PreferencesController < ApplicationController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. def show; end
  6. def update
  7. current_user.settings['notification_emails'] = {
  8. follow: user_params[:notification_emails][:follow] == '1',
  9. follow_request: user_params[:notification_emails][:follow_request] == '1',
  10. reblog: user_params[:notification_emails][:reblog] == '1',
  11. favourite: user_params[:notification_emails][:favourite] == '1',
  12. mention: user_params[:notification_emails][:mention] == '1',
  13. digest: user_params[:notification_emails][:digest] == '1',
  14. }
  15. current_user.settings['interactions'] = {
  16. must_be_follower: user_params[:interactions][:must_be_follower] == '1',
  17. must_be_following: user_params[:interactions][:must_be_following] == '1',
  18. }
  19. current_user.settings['default_privacy'] = user_params[:setting_default_privacy]
  20. current_user.settings['boost_modal'] = user_params[:setting_boost_modal] == '1'
  21. if current_user.update(user_params.except(:notification_emails, :interactions, :setting_default_privacy, :setting_boost_modal))
  22. redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
  23. else
  24. render action: :show
  25. end
  26. end
  27. private
  28. def user_params
  29. params.require(:user).permit(:locale, :setting_default_privacy, :setting_boost_modal, notification_emails: [:follow, :follow_request, :reblog, :favourite, :mention, :digest], interactions: [:must_be_follower, :must_be_following])
  30. end
  31. end