2014-10-28 17:29:42 +03:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2014-11-04 06:31:10 +03:00
|
|
|
import base from 'ghost/mixins/editor-base-route';
|
2014-08-01 00:29:35 +04:00
|
|
|
import isNumber from 'ghost/utils/isNumber';
|
|
|
|
import isFinite from 'ghost/utils/isFinite';
|
2014-05-09 09:00:10 +04:00
|
|
|
|
2014-10-28 17:29:42 +03:00
|
|
|
var EditorEditRoute = AuthenticatedRoute.extend(base, {
|
2014-11-25 23:56:08 +03:00
|
|
|
titleToken: 'Editor',
|
|
|
|
|
2014-03-02 18:30:35 +04:00
|
|
|
model: function (params) {
|
2014-06-09 04:18:39 +04:00
|
|
|
var self = this,
|
2014-07-30 20:44:49 +04:00
|
|
|
postId,
|
2014-11-21 21:07:30 +03:00
|
|
|
query;
|
2014-06-06 05:18:03 +04:00
|
|
|
|
2014-06-09 04:18:39 +04:00
|
|
|
postId = Number(params.post_id);
|
|
|
|
|
2014-08-01 00:29:35 +04:00
|
|
|
if (!isNumber(postId) || !isFinite(postId) || postId % 1 !== 0 || postId <= 0) {
|
2014-07-02 18:09:04 +04:00
|
|
|
return this.transitionTo('error404', 'editor/' + params.post_id);
|
2014-06-09 04:18:39 +04:00
|
|
|
}
|
|
|
|
|
2014-11-21 21:07:30 +03:00
|
|
|
query = {
|
2014-07-30 20:44:49 +04:00
|
|
|
id: postId,
|
2014-06-17 23:17:08 +04:00
|
|
|
status: 'all',
|
2014-07-30 20:44:49 +04:00
|
|
|
staticPages: 'all'
|
|
|
|
};
|
2014-06-09 04:18:39 +04:00
|
|
|
|
2014-11-21 21:07:30 +03:00
|
|
|
return self.store.find('post', query).then(function (records) {
|
|
|
|
var post = records.get('firstObject');
|
2014-06-09 04:18:39 +04:00
|
|
|
|
2014-11-21 21:07:30 +03:00
|
|
|
if (post) {
|
|
|
|
return post;
|
|
|
|
}
|
2014-07-30 20:44:49 +04:00
|
|
|
|
2014-11-21 21:07:30 +03:00
|
|
|
return self.replaceWith('posts.index');
|
|
|
|
});
|
|
|
|
},
|
2014-07-31 12:29:05 +04:00
|
|
|
|
2014-11-21 21:07:30 +03:00
|
|
|
afterModel: function (post) {
|
|
|
|
var self = this;
|
2014-07-30 20:44:49 +04:00
|
|
|
|
2015-04-14 18:04:16 +03:00
|
|
|
return self.get('session.user').then(function (user) {
|
2014-11-21 21:07:30 +03:00
|
|
|
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
|
|
|
return self.replaceWith('posts.index');
|
|
|
|
}
|
2014-06-05 21:23:28 +04:00
|
|
|
});
|
2014-07-31 23:15:55 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2015-05-01 00:14:19 +03:00
|
|
|
authorizationFailed: function () {
|
2014-07-31 23:15:55 +04:00
|
|
|
this.send('openModal', 'signin');
|
|
|
|
}
|
2014-03-02 18:30:35 +04:00
|
|
|
}
|
2014-03-04 00:18:10 +04:00
|
|
|
});
|
|
|
|
|
2014-06-10 08:44:29 +04:00
|
|
|
export default EditorEditRoute;
|