Skip to content

Commit

Permalink
fix(core): Do not allow admins to delete the instance owner (#9489)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 22, 2024
1 parent 88b9a40 commit fc83005
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/cli/src/controllers/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export class UsersController {
);
}

if (userToDelete.role === 'global:owner') {
throw new ForbiddenError('Instance owner cannot be deleted.');
}

const personalProjectToDelete = await this.projectRepository.getPersonalProjectForUserOrFail(
userToDelete.id,
);
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/test/integration/users.api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,15 @@ describe('DELETE /users/:id', () => {
expect(user).toBeDefined();
});

test('should fail to delete the instance owner', async () => {
const admin = await createAdmin();
const adminAgent = testServer.authAgentFor(admin);
await adminAgent.delete(`/users/${owner.id}`).expect(403);

const user = await getUserById(owner.id);
expect(user).toBeDefined();
});

test('should fail to delete a user that does not exist', async () => {
await ownerAgent.delete(`/users/${uuid()}`).query({ transferId: '' }).expect(404);
});
Expand Down

0 comments on commit fc83005

Please sign in to comment.