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.

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