From bbd61fc91bd9bdbf41201dd8f609e02ef8339974 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 28 Feb 2023 12:45:57 +0300 Subject: auth: Unlink data from resources Enable the data editor to unlink data from a particular resource. --- gn3/auth/authorisation/resources/views.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'gn3/auth/authorisation/resources/views.py') 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 -- cgit v1.2.3