2015-10-28 14:36:45 +03:00
|
|
|
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
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';
|
2015-12-04 01:37:23 +03:00
|
|
|
import NotFoundHandler from 'ghost/mixins/404-handler';
|
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
|
|
|
|
2015-12-04 01:37:23 +03:00
|
|
|
export default AuthenticatedRoute.extend(base, NotFoundHandler, {
|
2014-11-25 23:56:08 +03:00
|
|
|
titleToken: 'Editor',
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
beforeModel(transition) {
|
2015-07-04 21:25:55 +03:00
|
|
|
this.set('_transitionedFromNew', transition.data.fromNew);
|
|
|
|
|
|
|
|
this._super(...arguments);
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
model(params) {
|
|
|
|
let 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) {
|
2015-10-28 14:36:45 +03: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
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.store.query('post', query).then((records) => {
|
|
|
|
let 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
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.replaceRoute('posts.index');
|
2014-11-21 21:07:30 +03:00
|
|
|
});
|
|
|
|
},
|
2014-07-31 12:29:05 +04:00
|
|
|
|
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) => {
|
2014-11-21 21:07:30 +03:00
|
|
|
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.replaceRoute('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
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
setupController(controller) {
|
2015-07-04 21:25:55 +03:00
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
controller.set('shouldFocusEditor', this.get('_transitionedFromNew'));
|
|
|
|
},
|
|
|
|
|
2014-07-31 23:15:55 +04:00
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
authorizationFailed() {
|
2015-11-18 13:50:48 +03:00
|
|
|
this.get('controller').send('toggleReAuthenticateModal');
|
2014-07-31 23:15:55 +04:00
|
|
|
}
|
2014-03-02 18:30:35 +04:00
|
|
|
}
|
2014-03-04 00:18:10 +04:00
|
|
|
});
|