Merge pull request #4501 from jaswilli/routes

Fix up single post routes.
This commit is contained in:
Hannah Wolfe 2014-11-23 21:15:23 +00:00
commit aa58aef433
2 changed files with 35 additions and 35 deletions

View File

@ -8,7 +8,7 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, {
var self = this,
post,
postId,
paginationSettings;
query;
postId = Number(params.post_id);
@ -17,32 +17,34 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, {
}
post = this.store.getById('post', postId);
if (post) {
return post;
}
paginationSettings = {
query = {
id: postId,
status: 'all',
staticPages: 'all'
};
return this.store.find('user', 'me').then(function (user) {
if (user.get('isAuthor')) {
paginationSettings.author = user.get('slug');
}
return self.store.find('post', paginationSettings).then(function (records) {
return self.store.find('post', query).then(function (records) {
var post = records.get('firstObject');
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
// do not show the post if they are an author but not this posts author
post = null;
}
if (post) {
return post;
}
return self.transitionTo('posts.index');
return self.replaceWith('posts.index');
});
},
afterModel: function (post) {
var self = this;
return self.store.find('user', 'me').then(function (user) {
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return self.replaceWith('posts.index');
}
});
}
});

View File

@ -9,7 +9,7 @@ var PostsPostRoute = AuthenticatedRoute.extend(loadingIndicator, ShortcutsRoute,
var self = this,
post,
postId,
paginationSettings;
query;
postId = Number(params.post_id);
@ -18,36 +18,34 @@ var PostsPostRoute = AuthenticatedRoute.extend(loadingIndicator, ShortcutsRoute,
}
post = this.store.getById('post', postId);
if (post) {
return post;
}
paginationSettings = {
query = {
id: postId,
status: 'all',
staticPages: 'all'
};
return this.store.find('user', 'me').then(function (user) {
if (user.get('isAuthor')) {
paginationSettings.author = user.get('slug');
}
return self.store.find('post', paginationSettings).then(function (records) {
return self.store.find('post', query).then(function (records) {
var post = records.get('firstObject');
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
// do not show the post if they are an author but not this posts author
post = null;
}
if (post) {
return post;
}
return self.transitionTo('posts.index');
return self.replaceWith('posts.index');
});
},
afterModel: function (post) {
var self = this;
return self.store.find('user', 'me').then(function (user) {
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return self.replaceWith('posts.index');
}
});
},