diff options
author | Frederick Muriuki Muriithi | 2023-02-28 12:45:57 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-02-28 12:50:27 +0300 |
commit | bbd61fc91bd9bdbf41201dd8f609e02ef8339974 (patch) | |
tree | 61ac39341bcc5764c664d7977eb835cb34163451 /gn3/auth/authorisation/resources/views.py | |
parent | 36248ee1592b87edd83a15c68e090ec220992535 (diff) | |
download | genenetwork3-bbd61fc91bd9bdbf41201dd8f609e02ef8339974.tar.gz |
auth: Unlink data from resources
Enable the data editor to unlink data from a particular resource.
Diffstat (limited to 'gn3/auth/authorisation/resources/views.py')
-rw-r--r-- | gn3/auth/authorisation/resources/views.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/gn3/auth/authorisation/resources/views.py b/gn3/auth/authorisation/resources/views.py index b2773a8..cac904c 100644 --- a/gn3/auth/authorisation/resources/views.py +++ b/gn3/auth/authorisation/resources/views.py @@ -7,7 +7,8 @@ from gn3.auth.db_utils import with_db_connection from .models import ( resource_by_id, resource_categories, link_data_to_resource, - resource_category_by_id, create_resource as _create_resource) + resource_category_by_id, unlink_data_from_resource, + create_resource as _create_resource) from ..errors import InvalidData @@ -73,3 +74,23 @@ def link_data(): return jsonify(with_db_connection(__link__)) except AssertionError as aserr: raise InvalidData(aserr.args[0]) from aserr + + + +@resources.route("/data/unlink", methods=["POST"]) +@require_oauth("profile group resource") +def unlink_data(): + """Unlink data bound to a specific resource.""" + try: + form = request.form + assert "resource_id" in form, "Resource ID not provided." + assert "dataset_id" in form, "Dataset ID not provided." + + with require_oauth.acquire("profile group resource") as the_token: + def __unlink__(conn: db.DbConnection): + return unlink_data_from_resource( + conn, the_token.user, uuid.UUID(form["resource_id"]), + form["dataset_id"]) + return jsonify(with_db_connection(__unlink__)) + except AssertionError as aserr: + raise InvalidData(aserr.args[0]) from aserr |