about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-04-20 21:26:52 -0400
committerEugen <eugen@zeonfederated.com>2017-04-21 03:26:52 +0200
commit2dda356e3fc7000ea630b802588cb91df296a89f (patch)
tree0a0b05f9d196fbc9706e15af9a5f950d31a0bdd7 /app/controllers
parent972f6bc861affd9bc40181492833108f905a04b6 (diff)
Clean up settings/preferences controller (#2237)
* Add missing fields group on preferences page

* Clean up settings/preferences controller

* Extract a UserSettingsDecorator
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/settings/preferences_controller.rb40
1 files changed, 20 insertions, 20 deletions
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 31a204420..6762faee4 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -8,25 +8,9 @@ class Settings::PreferencesController < ApplicationController
   def show; end
 
   def update
-    current_user.settings['notification_emails'] = {
-      follow:         user_params[:notification_emails][:follow]         == '1',
-      follow_request: user_params[:notification_emails][:follow_request] == '1',
-      reblog:         user_params[:notification_emails][:reblog]         == '1',
-      favourite:      user_params[:notification_emails][:favourite]      == '1',
-      mention:        user_params[:notification_emails][:mention]        == '1',
-      digest:         user_params[:notification_emails][:digest]         == '1',
-    }
-
-    current_user.settings['interactions'] = {
-      must_be_follower:  user_params[:interactions][:must_be_follower]  == '1',
-      must_be_following: user_params[:interactions][:must_be_following] == '1',
-    }
-
-    current_user.settings['default_privacy'] = user_params[:setting_default_privacy]
-    current_user.settings['boost_modal']     = user_params[:setting_boost_modal]   == '1'
-    current_user.settings['auto_play_gif']   = user_params[:setting_auto_play_gif] == '1'
-
-    if current_user.update(user_params.except(:notification_emails, :interactions, :setting_default_privacy, :setting_boost_modal, :setting_auto_play_gif))
+    user_settings.update(user_settings_params.to_h)
+
+    if current_user.update(user_params)
       redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
     else
       render :show
@@ -35,7 +19,23 @@ class Settings::PreferencesController < ApplicationController
 
   private
 
+  def user_settings
+    UserSettingsDecorator.new(current_user)
+  end
+
   def user_params
-    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])
+    params.require(:user).permit(
+      :locale
+    )
+  end
+
+  def user_settings_params
+    params.require(:user).permit(
+      :setting_default_privacy,
+      :setting_boost_modal,
+      :setting_auto_play_gif,
+      notification_emails: %i(follow follow_request reblog favourite mention digest),
+      interactions: %i(must_be_follower must_be_following)
+    )
   end
 end