about summary refs log tree commit diff
path: root/gn_auth/auth/authorisation/resources/inbredset/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn_auth/auth/authorisation/resources/inbredset/models.py')
-rw-r--r--gn_auth/auth/authorisation/resources/inbredset/models.py49
1 files changed, 19 insertions, 30 deletions
diff --git a/gn_auth/auth/authorisation/resources/inbredset/models.py b/gn_auth/auth/authorisation/resources/inbredset/models.py
index 64d41e3..2626f3e 100644
--- a/gn_auth/auth/authorisation/resources/inbredset/models.py
+++ b/gn_auth/auth/authorisation/resources/inbredset/models.py
@@ -1,39 +1,12 @@
 """Functions to handle the low-level details regarding populations auth."""
 from uuid import UUID, uuid4
+from typing import Sequence, Optional
 
 import sqlite3
 
-from gn_auth.auth.errors import NotFoundError
+import gn_auth.auth.db.sqlite3 as db
 from gn_auth.auth.authentication.users import User
-from gn_auth.auth.authorisation.resources.groups.models import Group
-from gn_auth.auth.authorisation.resources.base import Resource, ResourceCategory
-from gn_auth.auth.authorisation.resources.models import (
-    create_resource as _create_resource)
-
-def create_resource(
-        cursor: sqlite3.Cursor,
-        resource_name: str,
-        user: User,
-        group: Group,
-        public: bool
-) -> Resource:
-    """Convenience function to create a resource of type 'inbredset-group'."""
-    cursor.execute("SELECT * FROM resource_categories "
-                   "WHERE resource_category_key='inbredset-group'")
-    category = cursor.fetchone()
-    if category:
-        return _create_resource(cursor,
-                                resource_name,
-                                ResourceCategory(
-                                    resource_category_id=UUID(
-                                        category["resource_category_id"]),
-                                    resource_category_key="inbredset-group",
-                                    resource_category_description=category[
-                                        "resource_category_description"]),
-                                user,
-                                group,
-                                public)
-    raise NotFoundError("Could not find a 'inbredset-group' resource category.")
+from gn_auth.auth.authorisation.resources.base import Resource
 
 
 def assign_inbredset_group_owner_role(
@@ -94,3 +67,19 @@ def link_data_to_resource(# pylint: disable=[too-many-arguments, too-many-positi
         "VALUES (:resource_id, :data_link_id)",
         params)
     return params
+
+
+def resource_data(
+        cursor: db.DbCursor,
+        resource_id: UUID,
+        offset: int = 0,
+        limit: Optional[int] = None) -> Sequence[sqlite3.Row]:
+    """Fetch data linked to a inbred-set resource"""
+    cursor.execute(
+        ("SELECT * FROM inbredset_group_resources AS igr "
+         "INNER JOIN linked_inbredset_groups AS lig "
+         "ON igr.data_link_id=lig.data_link_id "
+         "WHERE igr.resource_id=?") + (
+             f" LIMIT {limit} OFFSET {offset}" if bool(limit) else ""),
+        (str(resource_id),))
+    return cursor.fetchall()