about summary refs log tree commit diff
path: root/gn3/auth/authorisation/data/mrna.py
diff options
context:
space:
mode:
authorJohn Nduli2024-10-18 15:06:34 +0300
committerFrederick Muriuki Muriithi2024-10-18 09:07:16 -0500
commit1aeb61f50567e2400c3cc1a18eeef1e59bdc68ac (patch)
tree7a4624659f735980345cf10aae101f9e6ec94deb /gn3/auth/authorisation/data/mrna.py
parent0820295202c2fe747c05b93ce0f1c5a604442f69 (diff)
downloadgenenetwork3-1aeb61f50567e2400c3cc1a18eeef1e59bdc68ac.tar.gz
refactor: remove unused gn3.auth modules
Diffstat (limited to 'gn3/auth/authorisation/data/mrna.py')
-rw-r--r--gn3/auth/authorisation/data/mrna.py100
1 files changed, 0 insertions, 100 deletions
diff --git a/gn3/auth/authorisation/data/mrna.py b/gn3/auth/authorisation/data/mrna.py
deleted file mode 100644
index bdfc5c1..0000000
--- a/gn3/auth/authorisation/data/mrna.py
+++ /dev/null
@@ -1,100 +0,0 @@
-"""Handle linking of mRNA Assay data to the Auth(entic|oris)ation system."""
-import uuid
-from typing import Iterable
-from MySQLdb.cursors import DictCursor
-
-import gn3.auth.db as authdb
-import gn3.db_utils as gn3db
-from gn3.auth.dictify import dictify
-from gn3.auth.authorisation.checks import authorised_p
-from gn3.auth.authorisation.groups.models import Group
-
-def linked_mrna_data(conn: authdb.DbConnection) -> Iterable[dict]:
-    """Retrieve mRNA Assay data that is linked to user groups."""
-    with authdb.cursor(conn) as cursor:
-        cursor.execute("SELECT * FROM linked_mrna_data")
-        return (dict(row) for row in cursor.fetchall())
-
-@authorised_p(("system:data:link-to-group",),
-              error_description=(
-                  "You do not have sufficient privileges to link data to (a) "
-                  "group(s)."),
-              oauth2_scope="profile group resource")
-def ungrouped_mrna_data(# pylint: disable=[too-many-arguments]
-        authconn: authdb.DbConnection, gn3conn: gn3db.Connection,
-        search_query: str, selected: tuple[dict, ...] = tuple(),
-        limit: int = 10000, offset: int = 0) -> tuple[
-            dict, ...]:
-    """Retrieve mrna data that is not linked to any user group."""
-    params = tuple(
-        (row["SpeciesId"], row["InbredSetId"], row["ProbeFreezeId"],
-         row["ProbeSetFreezeId"])
-        for row in linked_mrna_data(authconn)) + tuple(
-                (row["SpeciesId"], row["InbredSetId"], row["ProbeFreezeId"],
-                 row["ProbeSetFreezeId"])
-                for row in selected)
-    query = (
-        "SELECT s.SpeciesId, iset.InbredSetId, iset.InbredSetName, "
-        "pf.ProbeFreezeId, pf.Name AS StudyName, psf.Id AS ProbeSetFreezeId, "
-        "psf.Name AS dataset_name, psf.FullName AS dataset_fullname, "
-        "psf.ShortName AS dataset_shortname "
-        "FROM Species AS s INNER JOIN InbredSet AS iset "
-        "ON s.SpeciesId=iset.SpeciesId INNER JOIN ProbeFreeze AS pf "
-        "ON iset.InbredSetId=pf.InbredSetId INNER JOIN ProbeSetFreeze AS psf "
-        "ON pf.ProbeFreezeId=psf.ProbeFreezeId ") + (
-            "WHERE " if (len(params) > 0 or bool(search_query)) else "")
-
-    if len(params) > 0:
-        paramstr = ", ".join(["(%s, %s, %s, %s)"] * len(params))
-        query = query + (
-            "(s.SpeciesId, iset.InbredSetId, pf.ProbeFreezeId, psf.Id) "
-            f"NOT IN ({paramstr}) "
-            ) + ("AND " if bool(search_query) else "")
-
-    if bool(search_query):
-        query = query + (
-            "CONCAT(pf.Name, psf.Name, ' ', psf.FullName, ' ', psf.ShortName) "
-            "LIKE %s ")
-        params = params + ((f"%{search_query}%",),)# type: ignore[operator]
-
-    query = query + f"LIMIT {int(limit)} OFFSET {int(offset)}"
-    with gn3conn.cursor(DictCursor) as cursor:
-        cursor.execute(
-            query, tuple(item for sublist in params for item in sublist))
-        return tuple(row for row in cursor.fetchall())
-
-@authorised_p(
-    ("system:data:link-to-group",),
-    error_description=(
-        "You do not have sufficient privileges to link data to (a) "
-        "group(s)."),
-    oauth2_scope="profile group resource")
-def link_mrna_data(
-        conn: authdb.DbConnection, group: Group, datasets: dict) -> dict:
-    """Link genotye `datasets` to `group`."""
-    with authdb.cursor(conn) as cursor:
-        cursor.executemany(
-            "INSERT INTO linked_mrna_data VALUES "
-            "(:data_link_id, :group_id, :SpeciesId, :InbredSetId, "
-            ":ProbeFreezeId, :ProbeSetFreezeId, :dataset_name, "
-            ":dataset_fullname, :dataset_shortname) "
-            "ON CONFLICT "
-            "(SpeciesId, InbredSetId, ProbeFreezeId, ProbeSetFreezeId) "
-            "DO NOTHING",
-            tuple({
-                "data_link_id": str(uuid.uuid4()),
-                "group_id": str(group.group_id),
-                **{
-                    key: value for key,value in dataset.items() if key in (
-                        "SpeciesId", "InbredSetId", "ProbeFreezeId",
-                        "ProbeSetFreezeId", "dataset_fullname", "dataset_name",
-                        "dataset_shortname")
-                }
-            } for dataset in datasets))
-        return {
-            "description": (
-                f"Successfully linked {len(datasets)} to group "
-                f"'{group.group_name}'."),
-            "group": dictify(group),
-            "datasets": datasets
-        }