Merge pull request #3416 from alarobric/case_3291

Settings screens redirect for certain roles
This commit is contained in:
Hannah Wolfe 2014-07-30 14:17:19 +01:00
commit fe2e3f45c7
6 changed files with 92 additions and 18 deletions

View File

@ -0,0 +1,31 @@
var CurrentUserSettings = Ember.Mixin.create({
currentUser: function () {
return this.store.find('user', 'me');
},
transitionAuthor: function () {
var self = this;
return function (user) {
if (user.get('isAuthor')) {
return self.transitionTo('settings.users.user', user);
}
return user;
};
},
transitionEditor: function () {
var self = this;
return function (user) {
if (user.get('isEditor')) {
return self.transitionTo('settings.users');
}
return user;
};
}
});
export default CurrentUserSettings;

View File

@ -1,9 +1,16 @@
var AppsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, {
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
var AppsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, CurrentUserSettings, {
beforeModel: function () {
if (!this.get('config.apps')) {
this.transitionTo('settings.general');
return this.transitionTo('settings.general');
}
return this.currentUser()
.then(this.transitionAuthor())
.then(this.transitionEditor());
},
model: function () {
return this.store.find('app');
}

View File

@ -1,6 +1,13 @@
import loadingIndicator from 'ghost/mixins/loading-indicator';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
var SettingsGeneralRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, CurrentUserSettings, {
beforeModel: function () {
return this.currentUser()
.then(this.transitionAuthor())
.then(this.transitionEditor());
},
var SettingsGeneralRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, loadingIndicator, {
model: function () {
return this.store.find('setting', { type: 'blog,theme' }).then(function (records) {
return records.get('firstObject');

View File

@ -1,24 +1,32 @@
import {mobileQuery} from 'ghost/utils/mobile';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
var SettingsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, {
var SettingsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, CurrentUserSettings, {
// redirect to general tab, unless on a mobile phone
beforeModel: function () {
if (!mobileQuery.matches) {
this.transitionTo('settings.general');
} else {
//fill the empty {{outlet}} in settings.hbs if the user
//goes to fullscreen
var self = this;
this.currentUser()
.then(this.transitionAuthor())
.then(this.transitionEditor())
.then(function () {
if (!mobileQuery.matches) {
self.transitionTo('settings.general');
} else {
//fill the empty {{outlet}} in settings.hbs if the user
//goes to fullscreen
//fillOutlet needs special treatment so that it is
//properly bound to this when called from a MQ event
this.set('fillOutlet', _.bind(function fillOutlet(mq) {
if (!mq.matches) {
this.transitionTo('settings.general');
//fillOutlet needs special treatment so that it is
//properly bound to this when called from a MQ event
self.set('fillOutlet', _.bind(function fillOutlet(mq) {
if (!mq.matches) {
self.transitionTo('settings.general');
}
}, self));
mobileQuery.addListener(self.fillOutlet);
}
}, this));
mobileQuery.addListener(this.fillOutlet);
}
});
},
deactivate: function () {
if (this.get('fillOutlet')) {
mobileQuery.removeListener(this.fillOutlet);

View File

@ -1,3 +1,10 @@
var UsersRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin);
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
var UsersRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, CurrentUserSettings, {
beforeModel: function () {
return this.currentUser()
.then(this.transitionAuthor());
}
});
export default UsersRoute;

View File

@ -9,6 +9,20 @@ var SettingsUserRoute = Ember.Route.extend({
});
},
afterModel: function (user) {
var self = this;
this.store.find('user', 'me').then(function (currentUser) {
var isOwnProfile = user.get('id') === currentUser.get('id'),
isAuthor = currentUser.get('isAuthor'),
isEditor = currentUser.get('isEditor');
if (isAuthor && !isOwnProfile) {
self.transitionTo('settings.users.user', currentUser);
} else if (isEditor && !isOwnProfile && !user.get('isAuthor')) {
self.transitionTo('settings.users');
}
});
},
deactivate: function () {
var model = this.modelFor('settings.users.user');