mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
refs #6039, closes #6047, closes #6048 - delete old/unused fixtures file - add failing tests for #6047 & #6048 - redirect to sign-in if we get a 401 when making an API request - fix incorrect `this.notifications` call in tag controller - raise `authorizationFailed` action in application route's `sessionInvalidated` hook so that it can be handled by leaf routes (fixes re-auth modal display) - close "saving failed" alert when successfully re-authenticated - adds a "window-proxy" util so that we can override `window.*` operations in tests - fix `gh-selectize` attempting to register event handlers when the component has already been destroyed
75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
|
import isNumber from 'ghost/utils/isNumber';
|
|
import isFinite from 'ghost/utils/isFinite';
|
|
|
|
export default AuthenticatedRoute.extend(ShortcutsRoute, {
|
|
model: function (params) {
|
|
var self = this,
|
|
post,
|
|
postId,
|
|
query;
|
|
|
|
postId = Number(params.post_id);
|
|
|
|
if (!isNumber(postId) || !isFinite(postId) || postId % 1 !== 0 || postId <= 0) {
|
|
return this.transitionTo('error404', params.post_id);
|
|
}
|
|
|
|
post = this.store.peekRecord('post', postId);
|
|
if (post) {
|
|
return post;
|
|
}
|
|
|
|
query = {
|
|
id: postId,
|
|
status: 'all',
|
|
staticPages: 'all'
|
|
};
|
|
|
|
return self.store.queryRecord('post', query).then(function (post) {
|
|
if (post) {
|
|
return post;
|
|
}
|
|
|
|
return self.replaceRoute('posts.index');
|
|
});
|
|
},
|
|
|
|
afterModel: function (post) {
|
|
var self = this;
|
|
|
|
return self.get('session.user').then(function (user) {
|
|
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
|
|
return self.replaceRoute('posts.index');
|
|
}
|
|
});
|
|
},
|
|
|
|
setupController: function (controller, model) {
|
|
this._super(controller, model);
|
|
|
|
this.controllerFor('posts').set('currentPost', model);
|
|
},
|
|
|
|
shortcuts: {
|
|
'enter, o': 'openEditor',
|
|
'command+backspace, ctrl+backspace': 'deletePost'
|
|
},
|
|
|
|
actions: {
|
|
openEditor: function (post) {
|
|
post = post || this.get('controller.model');
|
|
|
|
if (!post) {
|
|
return;
|
|
}
|
|
|
|
this.transitionTo('editor.edit', post.get('id'));
|
|
},
|
|
|
|
deletePost: function () {
|
|
this.send('openModal', 'delete-post', this.get('controller.model'));
|
|
}
|
|
}
|
|
});
|