mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
f02c2acd71
* Ensures that posts listing only shows posts that the current user authored, if they only have the Author role. * Do not transition into the posts.post route if the current user is not the author (but has the Author role). This is needed because the API server will always return the post (regardless of the current user).
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
import styleBody from 'ghost/mixins/style-body';
|
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
|
import PaginationRouteMixin from 'ghost/mixins/pagination-route';
|
|
|
|
var paginationSettings = {
|
|
status: 'all',
|
|
staticPages: 'all',
|
|
page: 1
|
|
};
|
|
|
|
var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, ShortcutsRoute, styleBody, loadingIndicator, PaginationRouteMixin, {
|
|
classNames: ['manage'],
|
|
|
|
model: function () {
|
|
var self = this;
|
|
|
|
return this.store.find('user', 'me').then(function (user) {
|
|
if (user.get('isAuthor')) {
|
|
paginationSettings.author = user.get('slug');
|
|
}
|
|
// using `.filter` allows the template to auto-update when new models are pulled in from the server.
|
|
// we just need to 'return true' to allow all models by default.
|
|
return self.store.filter('post', paginationSettings, function (post) {
|
|
if (user.get('isAuthor')) {
|
|
return user.get('id') === post.get('author_id');
|
|
}
|
|
|
|
return true;
|
|
});
|
|
});
|
|
},
|
|
|
|
setupController: function (controller, model) {
|
|
this._super(controller, model);
|
|
this.setupPagination(paginationSettings);
|
|
},
|
|
|
|
stepThroughPosts: function (step) {
|
|
var currentPost = this.get('controller.currentPost'),
|
|
posts = this.get('controller.model'),
|
|
length = posts.get('length'),
|
|
newPosition;
|
|
|
|
newPosition = posts.indexOf(currentPost) + step;
|
|
|
|
//Make sure we're inbounds
|
|
if (newPosition >= length) {
|
|
newPosition = 0;
|
|
}
|
|
else if (newPosition < 0) {
|
|
newPosition = length - 1;
|
|
}
|
|
this.transitionTo('posts.post', posts.objectAt(newPosition));
|
|
},
|
|
|
|
shortcuts: {
|
|
'up': 'moveUp',
|
|
'down': 'moveDown'
|
|
},
|
|
actions: {
|
|
openEditor: function (post) {
|
|
this.transitionTo('editor.edit', post);
|
|
},
|
|
moveUp: function () {
|
|
this.stepThroughPosts(-1);
|
|
},
|
|
moveDown: function () {
|
|
this.stepThroughPosts(1);
|
|
}
|
|
}
|
|
});
|
|
|
|
export default PostsRoute;
|