2016-11-14 16:16:51 +03:00
|
|
|
/* eslint-disable camelcase */
|
2016-05-24 15:06:59 +03:00
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
|
|
import CurrentUserSettings from 'ghost-admin/mixins/current-user-settings';
|
2014-09-23 17:04:49 +04:00
|
|
|
|
2019-05-20 16:15:46 +03:00
|
|
|
export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
2015-10-28 14:36:45 +03:00
|
|
|
model(params) {
|
2015-11-18 13:50:48 +03:00
|
|
|
return this.store.queryRecord('user', {slug: params.user_slug, include: 'count.posts'});
|
2015-11-23 16:48:08 +03:00
|
|
|
},
|
2014-07-31 01:42:46 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
afterModel(user) {
|
2015-11-15 14:06:49 +03:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2021-07-08 16:37:31 +03:00
|
|
|
const currentUser = this.session.user;
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isOwnProfile) {
|
|
|
|
this.store.queryRecord('api-key', {id: 'me'}).then((apiKey) => {
|
|
|
|
this.controller.set('personalToken', apiKey.id + ':' + apiKey.secret);
|
|
|
|
this.controller.set('personalTokenRegenerated', false);
|
|
|
|
});
|
|
|
|
}
|
2014-07-25 11:52:17 +04:00
|
|
|
},
|
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
serialize(model) {
|
|
|
|
return {user_slug: model.get('slug')};
|
|
|
|
},
|
|
|
|
|
2014-11-12 23:35:41 +03:00
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
didTransition() {
|
2019-02-22 12:43:35 +03:00
|
|
|
this.modelFor('staff.user').get('errors').clear();
|
2015-09-03 00:10:51 +03:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
save() {
|
2016-08-11 09:58:38 +03:00
|
|
|
this.get('controller.save').perform();
|
2017-10-31 18:27:25 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
willTransition(transition) {
|
2019-03-06 16:53:54 +03:00
|
|
|
let controller = this.controller;
|
|
|
|
let user = controller.user;
|
|
|
|
let dirtyAttributes = controller.dirtyAttributes;
|
2017-10-31 18:27:25 +03:00
|
|
|
let modelIsDirty = user.get('hasDirtyAttributes');
|
|
|
|
|
2017-11-07 15:25:17 +03:00
|
|
|
// always reset the password properties on the user model when leaving
|
2017-11-07 15:34:39 +03:00
|
|
|
if (user) {
|
|
|
|
user.set('password', '');
|
|
|
|
user.set('newPassword', '');
|
|
|
|
user.set('ne2Password', '');
|
|
|
|
}
|
2017-11-07 15:25:17 +03:00
|
|
|
|
2017-10-31 18:27:25 +03:00
|
|
|
if (modelIsDirty || dirtyAttributes) {
|
|
|
|
transition.abort();
|
|
|
|
controller.send('toggleLeaveSettingsModal', transition);
|
|
|
|
return;
|
|
|
|
}
|
2014-11-12 23:35:41 +03:00
|
|
|
}
|
2019-05-20 18:16:19 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: 'Staff - User'
|
|
|
|
};
|
2014-07-01 19:58:26 +04:00
|
|
|
}
|
|
|
|
});
|