-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Fix user deletion flows #15614
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
Merged
Merged
Fix user deletion flows #15614
Changes from 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
de2a2e7
unrelated but forgot to commit before
ijreilly 6d664a6
replace cascade deletion
ijreilly e96cca2
commands to clean
ijreilly 5be6594
fixed commands
ijreilly 3380417
Merge branch 'main' of github.com:twentyhq/twenty into fix--role-dele…
ijreilly 7c1c9ca
some updates
ijreilly 540d763
more updates
ijreilly fc4cb60
cron to clean deleteed users
ijreilly e660481
fixes
ijreilly e0ba131
fixes
ijreilly 79fb589
fix comment
ijreilly 6796d2f
revert user hard deletion
ijreilly 1428f18
Merge branch 'main' of github.com:twentyhq/twenty into fix--role-dele…
ijreilly b44844b
fix
ijreilly 3f5bc25
generate graphql
ijreilly 8943894
fix
ijreilly 66a4d5a
wip
ijreilly c81a1b5
improve
ijreilly 279ada3
forbid access to deleteOneWorkspaceMember
ijreilly 5984f1e
fix test
ijreilly 5575577
tests
ijreilly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 75 additions & 5 deletions
80
packages/twenty-front/src/modules/settings/profile/components/DeleteAccount.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,122 @@ | ||
| import { useRecoilValue } from 'recoil'; | ||
|
|
||
| import { useAuth } from '@/auth/hooks/useAuth'; | ||
| import { availableWorkspacesState } from '@/auth/states/availableWorkspacesState'; | ||
| import { currentUserState } from '@/auth/states/currentUserState'; | ||
| import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState'; | ||
| import { countAvailableWorkspaces } from '@/auth/utils/availableWorkspacesUtils'; | ||
| import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; | ||
| import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal'; | ||
| import { useModal } from '@/ui/layout/modal/hooks/useModal'; | ||
| import styled from '@emotion/styled'; | ||
| import { useLingui } from '@lingui/react/macro'; | ||
| import { isDefined } from 'twenty-shared/utils'; | ||
| import { H2Title } from 'twenty-ui/display'; | ||
| import { Button } from 'twenty-ui/input'; | ||
| import { useDeleteUserAccountMutation } from '~/generated-metadata/graphql'; | ||
| import { | ||
| useDeleteUserAccountMutation, | ||
| useDeleteUserWorkspaceMutation, | ||
| } from '~/generated-metadata/graphql'; | ||
|
|
||
| const DELETE_ACCOUNT_MODAL_ID = 'delete-account-modal'; | ||
| const LEAVE_WORKSPACE_MODAL_ID = 'leave-workspace-modal'; | ||
|
|
||
| const StyledDiv = styled.div` | ||
| margin-bottom: ${({ theme }) => theme.spacing(2)}; | ||
| `; | ||
|
|
||
| export const DeleteAccount = () => { | ||
| const { t } = useLingui(); | ||
| const { openModal } = useModal(); | ||
| const { enqueueErrorSnackBar } = useSnackBar(); | ||
|
|
||
| const [deleteUserAccount] = useDeleteUserAccountMutation(); | ||
| const [deleteUserFromWorkspace] = useDeleteUserWorkspaceMutation(); | ||
| const currentUser = useRecoilValue(currentUserState); | ||
| const userEmail = currentUser?.email; | ||
| const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState); | ||
| const currentWorkspaceMemberId = currentWorkspaceMember?.id; | ||
| const { signOut } = useAuth(); | ||
| const availableWorkspaces = useRecoilValue(availableWorkspacesState); | ||
| const availableWorkspacesCount = | ||
| countAvailableWorkspaces(availableWorkspaces); | ||
|
|
||
| const userHasMultipleWorkspaces = availableWorkspacesCount > 1; | ||
|
|
||
| const deleteAccount = async () => { | ||
| await deleteUserAccount(); | ||
| await signOut(); | ||
| }; | ||
|
|
||
| const leaveWorkspace = async () => { | ||
| if (!isDefined(currentWorkspaceMemberId)) { | ||
| enqueueErrorSnackBar({ | ||
| message: t`Current workspace member not found.`, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| await deleteUserFromWorkspace?.({ | ||
| variables: { | ||
| workspaceMemberIdToDelete: currentWorkspaceMemberId, | ||
| }, | ||
| }); | ||
| await signOut(); | ||
| }; | ||
|
Comment on lines
+51
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: missing required argument Check backend mutation signature: deleteUserFromWorkspace(
@Args('workspaceMemberIdToDelete') workspaceMemberIdToDelete: string,
...
)Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/twenty-front/src/modules/settings/profile/components/DeleteAccount.tsx
Line: 45:48
Comment:
**logic:** missing required argument `workspaceMemberIdToDelete` for mutation - backend expects this parameter but frontend doesn't provide it
Check backend mutation signature:
```typescript
deleteUserFromWorkspace(
@Args('workspaceMemberIdToDelete') workspaceMemberIdToDelete: string,
...
)
```
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| return ( | ||
| <> | ||
| <H2Title | ||
| title={t`Danger zone`} | ||
| description={t`Delete account and all the associated data`} | ||
| description={ | ||
| userHasMultipleWorkspaces | ||
| ? t`Delete account and all the associated data or leave workspace` | ||
| : t`Delete account and all the associated data` | ||
| } | ||
| /> | ||
| {userHasMultipleWorkspaces && ( | ||
| <StyledDiv> | ||
| <Button | ||
| accent="danger" | ||
| onClick={() => openModal(LEAVE_WORKSPACE_MODAL_ID)} | ||
| variant="secondary" | ||
| title={t`Leave workspace`} | ||
| /> | ||
|
|
||
| <ConfirmationModal | ||
| confirmationValue={userEmail} | ||
| confirmationPlaceholder={userEmail ?? ''} | ||
| modalId={LEAVE_WORKSPACE_MODAL_ID} | ||
| title={t`Leave workspace`} | ||
| subtitle={ | ||
| <> | ||
| {t`This action cannot be undone. This will permanently remove your membership from this workspace.`} | ||
| <br /> | ||
| {t`Please type in your email to confirm.`} | ||
| </> | ||
| } | ||
| onConfirmClick={leaveWorkspace} | ||
| confirmButtonText={t`Leave workspace`} | ||
| /> | ||
| </StyledDiv> | ||
| )} | ||
| <Button | ||
| accent="danger" | ||
| onClick={() => openModal(DELETE_ACCOUNT_MODAL_ID)} | ||
| variant="secondary" | ||
| title={t`Delete account`} | ||
| /> | ||
|
|
||
| <ConfirmationModal | ||
| confirmationValue={userEmail} | ||
| confirmationPlaceholder={userEmail ?? ''} | ||
| modalId={DELETE_ACCOUNT_MODAL_ID} | ||
| title={t`Account Deletion`} | ||
| subtitle={ | ||
| <> | ||
| This action cannot be undone. This will permanently delete your | ||
| entire account. <br /> Please type in your email to confirm. | ||
| {t`This action cannot be undone. This will permanently delete your | ||
| entire account.`} | ||
| <br /> | ||
| {t`Please type in your email to confirm.`} | ||
| </> | ||
| } | ||
| onConfirmClick={deleteAccount} | ||
|
|
||
11 changes: 11 additions & 0 deletions
11
packages/twenty-front/src/modules/users/graphql/mutations/deleteUserWorkspace.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { gql } from '@apollo/client'; | ||
|
|
||
| export const DELETE_USER_FROM_WORKSPACE = gql` | ||
| mutation DeleteUserWorkspace($workspaceMemberIdToDelete: String!) { | ||
| deleteUserFromWorkspace( | ||
| workspaceMemberIdToDelete: $workspaceMemberIdToDelete | ||
| ) { | ||
| id | ||
| } | ||
| } | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm not sure about exposing the refetch for useFindMany for this new use case only 🤔 Could we use optimistic update / apollo cache mutation instead?
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.
why not? by fear it would be use in the wrong context?
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.
@lucasbordeau wdyt?
Uh oh!
There was an error while loading. Please reload this page.
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.
There's dedicated tooling for fetchMore and doing a refetch like that has not been QAed, so I would not expose this method.