Skip to content

Commit c941759

Browse files
authored
Merge pull request #3334 from OpenNeuroOrg/3316-unrestrict-deletion
feat(app): Allow users to delete datasets if no versions have been created
2 parents 96574b6 + 0961e5f commit c941759

File tree

3 files changed

+86
-42
lines changed

3 files changed

+86
-42
lines changed

packages/openneuro-app/src/scripts/dataset/routes/delete-page.tsx

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
import React, { useState } from "react"
2-
import { useCookies } from "react-cookie"
32
import DeleteDatasetForm from "../mutations/delete-dataset-form.jsx"
43
import DeleteDataset from "../mutations/delete.jsx"
54
import LoggedIn from "../../authentication/logged-in.jsx"
6-
import { getProfile } from "../../authentication/profile"
7-
import AdminUser from "../../authentication/admin-user.jsx"
8-
import { RegularUser } from "../../authentication/regular-user"
95
import { DatasetPageBorder } from "./styles/dataset-page-border"
106
import { HeaderRow3 } from "./styles/header-row"
117

12-
interface DeletePageProps {
13-
dataset: {
14-
permissions: Record<string, object>
15-
id: string
16-
}
8+
interface DeletePageAction {
9+
datasetId: string
10+
hasEdit: boolean
1711
}
1812

19-
const DeletePage = ({ dataset }: DeletePageProps): React.ReactElement => {
13+
export function DeletePageAction({ datasetId, hasEdit }: DeletePageAction) {
2014
const [values, setValues] = useState({
2115
reason: "",
2216
redirect: "",
@@ -28,40 +22,79 @@ const DeletePage = ({ dataset }: DeletePageProps): React.ReactElement => {
2822
}
2923
setValues(newValues)
3024
}
31-
const [cookies] = useCookies()
32-
const user = getProfile(cookies)
33-
const hasEdit = user && user.admin
34-
const datasetId = dataset.id
3525
return (
36-
<DatasetPageBorder>
37-
<HeaderRow3>Delete Dataset</HeaderRow3>
38-
<AdminUser>
39-
<DeleteDatasetForm
40-
values={values}
41-
onChange={handleInputChange}
42-
hideDisabled={false}
43-
hasEdit={hasEdit}
44-
/>
26+
<>
27+
<DeleteDatasetForm
28+
values={values}
29+
onChange={handleInputChange}
30+
hideDisabled={false}
31+
hasEdit={hasEdit}
32+
/>
33+
<p>
34+
<small className="warning-text">
35+
* Warning: this action will permanently remove this dataset along with
36+
associated snapshots.
37+
</small>
38+
</p>
39+
<div className="dataset-form-controls">
40+
<LoggedIn>
41+
<DeleteDataset datasetId={datasetId} metadata={values} />
42+
</LoggedIn>
43+
</div>
44+
</>
45+
)
46+
}
47+
48+
interface DeletePageMessageProps {
49+
hasEdit: boolean
50+
}
51+
52+
export function DeletePageMessage({ hasEdit }: DeletePageMessageProps) {
53+
if (hasEdit) {
54+
return (
55+
<>
4556
<p>
46-
<small className="warning-text">
47-
* Warning: this action will permanently remove this dataset along
48-
with associated snapshots.
49-
</small>
57+
This dataset has versions with DOIs that would be orphaned by
58+
deletion.
5059
</p>
51-
<div className="dataset-form-controls">
52-
<LoggedIn>
53-
<DeleteDataset datasetId={datasetId} metadata={values} />
54-
</LoggedIn>
55-
</div>
56-
</AdminUser>
57-
<RegularUser>
5860
<p>
59-
Please contact support to permanently remove a dataset and all
60-
versions of it. Provide a reason for the removal request and if the
61-
dataset is a duplicate or has been supplanted by another provide that
62-
information for a redirect to be created.
61+
If deletion is required please contact support to permanently remove a
62+
dataset and all versions of it. Provide a reason for the removal
63+
request and if the dataset is a duplicate or has been supplanted by
64+
another provide that information for a redirect to be created.
6365
</p>
64-
</RegularUser>
66+
</>
67+
)
68+
} else {
69+
return (
70+
<p>
71+
Login or request dataset admin permissions from a dataset admin to
72+
delete this dataset.
73+
</p>
74+
)
75+
}
76+
}
77+
78+
interface DeletePageProps {
79+
dataset: {
80+
permissions: Record<string, object>
81+
id: string
82+
snapshots: object[]
83+
}
84+
hasEdit: boolean
85+
}
86+
87+
const DeletePage = (
88+
{ dataset, hasEdit }: DeletePageProps,
89+
): React.ReactElement => {
90+
const datasetId = dataset.id
91+
const canBeDeleted = dataset.snapshots.length === 0 && hasEdit
92+
return (
93+
<DatasetPageBorder>
94+
<HeaderRow3>Delete Dataset</HeaderRow3>
95+
{canBeDeleted
96+
? <DeletePageAction datasetId={datasetId} hasEdit={hasEdit} />
97+
: <DeletePageMessage hasEdit={hasEdit} />}
6598
</DatasetPageBorder>
6699
)
67100
}

packages/openneuro-app/src/scripts/dataset/routes/snapshot.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ const SnapshotRoute = ({
7474
)}
7575
<p>
7676
Create a new version of this dataset for download and public access.
77-
This will begin an export of this dataset to GitHub and S3 if it has
78-
been made public.
77+
DOIs are assigned to versions created. This will begin an export of
78+
this dataset to GitHub and S3 if it has been made public.
7979
</p>
8080
<FormRow className="snapshot-input-group">
8181
{newVersion}
@@ -128,6 +128,14 @@ const SnapshotRoute = ({
128128
You must add at least one change message to create a new version
129129
</small>
130130
)}
131+
{snapshots.length === 0
132+
? (
133+
<p>
134+
Once a version has been created and DOI assigned, the dataset
135+
can no longer be deleted.
136+
</p>
137+
)
138+
: null}
131139
<div className="dataset-form-controls">
132140
<SnapshotDataset
133141
datasetId={datasetId}

packages/openneuro-app/src/scripts/dataset/routes/tab-routes-draft.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export const TabRoutesDraft = ({ dataset, hasEdit }) => {
3131
path="derivatives"
3232
element={<Derivatives derivatives={dataset.derivatives} />}
3333
/>
34-
<Route path="delete" element={<DeletePage dataset={dataset} />} />
34+
<Route
35+
path="delete"
36+
element={<DeletePage dataset={dataset} hasEdit={hasEdit} />}
37+
/>
3538
<Route path="admin" element={<AdminDataset dataset={dataset} />} />
3639
<Route
3740
path="publish"

0 commit comments

Comments
 (0)