0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Redirect to the first available post for current user.

This commit is contained in:
Robert Jackson 2014-07-31 07:25:40 -04:00 committed by Hannah Wolfe
parent 74549ddc59
commit 774d027ffb

View file

@ -7,19 +7,26 @@ var PostsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loa
beforeModel: function () { beforeModel: function () {
var self = this, var self = this,
// the store has been populated so we can work with the local copy // the store has been populated so we can work with the local copy
post = this.store.all('post').get('firstObject'); posts = this.store.all('post');
if (post) { return this.store.find('user', 'me').then(function (user) {
return this.store.find('user', 'me').then(function (user) { // return the first post find that matches the following criteria:
if (user.get('isAuthor') && post.isAuthoredByUser(user)) { // * User is an author, and is the author of this post
// do not show the post if they are an author but not this posts author // * User has a role other than author
return; return posts.find(function (post) {
if (user.get('isAuthor')) {
return post.isAuthoredByUser(user);
} else {
return true;
} }
return self.transitionTo('posts.post', post);
}); });
} })
.then(function (post) {
if (post) {
return self.transitionTo('posts.post', post);
}
});
} }
}); });
export default PostsIndexRoute; export default PostsIndexRoute;