this has been bugging me for ages, broken "fill your profile link" fixed AND bio updates when you save

This commit is contained in:
Sam 2013-04-12 10:07:46 +10:00
parent 04ca4077a7
commit 0f362c5474
4 changed files with 41 additions and 10 deletions

View File

@ -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();
});
}

View File

@ -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');
}
}

View File

@ -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)

View File

@ -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