Ghost/core/client/app/routes/team/user.js
Kevin Ansfield 571b9e783a Always call _super when using Ember hooks
no issue
- review use of Ember core hooks and add a call to `this._super` if missing
- fix a few occurrences of using the wrong component lifecycle hooks that could result in multiple/duplicate event handlers being attached

`_super` should always be called when overriding Ember's base hooks so that core functionality or app functionality added through extensions, mixins or addons is not lost. This is important as it guards against issues arising from later refactorings or core changes.

As example of lost functionality, there were a number of routes that extended from `AuthenticatedRoute` but then overrode the `beforeModel` hook without calling `_super` which meant that the route was no longer treated as authenticated.
2015-11-30 12:45:37 +00:00

58 lines
1.6 KiB
JavaScript

/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
import AuthenticatedRoute from 'ghost/routes/authenticated';
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
import styleBody from 'ghost/mixins/style-body';
export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
titleToken: 'Team - User',
classNames: ['team-view-user'],
model(params) {
return this.store.queryRecord('user', {slug: params.user_slug});
},
serialize(model) {
return {user_slug: model.get('slug')};
},
afterModel(user) {
this._super(...arguments);
return this.get('session.user').then((currentUser) => {
let isOwnProfile = user.get('id') === currentUser.get('id');
let isAuthor = currentUser.get('isAuthor');
let isEditor = currentUser.get('isEditor');
if (isAuthor && !isOwnProfile) {
this.transitionTo('team.user', currentUser);
} else if (isEditor && !isOwnProfile && !user.get('isAuthor')) {
this.transitionTo('team');
}
});
},
deactivate() {
let model = this.modelFor('team.user');
// we want to revert any unsaved changes on exit
if (model && model.get('hasDirtyAttributes')) {
model.rollbackAttributes();
}
model.get('errors').clear();
this._super(...arguments);
},
actions: {
didTransition() {
this.modelFor('team.user').get('errors').clear();
},
save() {
this.get('controller').send('save');
}
}
});