-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[permissions] forbid deletion of last admin user #10504
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR implements protection against deleting the last admin user in a workspace, ensuring workspace continuity.
- Added new
NO_ROLE_FOUND_FOR_USER_WORKSPACE
error code inpermissions.exception.ts
for proper error handling - Implemented
validateUserWorkspaceIsNotUniqueAdminOrThrow
method inuser-role.service.ts
to check if a user is the last admin - Enhanced
deleteUser
method inuser.service.ts
to prevent deletion of the last admin with clear error messaging - Added
UserWorkspaceModule
toUserModule
imports to access necessary services for admin validation - Created integration test in
user.integration-spec.ts
to verify the functionality works correctly
6 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile
public async validateUserWorkspaceIsNotUniqueAdminOrThrow({ | ||
userWorkspaceId, | ||
workspaceId, | ||
}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Missing type definition for method parameters. Consider adding explicit types: { userWorkspaceId: string, workspaceId: string }
public async validateUserWorkspaceIsNotUniqueAdminOrThrow({ | |
userWorkspaceId, | |
workspaceId, | |
}) { | |
public async validateUserWorkspaceIsNotUniqueAdminOrThrow({ | |
userWorkspaceId, | |
workspaceId, | |
}: { userWorkspaceId: string; workspaceId: string }) { |
private async validateMoreThanOneWorkspaceMemberHasAdminRoleOrThrow({ | ||
adminRoleId, | ||
workspaceId, | ||
}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Missing type definition for method parameters. Consider adding explicit types: { adminRoleId: string, workspaceId: string }
private async validateMoreThanOneWorkspaceMemberHasAdminRoleOrThrow({ | |
adminRoleId, | |
workspaceId, | |
}) { | |
private async validateMoreThanOneWorkspaceMemberHasAdminRoleOrThrow({ | |
adminRoleId, | |
workspaceId, | |
}: { adminRoleId: string; workspaceId: string }) { |
A user should not be able to delete their account if they are the last admin of a workspace.
It means that if a user wants to sign out of twenty, they should delete their workspace, not their account