0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

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
This commit is contained in:
Hannah Wolfe 2015-04-14 16:04:16 +01:00
parent a11822c80d
commit b4b5e2a3f5
16 changed files with 33 additions and 31 deletions

View file

@ -1,9 +1,5 @@
import Ember from 'ember'; import Ember from 'ember';
var CurrentUserSettings = Ember.Mixin.create({ var CurrentUserSettings = Ember.Mixin.create({
currentUser: function () {
return this.store.find('user', 'me');
},
transitionAuthor: function () { transitionAuthor: function () {
var self = this; var self = this;

View file

@ -76,7 +76,7 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut
return; return;
} }
this.store.find('user', 'me').then(function (user) { this.get('session.user').then(function (user) {
self.send('signedIn', user); self.send('signedIn', user);
var attemptedTransition = self.get('session').get('attemptedTransition'); var attemptedTransition = self.get('session').get('attemptedTransition');
if (attemptedTransition) { if (attemptedTransition) {
@ -138,10 +138,14 @@ ApplicationRoute = Ember.Route.extend(SimpleAuth.ApplicationRouteMixin, Shortcut
var self = this; var self = this;
if (this.session.isAuthenticated) { if (this.session.isAuthenticated) {
this.store.findAll('notification').then(function (serverNotifications) { this.get('session.user').then(function (user) {
serverNotifications.forEach(function (notification) { if (!user.get('isAuthor') && !user.get('isEditor')) {
self.notifications.handleNotification(notification, isDelayed); self.store.findAll('notification').then(function (serverNotifications) {
}); serverNotifications.forEach(function (notification) {
self.notifications.handleNotification(notification, isDelayed);
});
});
}
}); });
} }
}, },

View file

@ -43,7 +43,7 @@ var EditorEditRoute = AuthenticatedRoute.extend(base, {
afterModel: function (post) { afterModel: function (post) {
var self = this; 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)) { if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return self.replaceWith('posts.index'); return self.replaceWith('posts.index');
} }

View file

@ -22,7 +22,7 @@ PostsRoute = AuthenticatedRoute.extend(ShortcutsRoute, styleBody, loadingIndicat
model: function () { model: function () {
var self = this; var self = this;
return this.store.find('user', 'me').then(function (user) { return this.get('session.user').then(function (user) {
if (user.get('isAuthor')) { if (user.get('isAuthor')) {
paginationSettings.author = user.get('slug'); paginationSettings.author = user.get('slug');
} }

View file

@ -23,7 +23,7 @@ var PostsIndexRoute = MobileIndexRoute.extend(SimpleAuth.AuthenticatedRouteMixin
posts = this.store.all('post'), posts = this.store.all('post'),
post; post;
return this.store.find('user', 'me').then(function (user) { return this.get('session.user').then(function (user) {
post = posts.find(function (post) { post = posts.find(function (post) {
// Authors can only see posts they've written // Authors can only see posts they've written
if (user.get('isAuthor')) { if (user.get('isAuthor')) {

View file

@ -42,7 +42,7 @@ var PostsPostRoute = AuthenticatedRoute.extend(loadingIndicator, ShortcutsRoute,
afterModel: function (post) { afterModel: function (post) {
var self = this; 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)) { if (user.get('isAuthor') && !post.isAuthoredByUser(user)) {
return self.replaceWith('posts.index'); return self.replaceWith('posts.index');
} }

View file

@ -12,7 +12,7 @@ var AppsRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
return this.transitionTo('settings.general'); return this.transitionTo('settings.general');
} }
return this.currentUser() return this.get('session.user')
.then(this.transitionAuthor()) .then(this.transitionAuthor())
.then(this.transitionEditor()); .then(this.transitionEditor());
}, },

View file

@ -7,7 +7,7 @@ var SettingsCodeInjectionRoute = AuthenticatedRoute.extend(styleBody, loadingInd
classNames: ['settings-view-code'], classNames: ['settings-view-code'],
beforeModel: function () { beforeModel: function () {
return this.currentUser() return this.get('session.user')
.then(this.transitionAuthor()) .then(this.transitionAuthor())
.then(this.transitionEditor()); .then(this.transitionEditor());
}, },

View file

@ -9,7 +9,7 @@ var SettingsGeneralRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator
classNames: ['settings-view-general'], classNames: ['settings-view-general'],
beforeModel: function () { beforeModel: function () {
return this.currentUser() return this.get('session.user')
.then(this.transitionAuthor()) .then(this.transitionAuthor())
.then(this.transitionEditor()); .then(this.transitionEditor());
}, },

View file

@ -10,7 +10,7 @@ var SettingsIndexRoute = MobileIndexRoute.extend(SimpleAuth.AuthenticatedRouteMi
// is mobile // is mobile
beforeModel: function () { beforeModel: function () {
var self = this; var self = this;
return this.currentUser() return this.get('session.user')
.then(this.transitionAuthor()) .then(this.transitionAuthor())
.then(this.transitionEditor()) .then(this.transitionEditor())
.then(function () { .then(function () {

View file

@ -8,7 +8,7 @@ var LabsRoute = AuthenticatedRoute.extend(styleBody, loadingIndicator, CurrentUs
classNames: ['settings'], classNames: ['settings'],
beforeModel: function () { beforeModel: function () {
return this.currentUser() return this.get('session.user')
.then(this.transitionAuthor()) .then(this.transitionAuthor())
.then(this.transitionEditor()); .then(this.transitionEditor());
}, },

View file

@ -9,7 +9,8 @@ var NavigationRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings,
classNames: ['settings-view-navigation'], classNames: ['settings-view-navigation'],
beforeModel: function () { beforeModel: function () {
return this.currentUser().then(this.transitionAuthor()); return this.get('session.user')
.then(this.transitionAuthor());
}, },
model: function () { model: function () {

View file

@ -21,7 +21,7 @@ TagsRoute = AuthenticatedRoute.extend(CurrentUserSettings, PaginationRouteMixin,
titleToken: 'Tags', titleToken: 'Tags',
beforeModel: function () { beforeModel: function () {
return this.currentUser() return this.get('session.user')
.then(this.transitionAuthor()); .then(this.transitionAuthor());
}, },

View file

@ -1,11 +1,5 @@
import AuthenticatedRoute from 'ghost/routes/authenticated'; import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
var UsersRoute = AuthenticatedRoute.extend(CurrentUserSettings, { var UsersRoute = AuthenticatedRoute.extend();
beforeModel: function () {
return this.currentUser()
.then(this.transitionAuthor());
}
});
export default UsersRoute; export default UsersRoute;

View file

@ -1,4 +1,5 @@
import AuthenticatedRoute from 'ghost/routes/authenticated'; import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import PaginationRouteMixin from 'ghost/mixins/pagination-route'; import PaginationRouteMixin from 'ghost/mixins/pagination-route';
import styleBody from 'ghost/mixins/style-body'; import styleBody from 'ghost/mixins/style-body';
@ -11,7 +12,7 @@ paginationSettings = {
status: 'active' status: 'active'
}; };
UsersIndexRoute = AuthenticatedRoute.extend(styleBody, PaginationRouteMixin, { UsersIndexRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, PaginationRouteMixin, {
titleToken: 'Users', titleToken: 'Users',
classNames: ['settings-view-users'], classNames: ['settings-view-users'],
@ -21,11 +22,16 @@ UsersIndexRoute = AuthenticatedRoute.extend(styleBody, PaginationRouteMixin, {
this.setupPagination(paginationSettings); this.setupPagination(paginationSettings);
}, },
beforeModel: function () {
return this.get('session.user')
.then(this.transitionAuthor());
},
model: function () { model: function () {
var self = this; var self = this;
return self.store.find('user', {limit: 'all', status: 'invited'}).then(function () { 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')) { if (currentUser.get('isEditor')) {
// Editors only see authors in the list // Editors only see authors in the list
paginationSettings.role = 'Author'; paginationSettings.role = 'Author';

View file

@ -1,7 +1,8 @@
import AuthenticatedRoute from 'ghost/routes/authenticated'; import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import styleBody from 'ghost/mixins/style-body'; import styleBody from 'ghost/mixins/style-body';
var SettingsUserRoute = AuthenticatedRoute.extend(styleBody, { var SettingsUserRoute = AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
titleToken: 'User', titleToken: 'User',
classNames: ['settings-view-user'], classNames: ['settings-view-user'],
@ -25,7 +26,7 @@ var SettingsUserRoute = AuthenticatedRoute.extend(styleBody, {
afterModel: function (user) { afterModel: function (user) {
var self = this; 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'), var isOwnProfile = user.get('id') === currentUser.get('id'),
isAuthor = currentUser.get('isAuthor'), isAuthor = currentUser.get('isAuthor'),
isEditor = currentUser.get('isEditor'); isEditor = currentUser.get('isEditor');