-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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: Resolve "Can't delete an account" issue (#9232) #9238
fix: Resolve "Can't delete an account" issue (#9232) #9238
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 fixes a context binding issue in the user deletion process where this
was being lost during Array.map() execution, causing dataSourceService to be undefined.
- Fixed
deleteUserFromWorkspace
context inpackages/twenty-server/src/engine/core-modules/user/services/user.service.ts
by bindingthis
to preserve service access - Added error handling for workspace member deletion when user is the last member
- Ensures proper cleanup of workspace data when deleting the last user
- Maintains workspace event emission for member deletion tracking
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
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.
Thanks !
if (workspaceMembers.length === 1) { | ||
await this.workspaceService.deleteWorkspace(workspaceId); | ||
} | ||
|
||
const objectMetadata = await this.objectMetadataRepository.findOneOrFail({ | ||
where: { | ||
nameSingular: 'workspaceMember', |
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.
Just realised this should be filtered by workspaceId to be safe. Although it's only used for the emit event below. I'll update that in a future PR.
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.
LGTM!
Summary
This pull request addresses the issue described in #9232, where attempting to delete a user account results in a
TypeError: Cannot read properties of undefined (reading 'dataSourceService')
.Changes Made
this
context issue in thedeleteUserFromWorkspace
method by ensuring it is correctly bound.deleteUser
method to use a bound function when callingdeleteUserFromWorkspace
.Linked Issue
This pull request fixes #9232.
Additional Notes