mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
Merge pull request #4501 from jaswilli/routes
Fix up single post routes.
This commit is contained in:
commit
aa58aef433
@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -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');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user