mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-04-29 15:35:23 -04:00
this has been bugging me for ages, broken "fill your profile link" fixed AND bio updates when you save
This commit is contained in:
parent
04ca4077a7
commit
0f362c5474
4 changed files with 41 additions and 10 deletions
app
assets/javascripts/discourse
controllers
|
@ -142,7 +142,10 @@ Discourse.User = Discourse.Model.extend({
|
||||||
'new_topic_duration_minutes',
|
'new_topic_duration_minutes',
|
||||||
'external_links_in_new_tab',
|
'external_links_in_new_tab',
|
||||||
'enable_quoting'),
|
'enable_quoting'),
|
||||||
type: 'PUT'
|
type: 'PUT',
|
||||||
|
success: function(data) {
|
||||||
|
user.set('bio_excerpt',data.user.bio_excerpt);
|
||||||
|
}
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
Discourse.set('currentUser.enable_quoting', user.get('enable_quoting'));
|
Discourse.set('currentUser.enable_quoting', user.get('enable_quoting'));
|
||||||
Discourse.set('currentUser.external_links_in_new_tab', user.get('external_links_in_new_tab'));
|
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;
|
return r;
|
||||||
}.property('stats.@each'),
|
}.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
|
Load extra details for the user
|
||||||
|
|
||||||
|
@ -360,6 +377,7 @@ Discourse.User = Discourse.Model.extend({
|
||||||
|
|
||||||
user.setProperties(json.user);
|
user.setProperties(json.user);
|
||||||
user.set('totalItems', count);
|
user.set('totalItems', count);
|
||||||
|
user.onDetailsLoaded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,13 +9,22 @@
|
||||||
Discourse.RestrictedUserRoute = Discourse.Route.extend({
|
Discourse.RestrictedUserRoute = Discourse.Route.extend({
|
||||||
|
|
||||||
enter: function(router, context) {
|
enter: function(router, context) {
|
||||||
var user = this.controllerFor('user').get('content');
|
var _this = this;
|
||||||
this.allowed = user.can_edit;
|
|
||||||
},
|
|
||||||
|
|
||||||
redirect: function() {
|
// a bit hacky, but we don't have a fully loaded user at this point
|
||||||
if (!this.allowed) {
|
// so we need to wait for it
|
||||||
return this.transitionTo('user.activity');
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,7 +195,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# If we were given a serializer, add the class to the json that comes back
|
# If we were given a serializer, add the class to the json that comes back
|
||||||
if opts[:serializer].present?
|
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
|
end
|
||||||
|
|
||||||
render json: MultiJson.dump(json)
|
render json: MultiJson.dump(json)
|
||||||
|
|
|
@ -29,7 +29,7 @@ class UsersController < ApplicationController
|
||||||
def update
|
def update
|
||||||
user = User.where(username_lower: params[:username].downcase).first
|
user = User.where(username_lower: params[:username].downcase).first
|
||||||
guardian.ensure_can_edit!(user)
|
guardian.ensure_can_edit!(user)
|
||||||
json_result(user) do |u|
|
json_result(user, serializer: UserSerializer) do |u|
|
||||||
|
|
||||||
website = params[:website]
|
website = params[:website]
|
||||||
if website
|
if website
|
||||||
|
@ -50,7 +50,11 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
u.save
|
if u.save
|
||||||
|
u
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue