1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/routes/posts/index.js
Hannah Wolfe f770faab99 Avoid infinite transition loop
fixes #5136

- wrap notification fetch with a user role check to remove console error
- move author transition down to local route for users/user so that there's no infinite loop
- replace all store calls to fetch the current user with the session user instead
2015-04-16 20:05:30 +01:00

51 lines
1.4 KiB
JavaScript

import MobileIndexRoute from 'ghost/routes/mobile-index-route';
import loadingIndicator from 'ghost/mixins/loading-indicator';
import mobileQuery from 'ghost/utils/mobile';
var PostsIndexRoute = MobileIndexRoute.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, {
noPosts: false,
// Transition to a specific post if we're not on mobile
beforeModel: function () {
if (!mobileQuery.matches) {
return this.goToPost();
}
},
setupController: function (controller, model) {
/*jshint unused:false*/
controller.set('noPosts', this.get('noPosts'));
},
goToPost: function () {
var self = this,
// the store has been populated by PostsRoute
posts = this.store.all('post'),
post;
return this.get('session.user').then(function (user) {
post = posts.find(function (post) {
// Authors can only see posts they've written
if (user.get('isAuthor')) {
return post.isAuthoredByUser(user);
}
return true;
});
if (post) {
return self.transitionTo('posts.post', post);
}
self.set('noPosts', true);
});
},
// Mobile posts route callback
desktopTransition: function () {
this.goToPost();
}
});
export default PostsIndexRoute;