]> cat aescling's git repositories - mastodon.git/blob - app/controllers/settings/preferences_controller.rb
Simplify render in controllers (#2144)
[mastodon.git] / app / controllers / settings / preferences_controller.rb
1 # frozen_string_literal: true
2
3 class Settings::PreferencesController < ApplicationController
4 layout 'admin'
5
6 before_action :authenticate_user!
7
8 def show; end
9
10 def update
11 current_user.settings['notification_emails'] = {
12 follow: user_params[:notification_emails][:follow] == '1',
13 follow_request: user_params[:notification_emails][:follow_request] == '1',
14 reblog: user_params[:notification_emails][:reblog] == '1',
15 favourite: user_params[:notification_emails][:favourite] == '1',
16 mention: user_params[:notification_emails][:mention] == '1',
17 digest: user_params[:notification_emails][:digest] == '1',
18 }
19
20 current_user.settings['interactions'] = {
21 must_be_follower: user_params[:interactions][:must_be_follower] == '1',
22 must_be_following: user_params[:interactions][:must_be_following] == '1',
23 }
24
25 current_user.settings['default_privacy'] = user_params[:setting_default_privacy]
26 current_user.settings['boost_modal'] = user_params[:setting_boost_modal] == '1'
27 current_user.settings['auto_play_gif'] = user_params[:setting_auto_play_gif] == '1'
28
29 if current_user.update(user_params.except(:notification_emails, :interactions, :setting_default_privacy, :setting_boost_modal, :setting_auto_play_gif))
30 redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
31 else
32 render :show
33 end
34 end
35
36 private
37
38 def user_params
39 params.require(:user).permit(:locale, :setting_default_privacy, :setting_boost_modal, :setting_auto_play_gif, notification_emails: [:follow, :follow_request, :reblog, :favourite, :mention, :digest], interactions: [:must_be_follower, :must_be_following])
40 end
41 end
This page took 0.079537 seconds and 5 git commands to generate.