aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authorisation/resources/views.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-02-23 12:37:19 +0300
committerFrederick Muriuki Muriithi2023-02-23 12:37:19 +0300
commita2cb41430eb9d66f50b83c5b724172cbf90c89a2 (patch)
treea1a83b7fc5574de8ddf2e6051e076779654498f0 /gn3/auth/authorisation/resources/views.py
parentc876c9f53018529fed1cb025a085b6e9d37dc3ef (diff)
downloadgenenetwork3-a2cb41430eb9d66f50b83c5b724172cbf90c89a2.tar.gz
auth: Link data in MySQL to the groups (in SQLite)
In order for the group leaders (and other resource creators) to be able to link data to the resources, the data needs to be first linked to the relevant group. This commit enables the system admin to link the data in MySQL to the groups.
Diffstat (limited to 'gn3/auth/authorisation/resources/views.py')
-rw-r--r--gn3/auth/authorisation/resources/views.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/gn3/auth/authorisation/resources/views.py b/gn3/auth/authorisation/resources/views.py
index 44e2c4e..e373182 100644
--- a/gn3/auth/authorisation/resources/views.py
+++ b/gn3/auth/authorisation/resources/views.py
@@ -7,13 +7,13 @@ from flask import request, jsonify, Response, Blueprint, current_app as app
from gn3 import db_utils as gn3dbutils
from gn3.auth.db_utils import with_db_connection
-from .data import retrieve_ungrouped_data
+from .data import link_data_to_group, retrieve_ungrouped_data
from .models import (
resource_by_id, resource_categories, resource_category_by_id,
create_resource as _create_resource)
-from ..errors import AuthorisationError
-from ..groups.models import user_group, DUMMY_GROUP
+from ..errors import InvalidData, AuthorisationError
+from ..groups.models import user_group, DUMMY_GROUP, group_by_id
from ... import db
from ...dictify import dictify
@@ -115,7 +115,27 @@ def ungrouped_data(dataset_type: str) -> Response:
if dataset_type not in ("all", "mrna", "genotype", "phenotype"):
raise AuthorisationError(f"Invalid dataset type {dataset_type}")
- with gn3dbutils.database_connection() as gn3conn:
- return jsonify(with_db_connection(partial(
- retrieve_ungrouped_data, gn3conn=gn3conn,
- dataset_type=dataset_type)))
+ with require_oauth.acquire("profile group resource") as _the_token:
+ with gn3dbutils.database_connection() as gn3conn:
+ return jsonify(with_db_connection(partial(
+ retrieve_ungrouped_data, gn3conn=gn3conn,
+ dataset_type=dataset_type)))
+
+@resources.route("/data/link", methods=["POST"])
+@require_oauth("profile group resource")
+def link_data() -> Response:
+ """Link selected data to specified group."""
+ with require_oauth.acquire("profile group resource") as _the_token:
+ form = request.form
+ group_id = uuid.UUID(form["group_id"])
+ dataset_id = form["dataset_id"]
+ dataset_type = form.get("dataset_type")
+ if dataset_type not in ("mrna", "genotype", "phenotype"):
+ raise InvalidData("Unexpected dataset type requested!")
+ def __link__(conn: db.DbConnection):
+ group = group_by_id(conn, group_id)
+ with gn3dbutils.database_connection() as gn3conn:
+ return link_data_to_group(
+ conn, gn3conn, dataset_type, dataset_id, group)
+
+ return jsonify(with_db_connection(__link__))