mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
baf9138b27
Closes #3466 - Transferring the owner role is now done via a separate endpoint and not through Ember-Data. As a result the user role data needs to be updated manually. - Updated the owner endpoint to return a response body containing the updated user objects. - Updated tests.
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
var TransferOwnerController = Ember.Controller.extend({
|
|
actions: {
|
|
confirmAccept: function () {
|
|
var user = this.get('model'),
|
|
url = this.get('ghostPaths.url').api('users', 'owner'),
|
|
self = this;
|
|
|
|
self.get('popover').closePopovers();
|
|
|
|
ic.ajax.request(url, {
|
|
type: 'PUT',
|
|
data: {
|
|
owner: [{
|
|
'id': user.get('id')
|
|
}]
|
|
}
|
|
}).then(function (response) {
|
|
// manually update the roles for the users that just changed roles
|
|
// because store.pushPayload is not working with embedded relations
|
|
if (response && Ember.isArray(response.users)) {
|
|
response.users.forEach(function (userJSON) {
|
|
var user = self.store.getById('user', userJSON.id),
|
|
role = self.store.getById('role', userJSON.roles[0].id);
|
|
|
|
user.set('role', role);
|
|
});
|
|
}
|
|
|
|
self.notifications.closePassive();
|
|
self.notifications.showSuccess('Ownership successfully transferred to ' + user.get('name'));
|
|
}).catch(function (error) {
|
|
self.notifications.closePassive();
|
|
self.notifications.showAPIError(error);
|
|
});
|
|
},
|
|
|
|
confirmReject: function () {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
confirm: {
|
|
accept: {
|
|
text: 'YEP - I\'M SURE',
|
|
buttonClass: 'button-delete'
|
|
},
|
|
reject: {
|
|
text: 'CANCEL',
|
|
buttonClass: 'button'
|
|
}
|
|
}
|
|
});
|
|
|
|
export default TransferOwnerController; |