2014-10-28 17:29:42 +03:00
|
|
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
2015-04-14 18:04:16 +03:00
|
|
|
import CurrentUserSettings from 'ghost/mixins/current-user-settings';
|
2014-09-23 17:04:49 +04:00
|
|
|
import styleBody from 'ghost/mixins/style-body';
|
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
|
2015-05-25 21:17:10 +03:00
|
|
|
titleToken: 'Team - User',
|
2014-11-25 23:56:08 +03:00
|
|
|
|
2015-06-18 13:59:08 +03:00
|
|
|
classNames: ['team-view-user'],
|
2014-09-23 17:04:49 +04:00
|
|
|
|
2014-07-17 06:16:31 +04:00
|
|
|
model: function (params) {
|
2014-07-31 01:42:46 +04:00
|
|
|
var self = this;
|
2014-07-17 06:16:31 +04:00
|
|
|
// 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
|
2015-09-03 14:06:50 +03:00
|
|
|
return this.store.findAll('user', {reload: true}).then(function (result) {
|
2014-07-31 01:42:46 +04:00
|
|
|
var user = result.findBy('slug', params.slug);
|
|
|
|
|
|
|
|
if (!user) {
|
2015-06-18 13:59:08 +03:00
|
|
|
return self.transitionTo('error404', 'team/' + params.slug);
|
2014-07-31 01:42:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return user;
|
2014-07-01 19:58:26 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-25 11:52:17 +04:00
|
|
|
afterModel: function (user) {
|
|
|
|
var self = this;
|
2015-04-14 18:04:16 +03:00
|
|
|
return this.get('session.user').then(function (currentUser) {
|
2014-07-25 11:52:17 +04:00
|
|
|
var isOwnProfile = user.get('id') === currentUser.get('id'),
|
|
|
|
isAuthor = currentUser.get('isAuthor'),
|
|
|
|
isEditor = currentUser.get('isEditor');
|
|
|
|
if (isAuthor && !isOwnProfile) {
|
2015-06-18 13:59:08 +03:00
|
|
|
self.transitionTo('team.user', currentUser);
|
2014-07-25 11:52:17 +04:00
|
|
|
} else if (isEditor && !isOwnProfile && !user.get('isAuthor')) {
|
2015-06-18 13:59:08 +03:00
|
|
|
self.transitionTo('team');
|
2014-07-25 11:52:17 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-07-01 19:58:26 +04:00
|
|
|
deactivate: function () {
|
2015-06-18 13:59:08 +03:00
|
|
|
var model = this.modelFor('team.user');
|
2014-07-01 19:58:26 +04:00
|
|
|
|
|
|
|
// we want to revert any unsaved changes on exit
|
2015-09-03 14:06:50 +03:00
|
|
|
if (model && model.get('hasDirtyAttributes')) {
|
|
|
|
model.rollbackAttributes();
|
2014-07-17 06:16:31 +04:00
|
|
|
}
|
|
|
|
|
2015-09-03 00:10:51 +03:00
|
|
|
model.get('errors').clear();
|
|
|
|
|
2014-07-17 06:16:31 +04:00
|
|
|
this._super();
|
2014-11-12 23:35:41 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2015-09-03 00:10:51 +03:00
|
|
|
didTransition: function () {
|
|
|
|
this.modelFor('team.user').get('errors').clear();
|
|
|
|
},
|
|
|
|
|
2014-11-12 23:35:41 +03:00
|
|
|
save: function () {
|
|
|
|
this.get('controller').send('save');
|
|
|
|
}
|
2014-07-01 19:58:26 +04:00
|
|
|
}
|
|
|
|
});
|