From 7e3b63a7ba6dd862c3a32bc8a189d170fa15c950 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 24 Oct 2017 15:49:02 +0200 Subject: [PATCH] Disabled params wrapping. --- .../app/controllers/_profile/calendar_subscriptions.coffee | 5 ++--- .../javascripts/app/controllers/_profile/language.coffee | 2 +- .../app/controllers/_profile/notification.coffee | 2 +- app/assets/javascripts/app/controllers/chat.coffee | 4 ++-- app/assets/javascripts/app/controllers/clues.coffee | 2 +- app/assets/javascripts/app/controllers/cti.coffee | 2 +- app/controllers/users_controller.rb | 6 ++++-- config/initializers/wrap_parameters.rb | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_profile/calendar_subscriptions.coffee b/app/assets/javascripts/app/controllers/_profile/calendar_subscriptions.coffee index 5c85bcb9a..d45545391 100644 --- a/app/assets/javascripts/app/controllers/_profile/calendar_subscriptions.coffee +++ b/app/assets/javascripts/app/controllers/_profile/calendar_subscriptions.coffee @@ -59,9 +59,8 @@ class CalendarSubscriptions extends App.ControllerSubContent store: -> # get data data = - user: - calendar_subscriptions: - tickets: @preferences + calendar_subscriptions: + tickets: @preferences @ajax( id: 'preferences' diff --git a/app/assets/javascripts/app/controllers/_profile/language.coffee b/app/assets/javascripts/app/controllers/_profile/language.coffee index 9debae4ec..efb22a23c 100644 --- a/app/assets/javascripts/app/controllers/_profile/language.coffee +++ b/app/assets/javascripts/app/controllers/_profile/language.coffee @@ -41,7 +41,7 @@ class Index extends App.ControllerSubContent id: 'preferences' type: 'PUT' url: "#{@apiPath}/users/preferences" - data: JSON.stringify({user:params}) + data: JSON.stringify(params) processData: true success: @success error: @error diff --git a/app/assets/javascripts/app/controllers/_profile/notification.coffee b/app/assets/javascripts/app/controllers/_profile/notification.coffee index 3de8f3e2b..8cf097a83 100644 --- a/app/assets/javascripts/app/controllers/_profile/notification.coffee +++ b/app/assets/javascripts/app/controllers/_profile/notification.coffee @@ -156,7 +156,7 @@ class Index extends App.ControllerSubContent id: 'preferences' type: 'PUT' url: @apiPath + '/users/preferences' - data: JSON.stringify({user:params}) + data: JSON.stringify(params) processData: true success: @success error: @error diff --git a/app/assets/javascripts/app/controllers/chat.coffee b/app/assets/javascripts/app/controllers/chat.coffee index 6023b6a8a..2966e3b4c 100644 --- a/app/assets/javascripts/app/controllers/chat.coffee +++ b/app/assets/javascripts/app/controllers/chat.coffee @@ -219,7 +219,7 @@ class App.CustomerChat extends App.Controller id: 'preferences' type: 'PUT' url: "#{@apiPath}/users/preferences" - data: JSON.stringify(user: {chat: preferences.chat}) + data: JSON.stringify(chat: preferences.chat) processData: true success: @success error: @error @@ -757,7 +757,7 @@ class Setting extends App.ControllerModal id: 'preferences' type: 'PUT' url: "#{@apiPath}/users/preferences" - data: JSON.stringify({user:params}) + data: JSON.stringify(params) processData: true success: @success error: @error diff --git a/app/assets/javascripts/app/controllers/clues.coffee b/app/assets/javascripts/app/controllers/clues.coffee index 735a6329d..81037e9f0 100644 --- a/app/assets/javascripts/app/controllers/clues.coffee +++ b/app/assets/javascripts/app/controllers/clues.coffee @@ -12,7 +12,7 @@ class Index extends App.Controller id: 'preferences' type: 'PUT' url: "#{@apiPath}/users/preferences" - data: JSON.stringify({user:{intro:true}}) + data: JSON.stringify(intro: true) processData: true ) @navigate '#' diff --git a/app/assets/javascripts/app/controllers/cti.coffee b/app/assets/javascripts/app/controllers/cti.coffee index 46029c79b..dddd07602 100644 --- a/app/assets/javascripts/app/controllers/cti.coffee +++ b/app/assets/javascripts/app/controllers/cti.coffee @@ -231,7 +231,7 @@ class App.CTI extends App.Controller id: 'preferences' type: 'PUT' url: "#{@apiPath}/users/preferences" - data: JSON.stringify(user: {cti: state}) + data: JSON.stringify(cti: state) processData: true ) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 72727fff3..bad343c3e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -803,10 +803,12 @@ curl http://localhost/api/v1/users/preferences -v -u #{login}:#{password} -H "Co def preferences raise Exceptions::UnprocessableEntity, 'No current user!' if !current_user - if params[:user] + preferences_params = params.except(:controller, :action) + + if preferences_params.present? user = User.find(current_user.id) user.with_lock do - params[:user].permit!.to_h.each do |key, value| + preferences_params.permit!.to_h.each do |key, value| user.preferences[key.to_sym] = value end user.save! diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 33725e95f..ba7a7376e 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,7 +5,7 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [] if respond_to?(:wrap_parameters) end # To enable root element in JSON for ActiveRecord objects.