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-11-25 12:56:08 -08:00
|
|
|
titleToken: 'Editor',
|
|
|
|
|
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,
|
2014-11-21 18:07:30 +00:00
|
|
|
query;
|
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-11-21 18:07:30 +00:00
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
2014-06-05 13:23:28 -04:00
|
|
|
|
2014-11-21 18:07:30 +00:00
|
|
|
query = {
|
2014-07-30 17:44:49 +01:00
|
|
|
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-11-21 18:07:30 +00:00
|
|
|
return self.store.find('post', query).then(function (records) {
|
|
|
|
var post = records.get('firstObject');
|
2014-06-09 00:18:39 +00:00
|
|
|
|
2014-11-21 18:07:30 +00:00
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
2014-07-30 17:44:49 +01:00
|
|
|
|
2014-11-21 18:07:30 +00:00
|
|
|
return self.replaceWith('posts.index');
|
|
|
|
});
|
|
|
|
},
|
2014-07-31 09:29:05 +01:00
|
|
|
|
2014-11-21 18:07:30 +00:00
|
|
|
afterModel: function (post) {
|
|
|
|
var self = this;
|
2014-07-30 17:44:49 +01:00
|
|
|
|
2014-11-21 18:07:30 +00:00
|
|
|
return self.store.find('user', 'me').then(function (user) {
|
|
|
|
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
|
|
|
return self.replaceWith('posts.index');
|
|
|
|
}
|
2014-06-05 13:23:28 -04:00
|
|
|
});
|
2014-07-31 21:15:55 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
authorizationFailed: function () {
|
|
|
|
this.send('openModal', 'signin');
|
|
|
|
}
|
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;
|