mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
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.
This commit is contained in:
parent
27c1dbd409
commit
739b57e05b
2 changed files with 6 additions and 5 deletions
|
@ -8,7 +8,9 @@ var UploadController = Ember.Controller.extend({
|
||||||
this.get('model').save().then(function (model) {
|
this.get('model').save().then(function (model) {
|
||||||
self.notifications.showSuccess('Saved');
|
self.notifications.showSuccess('Saved');
|
||||||
return model;
|
return model;
|
||||||
}).catch(this.notifications.showErrors);
|
}).catch(function (err) {
|
||||||
|
self.notifications.showErrors(err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
confirmReject: function () {
|
confirmReject: function () {
|
||||||
|
|
|
@ -316,9 +316,8 @@ User = ghostBookshelf.Model.extend({
|
||||||
if (data.roles.length > 1) {
|
if (data.roles.length > 1) {
|
||||||
return when.reject(new errors.ValidationError('Only one role per user is supported at the moment.'));
|
return when.reject(new errors.ValidationError('Only one role per user is supported at the moment.'));
|
||||||
}
|
}
|
||||||
|
return Role.findOne({id: data.roles[0].id || data.roles[0]}).then(function (role) {
|
||||||
return Role.findOne({id: data.roles[0]}).then(function (role) {
|
if (role && role.get('name') === 'Owner') {
|
||||||
if (role.get('name') === 'Owner') {
|
|
||||||
// Get admin and owner role
|
// Get admin and owner role
|
||||||
return Role.findOne({name: 'Administrator'}).then(function (result) {
|
return Role.findOne({name: 'Administrator'}).then(function (result) {
|
||||||
adminRole = result;
|
adminRole = result;
|
||||||
|
@ -340,7 +339,7 @@ User = ghostBookshelf.Model.extend({
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// assign all other roles
|
// 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 () {
|
}).then(function () {
|
||||||
return self.findOne(user, options);
|
return self.findOne(user, options);
|
||||||
|
|
Loading…
Add table
Reference in a new issue