2014-06-04 23:18:23 -04:00
|
|
|
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
2014-06-13 13:35:22 -06:00
|
|
|
|
2014-07-25 15:38:13 +02:00
|
|
|
var PostsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, {
|
2014-07-21 14:13:52 +00:00
|
|
|
// This route's only function is to determine whether or not a post
|
|
|
|
// exists to be used for the content preview. It has a parent resource (Posts)
|
|
|
|
// that is responsible for populating the store.
|
2014-06-17 15:17:08 -04:00
|
|
|
beforeModel: function () {
|
2014-07-31 09:29:05 +01:00
|
|
|
var self = this,
|
2014-07-21 14:13:52 +00:00
|
|
|
// the store has been populated so we can work with the local copy
|
2014-07-31 07:25:40 -04:00
|
|
|
posts = this.store.all('post');
|
2014-03-02 15:30:35 +01:00
|
|
|
|
2014-07-31 07:25:40 -04:00
|
|
|
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;
|
2014-07-31 09:29:05 +01:00
|
|
|
}
|
|
|
|
});
|
2014-07-31 07:25:40 -04:00
|
|
|
})
|
|
|
|
.then(function (post) {
|
|
|
|
if (post) {
|
|
|
|
return self.transitionTo('posts.post', post);
|
|
|
|
}
|
|
|
|
});
|
2014-03-02 15:30:35 +01:00
|
|
|
}
|
2014-03-03 21:18:10 +01:00
|
|
|
});
|
|
|
|
|
2014-07-31 07:25:40 -04:00
|
|
|
export default PostsIndexRoute;
|