diff options
author | Frederick Muriuki Muriithi | 2023-02-06 14:20:24 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-02-06 14:20:24 +0300 |
commit | 30da2f48eb35360bb339d54da2ab83d96a1cf85b (patch) | |
tree | e30f2e0c3e884df0be52c7c3ffe65d1636aaa2c1 /gn3/auth/authorisation/resources/views.py | |
parent | 6c76667857d5bbc8db962a551cece3f068074055 (diff) | |
download | genenetwork3-30da2f48eb35360bb339d54da2ab83d96a1cf85b.tar.gz |
auth: resource: Enable viewing the details of a resource.
Diffstat (limited to 'gn3/auth/authorisation/resources/views.py')
-rw-r--r-- | gn3/auth/authorisation/resources/views.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/gn3/auth/authorisation/resources/views.py b/gn3/auth/authorisation/resources/views.py index 77346bb..b45a9fc 100644 --- a/gn3/auth/authorisation/resources/views.py +++ b/gn3/auth/authorisation/resources/views.py @@ -1,9 +1,9 @@ """The views/routes for the resources package""" import uuid -from flask import request, jsonify, Blueprint, current_app as app +from flask import request, jsonify, Response, Blueprint, current_app as app from .models import ( - resource_categories, resource_category_by_id, + resource_by_id, resource_categories, resource_category_by_id, create_resource as _create_resource) from ... import db @@ -14,7 +14,7 @@ resources = Blueprint("resources", __name__) @resources.route("/categories", methods=["GET"]) @require_oauth("profile group resource") -def list_resource_categories(): +def list_resource_categories() -> Response: """Retrieve all resource categories""" db_uri = app.config["AUTH_DB"] with db.connection(db_uri) as conn: @@ -23,7 +23,7 @@ def list_resource_categories(): @resources.route("/create", methods=["POST"]) @require_oauth("profile group resource") -def create_resource(): +def create_resource() -> Response: """Create a new resource""" with require_oauth.acquire("profile group resource") as the_token: form = request.form @@ -33,6 +33,16 @@ def create_resource(): with db.connection(db_uri) as conn: resource = _create_resource( conn, resource_name, resource_category_by_id( - conn, resource_category_id).maybe(False, lambda rcat: rcat), + conn, resource_category_id), the_token.user) return jsonify(dictify(resource)) + +@resources.route("/view/<uuid:resource_id>") +@require_oauth("profile group resource") +def view_resource(resource_id: uuid.UUID) -> Response: + """View a particular resource's details.""" + with require_oauth.acquire("profile group resource") as the_token: + db_uri = app.config["AUTH_DB"] + with db.connection(db_uri) as conn: + return jsonify(dictify(resource_by_id( + conn, the_token.user, resource_id))) |