Ghost/ghost/admin/app/routes/staff/user.js
Kevin Ansfield 3653cfbfbf Refactored document-title handler
no issue
- moved `document-title` Route extension's functionality into the `ui` service
  - updates the title each time the router service emits a route changed event
  - `ui.updateDocumentTitle()` can now be called directly from components rather than the confusing `this.send('updateDocumentTitle')` bubbling behaviour
- refactored the `titleToken` implementation to use the now-formalised `RouteInfo`'s `metadata` field (https://github.com/emberjs/rfcs/blob/master/text/0398-RouteInfo-Metadata.md#appendix-a)
2019-05-20 16:16:19 +01:00

66 lines
2.0 KiB
JavaScript

/* eslint-disable camelcase */
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
import CurrentUserSettings from 'ghost-admin/mixins/current-user-settings';
export default AuthenticatedRoute.extend(CurrentUserSettings, {
model(params) {
return this.store.queryRecord('user', {slug: params.user_slug, include: 'count.posts'});
},
afterModel(user) {
this._super(...arguments);
return this.get('session.user').then((currentUser) => {
let isOwnProfile = user.get('id') === currentUser.get('id');
let isAuthorOrContributor = currentUser.get('isAuthorOrContributor');
let isEditor = currentUser.get('isEditor');
if (isAuthorOrContributor && !isOwnProfile) {
this.transitionTo('staff.user', currentUser);
} else if (isEditor && !isOwnProfile && !user.get('isAuthorOrContributor')) {
this.transitionTo('staff');
}
});
},
serialize(model) {
return {user_slug: model.get('slug')};
},
actions: {
didTransition() {
this.modelFor('staff.user').get('errors').clear();
},
save() {
this.get('controller.save').perform();
},
willTransition(transition) {
let controller = this.controller;
let user = controller.user;
let dirtyAttributes = controller.dirtyAttributes;
let modelIsDirty = user.get('hasDirtyAttributes');
// always reset the password properties on the user model when leaving
if (user) {
user.set('password', '');
user.set('newPassword', '');
user.set('ne2Password', '');
}
if (modelIsDirty || dirtyAttributes) {
transition.abort();
controller.send('toggleLeaveSettingsModal', transition);
return;
}
}
},
buildRouteInfoMetadata() {
return {
titleToken: 'Staff - User'
};
}
});