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

[permissions] forbid deletion of last admin user #10504

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ijreilly
Copy link
Collaborator

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 in permissions.exception.ts for proper error handling
  • Implemented validateUserWorkspaceIsNotUniqueAdminOrThrow method in user-role.service.ts to check if a user is the last admin
  • Enhanced deleteUser method in user.service.ts to prevent deletion of the last admin with clear error messaging
  • Added UserWorkspaceModule to UserModule 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

Comment on lines 140 to 143
public async validateUserWorkspaceIsNotUniqueAdminOrThrow({
userWorkspaceId,
workspaceId,
}) {
Copy link
Contributor

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 }

Suggested change
public async validateUserWorkspaceIsNotUniqueAdminOrThrow({
userWorkspaceId,
workspaceId,
}) {
public async validateUserWorkspaceIsNotUniqueAdminOrThrow({
userWorkspaceId,
workspaceId,
}: { userWorkspaceId: string; workspaceId: string }) {

Comment on lines 222 to 225
private async validateMoreThanOneWorkspaceMemberHasAdminRoleOrThrow({
adminRoleId,
workspaceId,
}) {
Copy link
Contributor

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 }

Suggested change
private async validateMoreThanOneWorkspaceMemberHasAdminRoleOrThrow({
adminRoleId,
workspaceId,
}) {
private async validateMoreThanOneWorkspaceMemberHasAdminRoleOrThrow({
adminRoleId,
workspaceId,
}: { adminRoleId: string; workspaceId: string }) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant