-
Notifications
You must be signed in to change notification settings - Fork 64
Add delete buttons for User and Community #3574
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
Open
isTravis
wants to merge
24
commits into
main
Choose a base branch
from
tr/delete-buttons
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
740fd80
First pass at delete flow for users and communities
isTravis 225b80d
lint
isTravis 53d7cec
Rework user Nulls
isTravis e4665f1
lint
isTravis 8137ad8
Handle DOI url updates on delete
isTravis 263cfaf
Add label on archive.pubpub.org pubs
isTravis 95e7b92
lint
isTravis b974f2b
Add ArchiveNotice and server check for archive community
isTravis 92b264f
lint
isTravis 8274a9b
Fix tests
isTravis 70204e0
Further fix tests
isTravis f592665
Fix tests 3
isTravis ef77636
lint
isTravis 6546b6a
Add debugging
isTravis e366f29
Handle collection_fkey
isTravis 9dd3400
cascade fix
isTravis 3b711a5
Reduce redundant functions
isTravis 6d9f9db
type fix
isTravis b2e9765
Merge branch 'main' into tr/delete-buttons
isTravis 6b9bbe2
Update server/community/destroyCommunity.ts
isTravis 2bfb6e5
Update server/user/account.ts
isTravis 733b8d5
Migration file tweaks
isTravis 024bba0
Add cost warning
isTravis 342de58
Merge branch 'main' into tr/delete-buttons
isTravis 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
136 changes: 136 additions & 0 deletions
136
client/containers/DashboardSettings/CommunitySettings/DeleteCommunity.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 |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| import React, { useCallback, useEffect, useState } from 'react'; | ||
|
|
||
| import { Button, Callout, Classes, Spinner, Tag } from '@blueprintjs/core'; | ||
|
|
||
| import { apiFetch } from 'client/utils/apiFetch'; | ||
| import { InputField } from 'components'; | ||
|
|
||
| type DeletionAudit = { | ||
| communityId: string; | ||
| communityTitle: string; | ||
| communitySubdomain: string; | ||
| totalPubs: number; | ||
| pubsWithDoi: number; | ||
| pubsWithReleases: number; | ||
| pubsWithoutDoi: number; | ||
| }; | ||
|
|
||
| type Props = { | ||
| communityData: { | ||
| id: string; | ||
| title: string; | ||
| }; | ||
| }; | ||
|
|
||
| const DeleteCommunity = (props: Props) => { | ||
| const { communityData } = props; | ||
| const [audit, setAudit] = useState<DeletionAudit | null>(null); | ||
| const [isLoadingAudit, setIsLoadingAudit] = useState(false); | ||
| const [confirmationTitle, setConfirmationTitle] = useState(''); | ||
| const [isDeleting, setIsDeleting] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const loadAudit = useCallback(async () => { | ||
| setIsLoadingAudit(true); | ||
| try { | ||
| const result = await apiFetch.get(`/api/communities/${communityData.id}/deletionAudit`); | ||
| setAudit(result); | ||
| } catch (err: any) { | ||
| setError(err?.message || 'Failed to load deletion audit'); | ||
| } finally { | ||
| setIsLoadingAudit(false); | ||
| } | ||
| }, [communityData.id]); | ||
|
|
||
| useEffect(() => { | ||
| loadAudit(); | ||
| }, [loadAudit]); | ||
|
|
||
| const normalizedConfirmation = confirmationTitle.toLowerCase().trim().replace(/\s+/g, ' '); | ||
| const normalizedTitle = communityData.title.toLowerCase().trim().replace(/\s+/g, ' '); | ||
| const canDelete = normalizedConfirmation === normalizedTitle; | ||
|
|
||
| const handleDelete = async () => { | ||
| setIsDeleting(true); | ||
| setError(null); | ||
| try { | ||
| await apiFetch('/api/communities/' + communityData.id, { | ||
| method: 'DELETE', | ||
| body: JSON.stringify({ confirmationTitle: communityData.title }), | ||
| }); | ||
| window.location.href = 'https://www.pubpub.org'; | ||
| } catch (err: any) { | ||
| setError(err?.message || 'Failed to delete community'); | ||
| setIsDeleting(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <h5>Delete community</h5> | ||
| <Callout intent="danger" icon="warning-sign"> | ||
| <p> | ||
| <b>Deleting a community is permanent and cannot be undone.</b> | ||
| </p> | ||
| {isLoadingAudit && <Spinner size={20} />} | ||
| {audit && ( | ||
| <div style={{ marginBottom: 15 }}> | ||
| <p> | ||
| This community contains <b>{audit.totalPubs}</b> pub | ||
| {audit.totalPubs !== 1 ? 's' : ''}: | ||
| </p> | ||
| <ul style={{ margin: '8px 0' }}> | ||
| {audit.pubsWithDoi > 0 && ( | ||
| <li> | ||
| <Tag intent="warning" minimal> | ||
| {audit.pubsWithDoi} | ||
| </Tag>{' '} | ||
| pub{audit.pubsWithDoi !== 1 ? 's' : ''} with DOIs — these will | ||
| be <b>moved to archive.pubpub.org</b> to preserve the scholarly | ||
| record. Their discussions, releases, drafts, and attributions | ||
| will be preserved. | ||
| </li> | ||
| )} | ||
| {audit.pubsWithoutDoi > 0 && ( | ||
| <li> | ||
| <Tag intent="danger" minimal> | ||
| {audit.pubsWithoutDoi} | ||
| </Tag>{' '} | ||
| pub{audit.pubsWithoutDoi !== 1 ? 's' : ''} without DOIs — these | ||
| will be <b>permanently deleted</b> along with all their | ||
| discussions, releases, and metadata. | ||
| </li> | ||
| )} | ||
| </ul> | ||
| <p> | ||
| All pages, collections, members, and community settings will be | ||
| permanently deleted. | ||
| </p> | ||
| </div> | ||
| )} | ||
| <p> | ||
| Please type <b>{communityData.title}</b> below to confirm. | ||
| </p> | ||
| <InputField | ||
| label={<b>Confirm community title</b>} | ||
| value={confirmationTitle} | ||
| onChange={(evt) => setConfirmationTitle(evt.target.value)} | ||
| /> | ||
| {error && ( | ||
| <Callout intent="danger" style={{ marginBottom: 10 }}> | ||
| {error} | ||
| </Callout> | ||
| )} | ||
| <Button | ||
| intent="danger" | ||
| text="Delete community" | ||
| loading={isDeleting} | ||
| onClick={handleDelete} | ||
| disabled={!canDelete} | ||
| /> | ||
| </Callout> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DeleteCommunity; | ||
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,142 @@ | ||
| import React, { useCallback, useEffect, useState } from 'react'; | ||
|
|
||
| import { Button, Callout, Card, Spinner, Tag } from '@blueprintjs/core'; | ||
| import SHA3 from 'crypto-js/sha3'; | ||
|
|
||
| import { apiFetch } from 'client/utils/apiFetch'; | ||
| import { InputField } from 'components'; | ||
|
|
||
| type DeletionAudit = { | ||
| userId: string; | ||
| fullName: string; | ||
| email: string; | ||
| pubAttributionCount: number; | ||
| collectionAttributionCount: number; | ||
| discussionCount: number; | ||
| threadCommentCount: number; | ||
| membershipCount: number; | ||
| releaseCount: number; | ||
| }; | ||
|
|
||
| const DeleteAccount = () => { | ||
| const [audit, setAudit] = useState<DeletionAudit | null>(null); | ||
| const [isLoadingAudit, setIsLoadingAudit] = useState(false); | ||
| const [password, setPassword] = useState(''); | ||
| const [isDeleting, setIsDeleting] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const loadAudit = useCallback(async () => { | ||
| setIsLoadingAudit(true); | ||
| try { | ||
| const result = await apiFetch.get('/api/account/deletionAudit'); | ||
| setAudit(result); | ||
| } catch (err: any) { | ||
| setError(err?.message || 'Failed to load account deletion audit'); | ||
| } finally { | ||
| setIsLoadingAudit(false); | ||
| } | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| loadAudit(); | ||
| }, [loadAudit]); | ||
|
|
||
| const handleDelete = async () => { | ||
| if (!password) return; | ||
| setIsDeleting(true); | ||
| setError(null); | ||
| try { | ||
| const hashedPassword = SHA3(password).toString(); | ||
| await apiFetch('/api/account', { | ||
| method: 'DELETE', | ||
| body: JSON.stringify({ password: hashedPassword }), | ||
| }); | ||
| window.location.href = 'https://www.pubpub.org'; | ||
| } catch (err: any) { | ||
| setError(err?.message || 'Failed to delete account'); | ||
| setIsDeleting(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Card> | ||
| <h5>Delete account</h5> | ||
| <Callout intent="danger" icon="warning-sign"> | ||
| <p> | ||
| <b>Deleting your account is permanent and cannot be undone.</b> | ||
| </p> | ||
| {isLoadingAudit && <Spinner size={20} />} | ||
| {audit && ( | ||
| <div style={{ marginBottom: 15 }}> | ||
| <p>Here is what will happen when you delete your account:</p> | ||
| <ul style={{ margin: '8px 0' }}> | ||
| {audit.pubAttributionCount > 0 && ( | ||
| <li> | ||
| <Tag minimal>{audit.pubAttributionCount}</Tag> pub attribution | ||
| {audit.pubAttributionCount !== 1 ? 's' : ''} will be{' '} | ||
| <b>preserved with your name</b> but unlinked from your account. | ||
| </li> | ||
| )} | ||
| {audit.collectionAttributionCount > 0 && ( | ||
| <li> | ||
| <Tag minimal>{audit.collectionAttributionCount}</Tag> collection | ||
| attribution | ||
| {audit.collectionAttributionCount !== 1 ? 's' : ''} will be{' '} | ||
| <b>preserved with your name</b> but unlinked from your account. | ||
| </li> | ||
| )} | ||
| {audit.discussionCount > 0 && ( | ||
| <li> | ||
| <Tag minimal>{audit.discussionCount}</Tag> discussion | ||
| {audit.discussionCount !== 1 ? 's' : ''} you started will be{' '} | ||
| <b>anonymized</b> (content preserved, shown as "Deleted User"). | ||
| </li> | ||
| )} | ||
| {audit.threadCommentCount > 0 && ( | ||
| <li> | ||
| <Tag minimal>{audit.threadCommentCount}</Tag> comment | ||
| {audit.threadCommentCount !== 1 ? 's' : ''} you wrote will be{' '} | ||
| <b>anonymized</b> (content preserved, shown as "Deleted User"). | ||
| </li> | ||
| )} | ||
| {audit.releaseCount > 0 && ( | ||
| <li> | ||
| <Tag minimal>{audit.releaseCount}</Tag> release | ||
| {audit.releaseCount !== 1 ? 's' : ''} you created will be | ||
| preserved. | ||
| </li> | ||
| )} | ||
| {audit.membershipCount > 0 && ( | ||
| <li> | ||
| <Tag minimal>{audit.membershipCount}</Tag> membership | ||
| {audit.membershipCount !== 1 ? 's' : ''} will be removed. | ||
| </li> | ||
| )} | ||
| </ul> | ||
| </div> | ||
| )} | ||
| <p>Enter your password to confirm account deletion.</p> | ||
| <InputField | ||
| label={<b>Password</b>} | ||
| type="password" | ||
| value={password} | ||
| onChange={(evt) => setPassword(evt.target.value)} | ||
| /> | ||
| {error && ( | ||
| <Callout intent="danger" style={{ marginBottom: 10 }}> | ||
| {error} | ||
| </Callout> | ||
| )} | ||
| <Button | ||
| intent="danger" | ||
| text="Permanently delete my account" | ||
| loading={isDeleting} | ||
| onClick={handleDelete} | ||
| disabled={!password} | ||
| /> | ||
| </Callout> | ||
| </Card> | ||
| ); | ||
| }; | ||
|
|
||
| export default DeleteAccount; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import React from 'react'; | ||
|
|
||
| import { Callout } from '@blueprintjs/core'; | ||
|
|
||
| import { usePageContext } from 'utils/hooks'; | ||
|
|
||
| import './pubArchiveNotice.scss'; | ||
|
|
||
| const PubArchiveNotice = () => { | ||
| const { communityData } = usePageContext(); | ||
|
|
||
| if (!communityData.isArchiveCommunity) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Callout icon="archive" intent="primary" className="pub-archive-notice-component"> | ||
| <p> | ||
| This publication's community has been removed. This page is maintained to preserve | ||
| the scholarly record. | ||
| </p> | ||
| </Callout> | ||
| ); | ||
| }; | ||
|
|
||
| export default PubArchiveNotice; |
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.
Uh oh!
There was an error while loading. Please reload this page.