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.

36 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class Settings::PreferencesController < ApplicationController
  3. layout 'auth'
  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. }
  14. current_user.settings['interactions'] = {
  15. must_be_follower: user_params[:interactions][:must_be_follower] == '1',
  16. must_be_following: user_params[:interactions][:must_be_following] == '1',
  17. }
  18. if current_user.update(user_params.except(:notification_emails, :interactions))
  19. redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
  20. else
  21. render action: :show
  22. end
  23. end
  24. private
  25. def user_params
  26. params.require(:user).permit(:locale, notification_emails: [:follow, :follow_request, :reblog, :favourite, :mention], interactions: [:must_be_follower, :must_be_following])
  27. end
  28. end