mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Settings screens redirect for certain roles
Closes #3291 - Adds redirects based on roles as defined in the case - Adds new mixin `CurrentUserSettings` - For authors, all settings pages redirect to `users/self` - For editors, all settings pages other than specific users redirect to `users`. Any user that is not self or an author redirects to `users`
This commit is contained in:
parent
05afe8afb2
commit
4d074c3e55
6 changed files with 92 additions and 18 deletions
31
ghost/admin/mixins/current-user-settings.js
Normal file
31
ghost/admin/mixins/current-user-settings.js
Normal 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;
|
|
@ -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 () {
|
beforeModel: function () {
|
||||||
if (!this.get('config.apps')) {
|
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 () {
|
model: function () {
|
||||||
return this.store.find('app');
|
return this.store.find('app');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
import loadingIndicator from 'ghost/mixins/loading-indicator';
|
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 () {
|
model: function () {
|
||||||
return this.store.find('setting', { type: 'blog,theme' }).then(function (records) {
|
return this.store.find('setting', { type: 'blog,theme' }).then(function (records) {
|
||||||
return records.get('firstObject');
|
return records.get('firstObject');
|
||||||
|
|
|
@ -1,24 +1,32 @@
|
||||||
import {mobileQuery} from 'ghost/utils/mobile';
|
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
|
// redirect to general tab, unless on a mobile phone
|
||||||
beforeModel: function () {
|
beforeModel: function () {
|
||||||
|
var self = this;
|
||||||
|
this.currentUser()
|
||||||
|
.then(this.transitionAuthor())
|
||||||
|
.then(this.transitionEditor())
|
||||||
|
.then(function () {
|
||||||
if (!mobileQuery.matches) {
|
if (!mobileQuery.matches) {
|
||||||
this.transitionTo('settings.general');
|
self.transitionTo('settings.general');
|
||||||
} else {
|
} else {
|
||||||
//fill the empty {{outlet}} in settings.hbs if the user
|
//fill the empty {{outlet}} in settings.hbs if the user
|
||||||
//goes to fullscreen
|
//goes to fullscreen
|
||||||
|
|
||||||
//fillOutlet needs special treatment so that it is
|
//fillOutlet needs special treatment so that it is
|
||||||
//properly bound to this when called from a MQ event
|
//properly bound to this when called from a MQ event
|
||||||
this.set('fillOutlet', _.bind(function fillOutlet(mq) {
|
self.set('fillOutlet', _.bind(function fillOutlet(mq) {
|
||||||
if (!mq.matches) {
|
if (!mq.matches) {
|
||||||
this.transitionTo('settings.general');
|
self.transitionTo('settings.general');
|
||||||
}
|
}
|
||||||
}, this));
|
}, self));
|
||||||
mobileQuery.addListener(this.fillOutlet);
|
mobileQuery.addListener(self.fillOutlet);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deactivate: function () {
|
deactivate: function () {
|
||||||
if (this.get('fillOutlet')) {
|
if (this.get('fillOutlet')) {
|
||||||
mobileQuery.removeListener(this.fillOutlet);
|
mobileQuery.removeListener(this.fillOutlet);
|
||||||
|
|
|
@ -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;
|
export default UsersRoute;
|
||||||
|
|
|
@ -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 () {
|
deactivate: function () {
|
||||||
var model = this.modelFor('settings.users.user');
|
var model = this.modelFor('settings.users.user');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue