From 038632e9a6dd8e5ae1246cac6fec2c4a91d663be Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Thu, 31 Jul 2014 13:41:10 +0000 Subject: [PATCH] Update user roles in store after owner transfer 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. --- ghost/admin/controllers/modals/transfer-owner.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ghost/admin/controllers/modals/transfer-owner.js b/ghost/admin/controllers/modals/transfer-owner.js index 5afa0a36d3..a861283dc3 100644 --- a/ghost/admin/controllers/modals/transfer-owner.js +++ b/ghost/admin/controllers/modals/transfer-owner.js @@ -14,7 +14,18 @@ var TransferOwnerController = Ember.Controller.extend({ 'id': user.get('id') }] } - }).then(function () { + }).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) {