about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--gn_auth/auth/authorisation/resources/genotypes/models.py9
-rw-r--r--gn_auth/auth/authorisation/resources/models.py10
-rw-r--r--gn_auth/auth/authorisation/resources/mrna.py9
-rw-r--r--gn_auth/auth/authorisation/resources/phenotypes/models.py9
-rw-r--r--gn_auth/auth/authorisation/resources/views.py9
5 files changed, 28 insertions, 18 deletions
diff --git a/gn_auth/auth/authorisation/resources/genotypes/models.py b/gn_auth/auth/authorisation/resources/genotypes/models.py
index 464537e..762ee7c 100644
--- a/gn_auth/auth/authorisation/resources/genotypes/models.py
+++ b/gn_auth/auth/authorisation/resources/genotypes/models.py
@@ -27,14 +27,15 @@ def resource_data(
 def link_data_to_resource(
         conn: db.DbConnection,
         resource: Resource,
-        data_link_id: uuid.UUID) -> dict:
+        data_link_ids: tuple[uuid.UUID, ...]
+) -> tuple[dict, ...]:
     """Link Genotype data with a resource using the GUI."""
     with db.cursor(conn) as cursor:
-        params = {
+        params = tuple({
             "resource_id": str(resource.resource_id),
             "data_link_id": str(data_link_id)
-        }
-        cursor.execute(
+        } for data_link_id in data_link_ids)
+        cursor.executemany(
             "INSERT INTO genotype_resources VALUES"
             "(:resource_id, :data_link_id)",
             params)
diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py
index d136fec..e538a87 100644
--- a/gn_auth/auth/authorisation/resources/models.py
+++ b/gn_auth/auth/authorisation/resources/models.py
@@ -207,8 +207,12 @@ def resource_by_id(
     raise NotFoundError(f"Could not find a resource with id '{resource_id}'")
 
 def link_data_to_resource(
-        conn: db.DbConnection, user: User, resource_id: UUID, dataset_type: str,
-        data_link_id: UUID) -> dict:
+        conn: db.DbConnection,
+        user: User,
+        resource_id: UUID,
+        dataset_type: str,
+        data_link_ids: tuple[UUID, ...]
+) -> tuple[dict, ...]:
     """Link data to resource."""
     if not authorised_for(
             conn, user, ("group:resource:edit-resource",),
@@ -223,7 +227,7 @@ def link_data_to_resource(
         "mrna": mrna_link_data_to_resource,
         "genotype": genotype_link_data_to_resource,
         "phenotype": phenotype_link_data_to_resource,
-    }[dataset_type.lower()](conn, resource, data_link_id)
+    }[dataset_type.lower()](conn, resource, data_link_ids)
 
 def unlink_data_from_resource(
         conn: db.DbConnection, user: User, resource_id: UUID, data_link_id: UUID):
diff --git a/gn_auth/auth/authorisation/resources/mrna.py b/gn_auth/auth/authorisation/resources/mrna.py
index 7fce227..66f8824 100644
--- a/gn_auth/auth/authorisation/resources/mrna.py
+++ b/gn_auth/auth/authorisation/resources/mrna.py
@@ -26,14 +26,15 @@ def resource_data(cursor: db.DbCursor,
 def link_data_to_resource(
         conn: db.DbConnection,
         resource: Resource,
-        data_link_id: uuid.UUID) -> dict:
+        data_link_ids: tuple[uuid.UUID, ...]
+) -> tuple[dict, ...]:
     """Link mRNA Assay data with a resource."""
     with db.cursor(conn) as cursor:
-        params = {
+        params = tuple({
             "resource_id": str(resource.resource_id),
             "data_link_id": str(data_link_id)
-        }
-        cursor.execute(
+        } for data_link_id in data_link_ids)
+        cursor.executemany(
             "INSERT INTO mrna_resources VALUES"
             "(:resource_id, :data_link_id)",
             params)
diff --git a/gn_auth/auth/authorisation/resources/phenotypes/models.py b/gn_auth/auth/authorisation/resources/phenotypes/models.py
index d4a516a..0ef91ab 100644
--- a/gn_auth/auth/authorisation/resources/phenotypes/models.py
+++ b/gn_auth/auth/authorisation/resources/phenotypes/models.py
@@ -29,14 +29,15 @@ def resource_data(
 def link_data_to_resource(
         conn: db.DbConnection,
         resource: Resource,
-        data_link_id: uuid.UUID) -> dict:
+        data_link_ids: tuple[uuid.UUID, ...]
+) -> tuple[dict, ...]:
     """Link Phenotype data with a resource."""
     with db.cursor(conn) as cursor:
-        params = {
+        params = tuple({
             "resource_id": str(resource.resource_id),
             "data_link_id": str(data_link_id)
-        }
-        cursor.execute(
+        } for data_link_id in data_link_ids)
+        cursor.executemany(
             "INSERT INTO phenotype_resources VALUES"
             "(:resource_id, :data_link_id)",
             params)
diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py
index 29ab3ed..0a68927 100644
--- a/gn_auth/auth/authorisation/resources/views.py
+++ b/gn_auth/auth/authorisation/resources/views.py
@@ -153,7 +153,7 @@ def link_data():
     try:
         form = request_json()
         assert "resource_id" in form, "Resource ID not provided."
-        assert "data_link_id" in form, "Data Link ID not provided."
+        assert "data_link_ids" in form, "Data Link IDs not provided."
         assert "dataset_type" in form, "Dataset type not specified"
         assert form["dataset_type"].lower() in (
             "mrna", "genotype", "phenotype"), "Invalid dataset type provided."
@@ -161,8 +161,11 @@ def link_data():
         with require_oauth.acquire("profile group resource") as the_token:
             def __link__(conn: db.DbConnection):
                 return link_data_to_resource(
-                    conn, the_token.user, UUID(form["resource_id"]),
-                    form["dataset_type"], UUID(form["data_link_id"]))
+                    conn,
+                    the_token.user,
+                    UUID(form["resource_id"]),
+                    form["dataset_type"],
+                    tuple(UUID(dlinkid) for dlinkid in form["data_link_ids"]))
 
             return jsonify(with_db_connection(__link__))
     except AssertionError as aserr: