Skip to content

Commit

Permalink
HTTP Delete file from submission & changelog
Browse files Browse the repository at this point in the history
- add changelog for file operation update and remove
- add delete endpoint to remove a list of files identified by accession id
  • Loading branch information
blankdots committed Nov 28, 2022
1 parent 7a34082 commit 9e42c1b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- add message broker publishing to workflow
- add rabbitmq + default config to integration tests
- File operator that does database operations for files #148
- introduced `/v1/submissions/{submissionId}/files` to update and remove files in a submission #633
- file flagged for deletion also removed from submission and check files have the status ready when being read from the submission #633
- prevent publish if files have in submission have status added (added but no metadata object) or failed (failed in ingestion, completion, or for any other reason) #633
- Mongo indexes for `file` schema #148
- `/files` endpoint to retrieve files attached to a project #148 #627
- option to add additional members to `application/problem+json` #642
Expand Down
32 changes: 32 additions & 0 deletions metadata_backend/api/handlers/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,35 @@ async def add_submission_files(self, req: Request) -> Response:
reason = "Request does not contain a list of Objects each with `accessionId` and `version`"
LOG.error(reason)
raise web.HTTPBadRequest(reason=reason)

async def delete_submission_files(self, req: Request) -> Response:
"""Remove files from a submission.
Body needs to contain a list of accessionId for files.
:param req: POST request with metadata schema in the body
:returns: HTTP No Content response
"""
submission_id = req.match_info["submissionId"]
db_client = req.app["db_client"]
submission_operator = SubmissionOperator(db_client)

# Check submission exists and is not already published
await submission_operator.check_submission_exists(submission_id)
await submission_operator.check_submission_published(submission_id, req.method)

await self._handle_check_ownership(req, "submission", submission_id)

file_operator = FileOperator(db_client)

data: List[str] = await req.json()

if isinstance(data, list):
for accession_id in data:
await file_operator.remove_file_submission(accession_id, "accessionId", submission_id)
LOG.info("Removing file: %r from submission with ID: %r was successful.", accession_id, submission_id)
return web.HTTPNoContent()

reason = "Request does not contain a list of files identified by `accessionId`"
LOG.error(reason)
raise web.HTTPBadRequest(reason=reason)
1 change: 1 addition & 0 deletions metadata_backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def on_prepare(_: web.Request, response: web.StreamResponse) -> None:
web.put("/submissions/{submissionId}/files", _submission.put_submission_path),
web.patch("/submissions/{submissionId}", _submission.patch_submission),
web.delete("/submissions/{submissionId}", _submission.delete_submission),
web.delete("/submissions/{submissionId}/files", _submission.delete_submission_files),
# publish submissions
web.patch("/publish/{submissionId}", _publish_submission.publish_submission),
# users operations
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def test_api_routes_are_set(self):
"""
server = await self.get_application()
self.assertIs(len(server.router.routes()), 60)
self.assertIs(len(server.router.routes()), 61)

async def test_frontend_routes_are_set(self):
"""Test correct routes are set when frontend folder exists."""
Expand Down

0 comments on commit 9e42c1b

Please sign in to comment.