2014-10-28 08:29:42 -06:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2014-11-03 20:31:10 -07:00
|
|
|
import base from 'ghost/mixins/editor-base-route';
|
2014-07-31 16:29:35 -04:00
|
|
|
import isNumber from 'ghost/utils/isNumber';
|
|
|
|
import isFinite from 'ghost/utils/isFinite';
|
2014-05-09 00:00:10 -05:00
|
|
|
|
2014-10-28 08:29:42 -06:00
|
|
|
var EditorEditRoute = AuthenticatedRoute.extend(base, {
|
2014-03-02 15:30:35 +01:00
|
|
|
model: function (params) {
|
2014-06-09 00:18:39 +00:00
|
|
|
var self = this,
|
|
|
|
post,
|
2014-07-30 17:44:49 +01:00
|
|
|
postId,
|
|
|
|
paginationSettings;
|
2014-06-05 21:18:03 -04:00
|
|
|
|
2014-06-09 00:18:39 +00:00
|
|
|
postId = Number(params.post_id);
|
|
|
|
|
2014-07-31 16:29:35 -04:00
|
|
|
if (!isNumber(postId) || !isFinite(postId) || postId % 1 !== 0 || postId <= 0) {
|
2014-07-02 14:09:04 +00:00
|
|
|
return this.transitionTo('error404', 'editor/' + params.post_id);
|
2014-06-09 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
post = this.store.getById('post', postId);
|
2014-06-05 13:23:28 -04:00
|
|
|
|
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
paginationSettings = {
|
|
|
|
id: postId,
|
2014-06-17 15:17:08 -04:00
|
|
|
status: 'all',
|
2014-07-30 17:44:49 +01:00
|
|
|
staticPages: 'all'
|
|
|
|
};
|
2014-06-09 00:18:39 +00:00
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
return this.store.find('user', 'me').then(function (user) {
|
|
|
|
if (user.get('isAuthor')) {
|
|
|
|
paginationSettings.author = user.get('slug');
|
2014-06-09 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
return self.store.find('post', paginationSettings).then(function (records) {
|
|
|
|
var post = records.get('firstObject');
|
|
|
|
|
2014-07-31 09:29:05 +01:00
|
|
|
if (user.get('isAuthor') && post.isAuthoredByUser(user)) {
|
|
|
|
// do not show the post if they are an author but not this posts author
|
|
|
|
post = null;
|
|
|
|
}
|
|
|
|
|
2014-07-30 17:44:49 +01:00
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.transitionTo('posts.index');
|
|
|
|
});
|
2014-06-05 13:23:28 -04:00
|
|
|
});
|
2014-03-02 15:30:35 +01:00
|
|
|
}
|
2014-03-03 21:18:10 +01:00
|
|
|
});
|
|
|
|
|
2014-06-09 22:44:29 -06:00
|
|
|
export default EditorEditRoute;
|