diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js index bd368234c..9dee51a5f 100644 --- a/app/assets/javascripts/discourse/models/user.js +++ b/app/assets/javascripts/discourse/models/user.js @@ -142,7 +142,10 @@ Discourse.User = Discourse.Model.extend({ 'new_topic_duration_minutes', 'external_links_in_new_tab', 'enable_quoting'), - type: 'PUT' + type: 'PUT', + success: function(data) { + user.set('bio_excerpt',data.user.bio_excerpt); + } }).then(function() { Discourse.set('currentUser.enable_quoting', user.get('enable_quoting')); Discourse.set('currentUser.external_links_in_new_tab', user.get('external_links_in_new_tab')); @@ -329,6 +332,20 @@ Discourse.User = Discourse.Model.extend({ return r; }.property('stats.@each'), + onDetailsLoaded: function(callback){ + var _this = this; + + if(callback){ + this.onDetailsLoadedCallbacks = this.onDetailsLoadedCallbacks || []; + this.onDetailsLoadedCallbacks.push(callback); + } else { + var callbacks = this.onDetailsLoadedCallbacks; + $.each(callbacks, function(){ + this.apply(_this); + }); + } + }, + /** Load extra details for the user @@ -360,6 +377,7 @@ Discourse.User = Discourse.Model.extend({ user.setProperties(json.user); user.set('totalItems', count); + user.onDetailsLoaded(); }); } diff --git a/app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js b/app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js index 7e3f100e7..cbb75976f 100644 --- a/app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js +++ b/app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js @@ -9,13 +9,22 @@ Discourse.RestrictedUserRoute = Discourse.Route.extend({ enter: function(router, context) { - var user = this.controllerFor('user').get('content'); - this.allowed = user.can_edit; - }, + var _this = this; - redirect: function() { - if (!this.allowed) { - return this.transitionTo('user.activity'); + // a bit hacky, but we don't have a fully loaded user at this point + // so we need to wait for it + var user = this.controllerFor('user').get('content'); + + if(user.can_edit === undefined) { + user.onDetailsLoaded(function(){ + if (this.get('can_edit') === false) { + _this.transitionTo('user.activity'); + } + }); + } + + if(user.can_edit === false) { + this.transitionTo('user.activity'); } } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e0e744af2..6b06aaec7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -195,7 +195,7 @@ class ApplicationController < ActionController::Base # If we were given a serializer, add the class to the json that comes back if opts[:serializer].present? - json[obj.class.name.underscore] = opts[:serializer].new(obj).serializable_hash + json[obj.class.name.underscore] = opts[:serializer].new(obj, scope: guardian).serializable_hash end render json: MultiJson.dump(json) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1f1f0e9b3..0198d9378 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -29,7 +29,7 @@ class UsersController < ApplicationController def update user = User.where(username_lower: params[:username].downcase).first guardian.ensure_can_edit!(user) - json_result(user) do |u| + json_result(user, serializer: UserSerializer) do |u| website = params[:website] if website @@ -50,7 +50,11 @@ class UsersController < ApplicationController end end - u.save + if u.save + u + else + nil + end end end