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.

31 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).follow = user_params[:notification_emails][:follow] == '1'
  8. current_user.settings(:notification_emails).reblog = user_params[:notification_emails][:reblog] == '1'
  9. current_user.settings(:notification_emails).favourite = user_params[:notification_emails][:favourite] == '1'
  10. current_user.settings(:notification_emails).mention = user_params[:notification_emails][:mention] == '1'
  11. current_user.settings(:interactions).must_be_follower = user_params[:interactions][:must_be_follower] == '1'
  12. current_user.settings(:interactions).must_be_following = user_params[:interactions][:must_be_following] == '1'
  13. if current_user.update(user_params.except(:notification_emails, :interactions))
  14. redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
  15. else
  16. render action: :show
  17. end
  18. end
  19. private
  20. def user_params
  21. params.require(:user).permit(:locale, notification_emails: [:follow, :reblog, :favourite, :mention], interactions: [:must_be_follower, :must_be_following])
  22. end
  23. end