Ghost/ghost/admin/routes/settings/index.js
Alan Richards 4d074c3e55 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`
2014-07-30 00:57:16 -07:00

38 lines
1.4 KiB
JavaScript

import {mobileQuery} from 'ghost/utils/mobile';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
var SettingsIndexRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, CurrentUserSettings, {
// redirect to general tab, unless on a mobile phone
beforeModel: function () {
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
self.set('fillOutlet', _.bind(function fillOutlet(mq) {
if (!mq.matches) {
self.transitionTo('settings.general');
}
}, self));
mobileQuery.addListener(self.fillOutlet);
}
});
},
deactivate: function () {
if (this.get('fillOutlet')) {
mobileQuery.removeListener(this.fillOutlet);
}
}
});
export default SettingsIndexRoute;