about summary refs log tree commit diff
path: root/gn_auth/auth/authorisation/resources
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-02-29 04:04:34 +0300
committerMunyoki Kilyungi2024-03-04 12:33:24 +0300
commitf5e833c0d72eaec80425203b15210ed304cc4811 (patch)
tree5ccb254dbfaf9c63a1874138dfa99ab1701655e9 /gn_auth/auth/authorisation/resources
parentbf700400e56b64e536d9535f86f0c8add31b1c48 (diff)
downloadgn-auth-f5e833c0d72eaec80425203b15210ed304cc4811.tar.gz
Add an extra endpoint for metadata authorisation.
* gn_auth/auth/authorisation/data/views.py: (metadata_resources): New
end-point for authorising metadata data.
* gn_auth/auth/authorisation/resources/models.py: Import sqlite3.Row.
(__metadata_resource_data__): New function.
(__assign_resource_owner_role__): Add __metadata_resource_data__
to the "resource_data_function" map.

Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn_auth/auth/authorisation/resources')
-rw-r--r--gn_auth/auth/authorisation/resources/models.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py
index d6e3a1d..3693ad1 100644
--- a/gn_auth/auth/authorisation/resources/models.py
+++ b/gn_auth/auth/authorisation/resources/models.py
@@ -1,6 +1,7 @@
 """Handle the management of resources."""
 from uuid import UUID, uuid4
 from functools import reduce, partial
+from sqlite3 import Row
 from typing import Dict, Sequence, Optional
 
 from gn_auth.auth.db import sqlite3 as db
@@ -35,6 +36,22 @@ from .phenotype import (
 
 from .errors import MissingGroupError
 
+
+def __metadata_resource_data__(
+        cursor: db.DbCursor,
+        resource_id: UUID,
+        offset: int = 0,
+        limit: Optional[int] = None
+) -> Sequence[Row]:
+    """Fetch metadata resources"""
+    cursor.execute(
+        (
+            ("SELECT * FROM metadata_resources as mt \
+WHERE mt.resource_id=?")
+            + (f" LIMIT {limit} OFFSET {offset}" if bool(limit) else "")),
+        (str(resource_id),))
+    return cursor.fetchall()
+
 def __assign_resource_owner_role__(cursor, resource, user, group):
     """Assign `user` the 'Resource Owner' role for `resource`."""
     cursor.execute(
@@ -185,6 +202,7 @@ def resource_data(conn, resource, offset: int = 0, limit: Optional[int] = None)
         "mrna": mrna_resource_data,
         "genotype": genotype_resource_data,
         "phenotype": phenotype_resource_data,
+        "metadata": __metadata_resource_data__,
         "system": lambda *args: tuple(),
         "group": lambda *args: tuple()
     }
@@ -291,6 +309,7 @@ def attach_resources_data(
         "mrna": mrna_attach_resources_data,
         "genotype": genotype_attach_resources_data,
         "phenotype": phenotype_attach_resources_data,
+        "metadata": lambda *args: [],
         "system": lambda *args: [],
         "group": lambda *args: [],
         "inbredset-group": lambda *args: []