From 739b57e05bbcde5af1a72bd97afd28d7ec8b13e9 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 22 Jul 2014 05:27:50 +0000 Subject: [PATCH] Update Users API to handle role objects or ids Closes #3357 - API method User#edit now handles User objects that have either an array of Role ids or objects. - Fixed error handler notification on upload modal controller. --- core/client/controllers/modals/upload.js | 4 +++- core/server/models/user.js | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/client/controllers/modals/upload.js b/core/client/controllers/modals/upload.js index 1664b93a56..64c3f9e0ee 100644 --- a/core/client/controllers/modals/upload.js +++ b/core/client/controllers/modals/upload.js @@ -8,7 +8,9 @@ var UploadController = Ember.Controller.extend({ this.get('model').save().then(function (model) { self.notifications.showSuccess('Saved'); return model; - }).catch(this.notifications.showErrors); + }).catch(function (err) { + self.notifications.showErrors(err); + }); }, confirmReject: function () { diff --git a/core/server/models/user.js b/core/server/models/user.js index 7986a0f7ac..28530c1982 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -316,9 +316,8 @@ User = ghostBookshelf.Model.extend({ if (data.roles.length > 1) { return when.reject(new errors.ValidationError('Only one role per user is supported at the moment.')); } - - return Role.findOne({id: data.roles[0]}).then(function (role) { - if (role.get('name') === 'Owner') { + return Role.findOne({id: data.roles[0].id || data.roles[0]}).then(function (role) { + if (role && role.get('name') === 'Owner') { // Get admin and owner role return Role.findOne({name: 'Administrator'}).then(function (result) { adminRole = result; @@ -340,7 +339,7 @@ User = ghostBookshelf.Model.extend({ }); } else { // assign all other roles - return user.roles().updatePivot({role_id: data.roles[0]}); + return user.roles().updatePivot({role_id: data.roles[0].id || data.roles[0]}); } }).then(function () { return self.findOne(user, options);