mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fix up single post routes.
No Issue - Add local store lookup back to edit route. - Prevent entry into route when an author is not the owner of a post even if model is passed in. - Clean up references to pagination as there's no pagination going on.
This commit is contained in:
parent
3fd6c80bb7
commit
915fa17436
2 changed files with 35 additions and 35 deletions
|
@ -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', query).then(function (records) {
|
||||
var post = records.get('firstObject');
|
||||
|
||||
if (post) {
|
||||
return post;
|
||||
}
|
||||
|
||||
return self.store.find('post', paginationSettings).then(function (records) {
|
||||
var post = records.get('firstObject');
|
||||
return self.replaceWith('posts.index');
|
||||
});
|
||||
},
|
||||
|
||||
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
||||
// do not show the post if they are an author but not this posts author
|
||||
post = null;
|
||||
}
|
||||
afterModel: function (post) {
|
||||
var self = this;
|
||||
|
||||
if (post) {
|
||||
return post;
|
||||
}
|
||||
|
||||
return self.transitionTo('posts.index');
|
||||
});
|
||||
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', query).then(function (records) {
|
||||
var post = records.get('firstObject');
|
||||
|
||||
if (post) {
|
||||
return post;
|
||||
}
|
||||
|
||||
return self.store.find('post', paginationSettings).then(function (records) {
|
||||
var post = records.get('firstObject');
|
||||
return self.replaceWith('posts.index');
|
||||
});
|
||||
},
|
||||
|
||||
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
||||
// do not show the post if they are an author but not this posts author
|
||||
post = null;
|
||||
}
|
||||
afterModel: function (post) {
|
||||
var self = this;
|
||||
|
||||
if (post) {
|
||||
return post;
|
||||
}
|
||||
|
||||
return self.transitionTo('posts.index');
|
||||
});
|
||||
return self.store.find('user', 'me').then(function (user) {
|
||||
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
||||
return self.replaceWith('posts.index');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue