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: Resolve "Can't delete an account" issue (#9232) #9238

Merged

Conversation

melvinjariwala
Copy link
Contributor

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

  • Fixed the this context issue in the deleteUserFromWorkspace method by ensuring it is correctly bound.
  • Updated the deleteUser method to use a bound function when calling deleteUserFromWorkspace.

Linked Issue

This pull request fixes #9232.

Additional Notes

  • Please review the changes carefully to ensure no unintended side effects in the user or workspace deletion process.
  • Suggestions for further improvement are welcome.

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 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 in packages/twenty-server/src/engine/core-modules/user/services/user.service.ts by binding this 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

@lucasbordeau lucasbordeau self-assigned this Dec 30, 2024
Copy link
Member

@magrinj magrinj left a 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',
Copy link
Member

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.

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Weiko Weiko merged commit 2349973 into twentyhq:main Jan 2, 2025
20 checks passed
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.

Can't delete an account
4 participants