diff options
author | Frederick Muriuki Muriithi | 2023-05-15 11:40:28 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-05-15 11:40:28 +0300 |
commit | 09ab7df7a5cedb3bf09117626a46185ad46566f8 (patch) | |
tree | 8505fcc57b7aedb05fb1af454d0dcfe250656012 /gn3/auth/authorisation/checks.py | |
parent | 2bdd136b18765fba47a8e313ebff3e65086ca1b1 (diff) | |
download | genenetwork3-09ab7df7a5cedb3bf09117626a46185ad46566f8.tar.gz |
collections: Move code to new package. Create new collections.
Move the code to a new package.
Enable the creation of new collection by both authenticated and anonymous
users.
Diffstat (limited to 'gn3/auth/authorisation/checks.py')
-rw-r--r-- | gn3/auth/authorisation/checks.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/gn3/auth/authorisation/checks.py b/gn3/auth/authorisation/checks.py index 0825c84..1c87c02 100644 --- a/gn3/auth/authorisation/checks.py +++ b/gn3/auth/authorisation/checks.py @@ -2,12 +2,12 @@ from functools import wraps from typing import Callable -from flask import current_app as app +from flask import request, current_app as app from gn3.auth import db from . import privileges as auth_privs -from .errors import AuthorisationError +from .errors import InvalidData, AuthorisationError from ..authentication.oauth2.resource_server import require_oauth @@ -59,3 +59,12 @@ def authorised_p( raise AuthorisationError(error_description) return __authoriser__ return __build_authoriser__ + +def require_json(func): + """Ensure the request has JSON data.""" + @wraps(func) + def __req_json__(*args, **kwargs): + if bool(request.json): + return func(*args, **kwargs) + raise InvalidData("Expected JSON data in the request.") + return __req_json__ |