mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
75abe76346
no issue - ran the `ember-native-class-codemod` codemod to convert just the route classes to native class syntax and performed some minor manual cleanup - modern Ember uses native classes rather than EmberObject-based objects, this brings us closer to normalizing our code style across the codebase - skipped the Application route as that requires deeper testing with a replacement for the `ShortcutsRoute` mixin
74 lines
2.2 KiB
JavaScript
74 lines
2.2 KiB
JavaScript
import {action} from '@ember/object';
|
|
/* eslint-disable camelcase */
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
|
|
export default class UserRoute extends AuthenticatedRoute {
|
|
model(params) {
|
|
return this.store.queryRecord('user', {slug: params.user_slug, include: 'count.posts'});
|
|
}
|
|
|
|
afterModel(user) {
|
|
super.afterModel(...arguments);
|
|
|
|
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('settings.staff.user', currentUser);
|
|
} else if (isEditor && !isOwnProfile && !user.get('isAuthorOrContributor')) {
|
|
this.transitionTo('settings.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);
|
|
});
|
|
}
|
|
}
|
|
|
|
serialize(model) {
|
|
return {user_slug: model.get('slug')};
|
|
}
|
|
|
|
@action
|
|
didTransition() {
|
|
this.modelFor('settings.staff.user').get('errors').clear();
|
|
}
|
|
|
|
@action
|
|
save() {
|
|
this.controller.save.perform();
|
|
}
|
|
|
|
@action
|
|
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'
|
|
};
|
|
}
|
|
}
|