From cb7d10fb1f7004ae59c9e3b4597b8ff95cb28ce8 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 19 May 2016 00:06:55 +0200 Subject: [PATCH] Fixed race condition if saving avatar image. Added image attribute in avatar observer controller. --- .../controllers/_application_controller_generic.coffee | 9 ++++----- .../javascripts/app/controllers/widget/avatar.coffee | 1 + .../app/controllers/widget/organization.coffee | 6 +++--- .../javascripts/app/controllers/widget/user.coffee | 6 +++--- app/controllers/users_controller.rb | 9 ++++++--- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee index 50ccc6cd8..a6ffdcbbd 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.coffee @@ -5,7 +5,7 @@ class App.ControllerGenericNew extends App.ControllerModal headPrefix: 'New' content: => - @head = @pageData.object + @head = @pageData.head || @pageData.object @controller = new App.ControllerForm( model: App[ @genericObject ] params: @item @@ -53,7 +53,7 @@ class App.ControllerGenericEdit extends App.ControllerModal content: => @item = App[ @genericObject ].find( @id ) - @head = @pageData.object + @head = @pageData.head || @pageData.object @controller = new App.ControllerForm( model: App[ @genericObject ] @@ -1116,9 +1116,8 @@ class App.ObserverController extends App.Controller if active currentAttributes[key] = object[key] if @observeNot - attributes = object.attributes() - for key, value of attributes - if !@observeNot[key] + for key, value of object + if !@observeNot[key] && !_.isFunction(value) currentAttributes[key] = value if !@lastAttributres diff --git a/app/assets/javascripts/app/controllers/widget/avatar.coffee b/app/assets/javascripts/app/controllers/widget/avatar.coffee index 8ef120488..5111a4ed9 100644 --- a/app/assets/javascripts/app/controllers/widget/avatar.coffee +++ b/app/assets/javascripts/app/controllers/widget/avatar.coffee @@ -5,6 +5,7 @@ class App.WidgetAvatar extends App.ObserverController firstname: true lastname: true email: true + image: true render: (user) => @html(user.avatar @size, @position, undefined, false, false, @type) diff --git a/app/assets/javascripts/app/controllers/widget/organization.coffee b/app/assets/javascripts/app/controllers/widget/organization.coffee index e53627f10..64e63a44b 100644 --- a/app/assets/javascripts/app/controllers/widget/organization.coffee +++ b/app/assets/javascripts/app/controllers/widget/organization.coffee @@ -6,7 +6,7 @@ class App.WidgetOrganization extends App.Controller super # subscribe and reload data / fetch new data if triggered - @subscribeId = App.Organization.full( @organization_id, @render, false, true ) + @subscribeId = App.Organization.full(@organization_id, @render, false, true) release: => App.Organization.unsubscribe(@subscribeId) @@ -58,9 +58,9 @@ class App.WidgetOrganization extends App.Controller update: (e) => name = $(e.target).attr('data-name') value = $(e.target).html() - org = App.Organization.find( @organization_id ) + org = App.Organization.find(@organization_id) if org[name] isnt value data = {} data[name] = value - org.updateAttributes( data ) + org.updateAttributes(data) @log 'notice', 'update', name, value, org diff --git a/app/assets/javascripts/app/controllers/widget/user.coffee b/app/assets/javascripts/app/controllers/widget/user.coffee index 6db505124..b065d083e 100644 --- a/app/assets/javascripts/app/controllers/widget/user.coffee +++ b/app/assets/javascripts/app/controllers/widget/user.coffee @@ -6,7 +6,7 @@ class App.WidgetUser extends App.Controller super # subscribe and reload data / fetch new data if triggered - @subscribeId = App.User.full( @user_id, @render, false, true ) + @subscribeId = App.User.full(@user_id, @render, false, true) release: => App.User.unsubscribe(@subscribeId) @@ -85,9 +85,9 @@ class App.WidgetUser extends App.Controller update: (e) => name = $(e.target).attr('data-name') value = $(e.target).html() - user = App.User.find( @user_id ) + user = App.User.find(@user_id) if user[name] isnt value data = {} data[name] = value - user.updateAttributes( data ) + user.updateAttributes(data) @log 'notice', 'update', name, value, user diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 147696499..a2fb6c755 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -733,7 +733,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content ) # update user link - current_user.update_attributes(image: avatar.store_hash) + user = User.find(current_user.id) + user.update_attributes(image: avatar.store_hash) render json: { avatar: avatar }, status: :ok end @@ -751,7 +752,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content avatar = Avatar.set_default('User', current_user.id, params[:id]) # update user link - current_user.update_attributes(image: avatar.store_hash) + user = User.find(current_user.id) + user.update_attributes(image: avatar.store_hash) render json: {}, status: :ok end @@ -770,7 +772,8 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content # update user link avatar = Avatar.get_default('User', current_user.id) - current_user.update_attributes(image: avatar.store_hash) + user = User.find(current_user.id) + user.update_attributes(image: avatar.store_hash) render json: {}, status: :ok end