Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the project endpoints according to the open api standard #1527

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading
Loading