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

Dds 1858 fix the superadmin endpoints according to the open api standard #1533

Merged
Show file tree
Hide file tree
Changes from 2 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
52 changes: 49 additions & 3 deletions dds_web/api/superadmin_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Installed
import flask_restful
from flask_restful import inputs
import flask
import structlog
import flask_mail
Expand Down Expand Up @@ -204,11 +205,31 @@ class FindUser(flask_restful.Resource):

@auth.login_required(role=["Super Admin"])
@logging_bind_request
@json_required
@handle_db_error
def get(self):
"""Return users or a confirmation on if one exists."""
# Get request info
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:
"""Return users or a confirmation on if one exists."""
rv0lt marked this conversation as resolved.
Show resolved Hide resolved

# Get username from request
user_to_find = flask.request.args.get("username")
if not user_to_find:
raise ddserr.DDSArgumentError(
message="Username required to check existence of account."
)

return {
"exists": models.User.query.filter_by(username=user_to_find).one_or_none()
is not None
}

@json_required
def old_get(self):
"""Implementation of old get method. Should be removed when api/v1 is removed.""" # Get request info

request_json = flask.request.get_json(silent=True) # Verified by json_required

# Get username from request
Expand Down Expand Up @@ -303,6 +324,31 @@ class AnyProjectsBusy(flask_restful.Resource):
@handle_db_error
def get(self):
"""Check if any projects are busy."""
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 busy projects
projects_busy: typing.List = models.Project.query.filter_by(busy=True).all()
num_busy: int = len(projects_busy)

# Set info to always return nu
return_info: typing.Dict = {"num": num_busy}

# Return 0 if none are busy
if num_busy == 0:
return return_info

# Check if user listing busy projects
if flask.request.args("list", type=inputs.boolean, default=False) is True:
return_info.update(
{"projects": {p.public_id: p.date_updated for p in projects_busy}}
)

return return_info

def old_get():
# Get busy projects
projects_busy: typing.List = models.Project.query.filter_by(busy=True).all()
num_busy: int = len(projects_busy)
Expand Down
19 changes: 7 additions & 12 deletions dds_web/static/swaggerv3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1418,15 +1418,15 @@ paths:
get:
tags:
- superadmin
summary: Get all users or check if there is a specific user in the database CHECK METHOD
description: This method requires the 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: Check if a specific user exists in the system. The username must be passed
operationId: findUser
parameters:
- $ref: "#/components/parameters/defaultHeader"
- in: query
name: username
schema:
type: string
description: username to check
responses:
"401":
$ref: "#/components/responses/UnauthorizedToken"
Expand Down Expand Up @@ -1483,12 +1483,7 @@ paths:
get:
tags:
- superadmin
summary: Check if any project are busy CHECK METHOD
description: This method requires the 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: Check if any project are busy. Returns the number of busy projects and can list them if requested.
operationId: anyProjectBusy
parameters:
- $ref: "#/components/parameters/defaultHeader"
Expand Down
Empty file added tests/tests_v3/api/__init.py__
Empty file.
Loading
Loading