Skip to content

Commit

Permalink
feat: schema validation for available ipd
Browse files Browse the repository at this point in the history
  • Loading branch information
slugb0t committed Oct 12, 2023
1 parent b1c1ba7 commit 44a11ed
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apis/study_metadata/study_available_ipd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from model import Study, db, StudyAvailableIpd
from apis.study_metadata_namespace import api
from ..authentication import is_granted
from jsonschema import validate, ValidationError


study_available = api.model(
Expand Down Expand Up @@ -44,6 +45,27 @@ def get(self, study_id: int):
@api.marshal_with(study_available)
def post(self, study_id: int):
"""Create study available metadata"""
# Schema validation
schema = {
"type": "array",
"additionalProperties": False,
"items": {
"type": "object",
"properties": {
"identifier": {"type": "string"},
"type": {"type": "string"},
"comment": {"type": "string"},
"url": {"type": "string"},
},
"required": ["identifier", "type", "comment", "url"],
},
}

try:
validate(request.json, schema)
except ValidationError as e:
return e.message, 400

study = Study.query.get(study_id)
if not is_granted("study_metadata", study):
return "Access denied, you can not delete study", 403
Expand Down

0 comments on commit 44a11ed

Please sign in to comment.