diff --git a/core/server/models/user.js b/core/server/models/user.js index c9be0e09e3..ff4337909c 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -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; } diff --git a/test/e2e-api/admin/users.test.js b/test/e2e-api/admin/users.test.js index d6332647d9..582e715074 100644 --- a/test/e2e-api/admin/users.test.js +++ b/test/e2e-api/admin/users.test.js @@ -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;