From 774d027ffb5b6a8c2dad7ae4d7b8bcd46b1a9b66 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 31 Jul 2014 07:25:40 -0400 Subject: [PATCH] Redirect to the first available post for current user. --- ghost/admin/routes/posts/index.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/ghost/admin/routes/posts/index.js b/ghost/admin/routes/posts/index.js index 41f1599b1a..496b1b29c6 100644 --- a/ghost/admin/routes/posts/index.js +++ b/ghost/admin/routes/posts/index.js @@ -7,19 +7,26 @@ var PostsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loa beforeModel: function () { var self = this, // 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) { - if (user.get('isAuthor') && post.isAuthoredByUser(user)) { - // do not show the post if they are an author but not this posts author - return; + return this.store.find('user', 'me').then(function (user) { + // return the first post find that matches the following criteria: + // * User is an author, and is the author of this post + // * User has a role other than author + 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; \ No newline at end of file +export default PostsIndexRoute;