Skip to content

Commit

Permalink
Merge pull request #1527 from ScilifelabDataCentre/DDS-1856-Fix-the-P…
Browse files Browse the repository at this point in the history
…roject-endpoints-according-to-the-OpenAPI-standard

Fix the project endpoints according to the open api standard
  • Loading branch information
rv0lt authored Jun 13, 2024
2 parents dd770b3 + 702a348 commit 9fb97f9
Show file tree
Hide file tree
Showing 5 changed files with 1,861 additions and 8 deletions.
4 changes: 4 additions & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,7 @@ _Nothing merged in CLI during this sprint_
- Fix raising error when archiving project, bucket deleted but DB error ([#1524](https://github.com/ScilifelabDataCentre/dds_web/pull/1524))
- Increase the identified less covered files([#1521](https://github.com/ScilifelabDataCentre/dds_web/pull/1521))
- Parse boolean inputs correctly ([#1528](https://github.com/ScilifelabDataCentre/dds_web/pull/1528))

# 2024-06-03 - 2024-06-14

- Fix the project endpoints according to the OpenAPI standard ([#1527](https://github.com/ScilifelabDataCentre/dds_web/pull/1527))
30 changes: 30 additions & 0 deletions dds_web/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# Installed
import flask_restful
from flask_restful import inputs
import flask
import sqlalchemy
import datetime
Expand Down Expand Up @@ -59,6 +60,35 @@ class ProjectStatus(flask_restful.Resource):
@handle_validation_errors
def get(self):
"""Get current project status and optionally entire status history"""
if "api/v1" in flask.request.path:
# requests comming from api/v1 should be handled as before
return self.old_get()

elif "api/v3" in flask.request.path:
# Get project ID, project and verify access
project_id = dds_web.utils.get_required_item(obj=flask.request.args, req="project")
project = dds_web.utils.collect_project(project_id=project_id)
dds_web.utils.verify_project_access(project=project)

# Get current status and deadline
return_info = {"current_status": project.current_status}
if project.current_deadline:
return_info["current_deadline"] = project.current_deadline

# Get status history
history = flask.request.args.get("history", type=inputs.boolean, default=False)
if history:
history_info = []
for pstatus in project.project_statuses:
history_info.append(tuple((pstatus.status, pstatus.date_created)))
history_info.sort(key=lambda x: x[1], reverse=True)
return_info.update({"history": history_info})

return return_info

def old_get(self):
"""Implementation of old get method. Should be removed when api/v1 is removed."""

# Get project ID, project and verify access
project_id = dds_web.utils.get_required_item(obj=flask.request.args, req="project")
project = dds_web.utils.collect_project(project_id=project_id)
Expand Down
12 changes: 4 additions & 8 deletions dds_web/static/swaggerv3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1001,12 +1001,7 @@ paths:
get:
tags:
- project
summary: Get current project status and optionally entire status history CHECK METHOD
description: This method requires some data
to be passed in the request body instead of the query.
Since this does not comply with the openAPI standards, swagger cannot document it properly,
therefore we need to change/remove it in the future.
deprecated: true
summary: Get current project status and optionally entire status history
operationId: projectStatusGet
parameters:
- $ref: "#/components/parameters/defaultHeader"
Expand All @@ -1017,7 +1012,7 @@ paths:
schema:
type: boolean
example: true
description: If true, return entire status history
description: If true, return entire status history. If false or missing, return only current status
responses:
"401":
$ref: "#/components/responses/UnauthorizedToken"
Expand Down Expand Up @@ -1659,7 +1654,8 @@ components:
in: query
schema:
type: string
description: Project id to query
required: true
description: project id to query
email:
name: email
in: query
Expand Down
Empty file added tests/tests_v3/api/__init__.py
Empty file.
Loading

0 comments on commit 9fb97f9

Please sign in to comment.