闭社主体 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
1.5 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. if current_user.update(user_params.except(:notification_emails, :interactions, :setting_default_privacy))
  21. redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
  22. else
  23. render action: :show
  24. end
  25. end
  26. private
  27. def user_params
  28. params.require(:user).permit(:locale, :setting_default_privacy, notification_emails: [:follow, :follow_request, :reblog, :favourite, :mention, :digest], interactions: [:must_be_follower, :must_be_following])
  29. end
  30. end