Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Task Owner can Delete Datasets (#764)
Browse files Browse the repository at this point in the history
* dataset api handle delete

* add api call to frontend

* add delete button and icon

* allow DELETE method

* call api on delete button click

* remove unused svg attrs

* use fontawesome trash icon

* delete dataset files on s3

* typos and misc

* remove delete button text
  • Loading branch information
kokrui authored Oct 13, 2021
1 parent 21086e5 commit e534f68
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
4 changes: 3 additions & 1 deletion api/common/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def add_cors_headers():

bottle.default_app()
bottle.response.headers["Access-Control-Allow-Origin"] = origin
bottle.response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, OPTIONS"
bottle.response.headers[
"Access-Control-Allow-Methods"
] = "GET, POST, PUT, DELETE, OPTIONS"
bottle.response.headers[
"Access-Control-Allow-Headers"
] = "Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token, Authorization"
Expand Down
35 changes: 35 additions & 0 deletions api/controllers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,41 @@ def update(credentials, did):
return util.json_encode({"success": "ok"})


@bottle.delete("/datasets/delete/<did:int>")
@_auth.requires_auth
def delete(credentials, did):
dm = DatasetModel()
dataset = dm.get(did)
ensure_owner_or_admin(dataset.tid, credentials["id"])

tm = TaskModel()
task = tm.get(dataset.tid)

delta_metric_types = [
config["type"]
for config in ujson.loads(task.annotation_config_json)["delta_metrics"]
]
delta_metric_types.append(None)

s3_client = boto3.client(
"s3",
aws_access_key_id=config["eval_aws_access_key_id"],
aws_secret_access_key=config["eval_aws_secret_access_key"],
region_name=config["eval_aws_region"],
)

for perturb_prefix in delta_metric_types:
s3_client.delete_object(
Bucket=task.s3_bucket,
Key=get_data_s3_path(
task.task_code, dataset.name + ".jsonl", perturb_prefix
),
)

dm.delete(dataset)
return util.json_encode({"success": "ok"})


@bottle.post("/datasets/create/<tid:int>/<name>")
@_auth.requires_auth
def create(credentials, tid, name):
Expand Down
6 changes: 6 additions & 0 deletions frontends/web/src/common/ApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ export default class ApiService {
});
}

deleteDataset(did) {
return this.fetch(`${this.domain}/datasets/delete/${did}`, {
method: "DELETE",
});
}

uploadPredictions(tid, modelName, files) {
const token = this.getToken();
const formData = new FormData();
Expand Down
13 changes: 12 additions & 1 deletion frontends/web/src/components/TaskOwnerPageComponents/Datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,24 @@ const Datasets = (props) => {
className="py-3 my-0 border-bottom"
>
<Form.Label column>Name</Form.Label>
<Col sm="8">
<Col sm="6">
<Form.Control
disabled
plaintext
defaultValue={dataset.name}
/>
</Col>
<Col sm="2">
<Button
variant="danger"
className="btn-block"
onClick={() => {
props.handleDatasetDelete(values.id);
}}
>
<i class="fas fa-trash-alt"></i>
</Button>
</Col>
</Form.Group>
<Form.Group
as={Row}
Expand Down
7 changes: 7 additions & 0 deletions frontends/web/src/containers/TaskOwnerPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ class TaskOwnerPage extends React.Component {
);
};

handleDatasetDelete = (did) => {
this.context.api.deleteDataset(did).then((result) => {
this.fetchDatasets();
});
};

handleRoundUpdate = (
values,
{ setFieldError, setSubmitting, setFieldValue, resetForm }
Expand Down Expand Up @@ -544,6 +550,7 @@ class TaskOwnerPage extends React.Component {
handleUploadAndCreateDataset={
this.handleUploadAndCreateDataset
}
handleDatasetDelete={this.handleDatasetDelete}
/>
) : null}
</>
Expand Down

0 comments on commit e534f68

Please sign in to comment.