Skip to content

Commit

Permalink
Avoid infinite transition loop
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ErisDS committed Apr 16, 2015
1 parent a11822c commit b4b5e2a
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 31 deletions.
4 changes: 0 additions & 4 deletions core/client/app/mixins/current-user-settings.js
@@ -1,9 +1,5 @@
import Ember from 'ember';
var CurrentUserSettings = Ember.Mixin.create({
currentUser: function () {
return this.store.find('user', 'me');
},

transitionAuthor: function () {
var self = this;

Expand Down
14 changes: 9 additions & 5 deletions core/client/app/routes/application.js
Expand Up @@ -76,7 +76,7 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut
return;
}

this.store.find('user', 'me').then(function (user) {
this.get('session.user').then(function (user) {
self.send('signedIn', user);
var attemptedTransition = self.get('session').get('attemptedTransition');
if (attemptedTransition) {
Expand Down Expand Up @@ -138,10 +138,14 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut
var self = this;

if (this.session.isAuthenticated) {
this.store.findAll('notification').then(function (serverNotifications) {
serverNotifications.forEach(function (notification) {
self.notifications.handleNotification(notification, isDelayed);
});
this.get('session.user').then(function (user) {
if (!user.get('isAuthor') && !user.get('isEditor')) {
self.store.findAll('notification').then(function (serverNotifications) {
serverNotifications.forEach(function (notification) {
self.notifications.handleNotification(notification, isDelayed);
});
});
}
});
}
},
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/editor/edit.js
Expand Up @@ -43,7 +43,7 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, {
afterModel: function (post) {
var self = this;

return self.store.find('user', 'me').then(function (user) {
return self.get('session.user').then(function (user) {
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return self.replaceWith('posts.index');
}
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/posts.js
Expand Up @@ -22,7 +22,7 @@ PostsRoute = AuthenticatedRoute.extend(ShortcutsRoute, styleBody, loadingIndicat
model: function () {
var self = this;

return this.store.find('user', 'me').then(function (user) {
return this.get('session.user').then(function (user) {
if (user.get('isAuthor')) {
paginationSettings.author = user.get('slug');
}
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/posts/index.js
Expand Up @@ -23,7 +23,7 @@ var PostsIndexRoute = MobileIndexRoute.extend(SimpleAuth.AuthenticatedRouteMixin
posts = this.store.all('post'),
post;

return this.store.find('user', 'me').then(function (user) {
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')) {
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/posts/post.js
Expand Up @@ -42,7 +42,7 @@ var PostsPostRoute = AuthenticatedRoute.extend(loadingIndicator, ShortcutsRoute,
afterModel: function (post) {
var self = this;

return self.store.find('user', 'me').then(function (user) {
return self.get('session.user').then(function (user) {
if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return self.replaceWith('posts.index');
}
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/settings/apps.js
Expand Up @@ -12,7 +12,7 @@ var AppsRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
return this.transitionTo('settings.general');
}

return this.currentUser()
return this.get('session.user')
.then(this.transitionAuthor())
.then(this.transitionEditor());
},
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/settings/code-injection.js
Expand Up @@ -7,7 +7,7 @@ var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingInd
classNames: ['settings-view-code'],

beforeModel: function () {
return this.currentUser()
return this.get('session.user')
.then(this.transitionAuthor())
.then(this.transitionEditor());
},
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/settings/general.js
Expand Up @@ -9,7 +9,7 @@ var SettingsGeneralRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator
classNames: ['settings-view-general'],

beforeModel: function () {
return this.currentUser()
return this.get('session.user')
.then(this.transitionAuthor())
.then(this.transitionEditor());
},
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/settings/index.js
Expand Up @@ -10,7 +10,7 @@ var SettingsIndexRoute = MobileIndexRoute.extend(SimpleAuth.AuthenticatedRouteMi
// is mobile
beforeModel: function () {
var self = this;
return this.currentUser()
return this.get('session.user')
.then(this.transitionAuthor())
.then(this.transitionEditor())
.then(function () {
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/settings/labs.js
Expand Up @@ -8,7 +8,7 @@ var LabsRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUs

classNames: ['settings'],
beforeModel: function () {
return this.currentUser()
return this.get('session.user')
.then(this.transitionAuthor())
.then(this.transitionEditor());
},
Expand Down
3 changes: 2 additions & 1 deletion core/client/app/routes/settings/navigation.js
Expand Up @@ -9,7 +9,8 @@ var NavigationRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings,
classNames: ['settings-view-navigation'],

beforeModel: function () {
return this.currentUser().then(this.transitionAuthor());
return this.get('session.user')
.then(this.transitionAuthor());
},

model: function () {
Expand Down
2 changes: 1 addition & 1 deletion core/client/app/routes/settings/tags.js
Expand Up @@ -21,7 +21,7 @@ TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin,
titleToken: 'Tags',

beforeModel: function () {
return this.currentUser()
return this.get('session.user')
.then(this.transitionAuthor());
},

Expand Down
8 changes: 1 addition & 7 deletions core/client/app/routes/settings/users.js
@@ -1,11 +1,5 @@
import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';

var UsersRoute = AuthenticatedRoute.extend(CurrentUserSettings, {
beforeModel: function () {
return this.currentUser()
.then(this.transitionAuthor());
}
});
var UsersRoute = AuthenticatedRoute.extend();

export default UsersRoute;
10 changes: 8 additions & 2 deletions core/client/app/routes/settings/users/index.js
@@ -1,4 +1,5 @@
import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import PaginationRouteMixin from 'ghost/mixins/pagination-route';
import styleBody from 'ghost/mixins/style-body';

Expand All @@ -11,7 +12,7 @@ paginationSettings = {
status: 'active'
};

UsersIndexRoute = AuthenticatedRoute.extend(styleBody, PaginationRouteMixin, {
UsersIndexRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, PaginationRouteMixin, {
titleToken: 'Users',

classNames: ['settings-view-users'],
Expand All @@ -21,11 +22,16 @@ UsersIndexRoute = AuthenticatedRoute.extend(styleBody, PaginationRouteMixin, {
this.setupPagination(paginationSettings);
},

beforeModel: function () {
return this.get('session.user')
.then(this.transitionAuthor());
},

model: function () {
var self = this;

return self.store.find('user', {limit: 'all', status: 'invited'}).then(function () {
return self.store.find('user', 'me').then(function (currentUser) {
return self.get('session.user').then(function (currentUser) {
if (currentUser.get('isEditor')) {
// Editors only see authors in the list
paginationSettings.role = 'Author';
Expand Down
5 changes: 3 additions & 2 deletions core/client/app/routes/settings/users/user.js
@@ -1,7 +1,8 @@
import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import styleBody from 'ghost/mixins/style-body';

var SettingsUserRoute = AuthenticatedRoute.extend(styleBody, {
var SettingsUserRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
titleToken: 'User',

classNames: ['settings-view-user'],
Expand All @@ -25,7 +26,7 @@ var SettingsUserRoute = AuthenticatedRoute.extend(styleBody, {

afterModel: function (user) {
var self = this;
this.store.find('user', 'me').then(function (currentUser) {
return this.get('session.user').then(function (currentUser) {
var isOwnProfile = user.get('id') === currentUser.get('id'),
isAuthor = currentUser.get('isAuthor'),
isEditor = currentUser.get('isEditor');
Expand Down

0 comments on commit b4b5e2a

Please sign in to comment.