Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Do not allow admins to delete the instance owner #9489

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -164,6 +164,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 @@ -555,6 +555,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
Loading