FIX: If you follow a link to a user that doesn't exist, show 404

This commit is contained in:
Robin Ward 2015-06-29 15:47:05 -04:00
parent e026dc16d8
commit 1b1ea08ac3
1 changed files with 22 additions and 18 deletions

View File

@ -1,22 +1,22 @@
var INDEX_STREAM_ROUTES = ["user.deletedPosts", "user.flaggedPosts", "userActivity.index"];
const INDEX_STREAM_ROUTES = ["user.deletedPosts", "user.flaggedPosts", "userActivity.index"];
export default Discourse.Route.extend({
titleToken: function() {
var model = this.modelFor('user');
var username = model.get('username');
titleToken() {
const model = this.modelFor('user');
const username = model.get('username');
if (username) {
return [I18n.t("user.profile"), username];
}
},
actions: {
logout: function() {
logout() {
Discourse.logout();
},
composePrivateMessage: function(user, post) {
var recipient = user ? user.get('username') : '',
composePrivateMessage(user, post) {
const recipient = user ? user.get('username') : '',
reply = post ? window.location.protocol + "//" + window.location.host + post.get("url") : null;
return this.controllerFor('composer').open({
@ -28,18 +28,18 @@ export default Discourse.Route.extend({
});
},
willTransition: function(transition) {
willTransition(transition) {
// will reset the indexStream when transitioning to routes that aren't "indexStream"
// otherwise the "header" will jump
var isIndexStream = ~INDEX_STREAM_ROUTES.indexOf(transition.targetName);
const isIndexStream = ~INDEX_STREAM_ROUTES.indexOf(transition.targetName);
this.controllerFor('user').set('indexStream', isIndexStream);
return true;
}
},
model: function(params) {
model(params) {
// If we're viewing the currently logged in user, return that object instead
var currentUser = Discourse.User.current();
const currentUser = this.currentUser;
if (currentUser && (params.username.toLowerCase() === currentUser.get('username_lower'))) {
return currentUser;
}
@ -47,34 +47,38 @@ export default Discourse.Route.extend({
return Discourse.User.create({username: params.username});
},
afterModel: function() {
var user = this.modelFor('user');
afterModel() {
const user = this.modelFor('user');
const self = this;
return user.findDetails().then(function() {
return user.findStaffInfo();
}).catch(function() {
return self.replaceWith('/404');
});
},
serialize: function(model) {
serialize(model) {
if (!model) return {};
return { username: (Em.get(model, 'username') || '').toLowerCase() };
},
setupController: function(controller, user) {
setupController(controller, user) {
controller.set('model', user);
// Add a search context
this.controllerFor('search').set('searchContext', user.get('searchContext'));
},
activate: function() {
activate() {
this._super();
var user = this.modelFor('user');
const user = this.modelFor('user');
this.messageBus.subscribe("/users/" + user.get('username_lower'), function(data) {
user.loadUserAction(data);
});
},
deactivate: function() {
deactivate() {
this._super();
this.messageBus.unsubscribe("/users/" + this.modelFor('user').get('username_lower'));