mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Fixed error when editing user with empty roles data
- we send the roles data array in when we're changing the role of the user - if we send an empty array, we don't want to edit the user's role - the code _thought_ that's what it was doing, but we only check the falsiness of the array, which is truthy for `[]` - it also needs to check the length of the array - this commit includes a test which would fail with a 500 error without the fix
This commit is contained in:
parent
c4470ff732
commit
f2c074ac59
2 changed files with 12 additions and 1 deletions
|
@ -510,7 +510,7 @@ User = ghostBookshelf.Model.extend({
|
|||
return ghostBookshelf.Model.edit.call(self, data, options).then((user) => {
|
||||
let roleId;
|
||||
|
||||
if (!data.roles) {
|
||||
if (!data.roles || !data.roles.length) {
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
|
@ -185,6 +185,17 @@ describe('User API', function () {
|
|||
}
|
||||
});
|
||||
|
||||
it('Can edit user with empty roles data', async function () {
|
||||
await request.put(localUtils.API.getApiQuery('users/me'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
users: [{
|
||||
roles: []
|
||||
}]
|
||||
})
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it('Can destroy an active user', async function () {
|
||||
const userId = testUtils.getExistingData().users[1].id;
|
||||
|
||||
|
|
Loading…
Reference in a new issue