0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/client/routes/settings/users/user.js
Alan Richards dacd1060ee 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.3 KiB
JavaScript

var SettingsUserRoute = Ember.Route.extend({
model: function (params) {
// TODO: Make custom user adapter that uses /api/users/:slug endpoint
// return this.store.find('user', { slug: params.slug });
// Instead, get all the users and then find by slug
return this.store.find('user').then(function (result) {
return result.findBy('slug', params.slug);
});
},
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');
// we want to revert any unsaved changes on exit
if (model && model.get('isDirty')) {
model.rollback();
}
this._super();
}
});
export default SettingsUserRoute;