2016-05-24 15:06:59 +03:00
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
2017-07-22 02:11:24 +03:00
|
|
|
|
2018-01-17 16:27:37 +03:00
|
|
|
export default AuthenticatedRoute.extend({
|
2015-10-28 14:36:45 +03:00
|
|
|
model(params) {
|
2016-11-14 13:53:15 +03:00
|
|
|
let query = {
|
|
|
|
id: params.post_id,
|
2014-06-17 23:17:08 +04:00
|
|
|
status: 'all',
|
2017-05-30 12:15:46 +03:00
|
|
|
staticPages: 'all',
|
|
|
|
formats: 'mobiledoc,plaintext'
|
2014-07-30 20:44:49 +04:00
|
|
|
};
|
2014-06-09 04:18:39 +04:00
|
|
|
|
2018-01-17 16:27:37 +03:00
|
|
|
return this.store.query('post', query)
|
|
|
|
.then(records => records.get('firstObject'));
|
2014-11-21 21:07:30 +03:00
|
|
|
},
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2018-01-17 16:27:37 +03:00
|
|
|
// the API will return a post even if the logged in user doesn't have
|
|
|
|
// permission to edit it (all posts are public) so we need to do our
|
|
|
|
// own permissions check and redirect if necessary
|
2015-10-28 14:36:45 +03:00
|
|
|
afterModel(post) {
|
2015-11-15 14:06:49 +03:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.get('session.user').then((user) => {
|
2018-02-07 12:42:46 +03:00
|
|
|
if (user.get('isAuthorOrContributor') && !post.isAuthoredByUser(user)) {
|
|
|
|
return this.replaceWith('posts.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the post is not a draft and user is contributor, redirect to index
|
|
|
|
if (user.get('isContributor') && !post.get('isDraft')) {
|
2016-01-26 13:08:38 +03:00
|
|
|
return this.replaceWith('posts.index');
|
2014-11-21 21:07:30 +03:00
|
|
|
}
|
2014-06-05 21:23:28 +04:00
|
|
|
});
|
2014-07-31 23:15:55 +04:00
|
|
|
},
|
|
|
|
|
2018-01-17 16:27:37 +03:00
|
|
|
// there's no specific controller for this route, instead all editor
|
|
|
|
// handling is done on the editor route/controler
|
|
|
|
setupController(controller, post) {
|
|
|
|
let editor = this.controllerFor('editor');
|
|
|
|
editor.setPost(post);
|
2014-03-02 18:30:35 +04:00
|
|
|
}
|
2014-03-04 00:18:10 +04:00
|
|
|
});
|