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
- add endpoints in specification.yml
  • Loading branch information
blankdots committed Nov 30, 2022
1 parent 8cffefe commit d28cda2
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 3 deletions.
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
127 changes: 125 additions & 2 deletions docs/specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,90 @@ paths:
schema:
$ref: "#/components/schemas/405MethodNotAllowed"
/v1/submissions/{submissionId}/files:
post:
tags:
- Submission
summary: Add new files to a submission.
parameters:
- name: submissionId
in: path
description: ID of the object submission.
schema:
type: string
required: true
requestBody:
content:
application/json:
schema:
type: array
items:
type: object
properties:
accessionId:
type: string
title: Accession Id for file
version:
type: integer
title: Version of the file
responses:
204:
description: No Content
400:
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/400BadRequest"
401:
description: Unauthorized
content:
application/json:
schema:
$ref: "#/components/schemas/401Unauthorized"
403:
description: Forbidden
content:
application/json:
schema:
$ref: "#/components/schemas/403Forbidden"
get:
tags:
- Query
summary: Retrieve all files with detailed info specific to a submission.
parameters:
- name: submissionId
in: path
description: ID of the object submission.
schema:
type: string
required: true
responses:
200:
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/File"
400:
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/400BadRequest"
401:
description: Unauthorized
content:
application/json:
schema:
$ref: "#/components/schemas/401Unauthorized"
403:
description: Forbidden
content:
application/json:
schema:
$ref: "#/components/schemas/403Forbidden"
put:
tags:
- Manage
Expand Down Expand Up @@ -1459,6 +1543,45 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/405MethodNotAllowed"
/v1/submissions/{submissionId}/files/{fileId}:
delete:
tags:
- Manage
summary: Remove file from a submission.
parameters:
- name: submissionId
in: path
description: ID of the object submission.
schema:
type: string
required: true
- name: fileId
in: path
description: ID of the object submission.
schema:
type: string
required: true
responses:
204:
description: No Content
400:
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/400BadRequest"
401:
description: Unauthorized
content:
application/json:
schema:
$ref: "#/components/schemas/401Unauthorized"
403:
description: Forbidden
content:
application/json:
schema:
$ref: "#/components/schemas/403Forbidden"
/v1/publish/{submissionId}:
patch:
tags:
Expand Down Expand Up @@ -3010,7 +3133,7 @@ components:
type: object
description: Describes a submission file information that can be attached to a submission
properties:
accesionId:
accessionId:
type: string
title: Accession Id for file
version:
Expand All @@ -3032,5 +3155,5 @@ components:
description: type of schema this Accession ID relates to and was added in submit
error:
type: string
title: Accession Id for file
title: Error for file if status is failed
description: required only if status is failed
25 changes: 25 additions & 0 deletions metadata_backend/api/handlers/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,28 @@ 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"]
file_accession_id = req.match_info["fileId"]
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)

await file_operator.remove_file_submission(file_accession_id, "accessionId", submission_id)
LOG.info("Removing file: %r from submission with ID: %r was successful.", file_accession_id, submission_id)
return web.HTTPNoContent()
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/{fileId}", _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 d28cda2

Please sign in to comment.