about summary refs log tree commit diff
path: root/gn_auth/auth/authorisation
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2026-08-27 10:51:16 -0500
committerFrederick Muriuki Muriithi2026-08-27 12:51:31 -0500
commit800913ddee45fcb0b0e3a9d8c3917d3cf9644ca4 (patch)
tree30b78dca5002899cce2d2f875bffe70a74933c87 /gn_auth/auth/authorisation
parentc9d6594750ad7a01b1e23af77e4f847e23f26306 (diff)
downloadgn-auth-800913ddee45fcb0b0e3a9d8c3917d3cf9644ca4.tar.gz
Cleanup deprecation warnings: Switch to gn_libs.sqlite3
The gn_auth.auth.db.sqlite3 module is deprecated and should be
removed. This cleanup goes a ways towards that goal.
Diffstat (limited to 'gn_auth/auth/authorisation')
-rw-r--r--gn_auth/auth/authorisation/checks.py2
-rw-r--r--gn_auth/auth/authorisation/data/genotypes.py3
-rw-r--r--gn_auth/auth/authorisation/data/mrna.py3
-rw-r--r--gn_auth/auth/authorisation/data/views.py10
-rw-r--r--gn_auth/auth/authorisation/privileges/models.py2
-rw-r--r--gn_auth/auth/authorisation/resources/checks.py13
-rw-r--r--gn_auth/auth/authorisation/resources/groups/models.py2
-rw-r--r--gn_auth/auth/authorisation/roles/models.py2
-rw-r--r--gn_auth/auth/authorisation/users/views.py9
9 files changed, 23 insertions, 23 deletions
diff --git a/gn_auth/auth/authorisation/checks.py b/gn_auth/auth/authorisation/checks.py
index 66bb723..15d4b99 100644
--- a/gn_auth/auth/authorisation/checks.py
+++ b/gn_auth/auth/authorisation/checks.py
@@ -2,12 +2,12 @@
 from functools import wraps
 from typing import Callable
 
+from gn_libs import sqlite3 as db
 from flask import request, current_app as app
 
 from gn_auth.auth.errors import InvalidData, AuthorisationError
 
 from . import privileges as auth_privs
-from ..db import sqlite3 as db
 from ..authentication.oauth2.resource_server import require_oauth
 
 def __system_privileges_in_roles__(conn, user): # TODO: Remove this hack.
diff --git a/gn_auth/auth/authorisation/data/genotypes.py b/gn_auth/auth/authorisation/data/genotypes.py
index b6f0464..d5af3ae 100644
--- a/gn_auth/auth/authorisation/data/genotypes.py
+++ b/gn_auth/auth/authorisation/data/genotypes.py
@@ -6,10 +6,9 @@ from functools import reduce
 from dataclasses import asdict
 
 from gn_libs import mysqldb as gn3db
+from gn_libs import sqlite3 as authdb
 from MySQLdb.cursors import DictCursor
 
-from gn_auth.auth.db import sqlite3 as authdb
-
 from gn_auth.auth.authorisation.checks import authorised_p
 from gn_auth.auth.authorisation.resources.groups.models import Group
 
diff --git a/gn_auth/auth/authorisation/data/mrna.py b/gn_auth/auth/authorisation/data/mrna.py
index 7cced10..dd589e0 100644
--- a/gn_auth/auth/authorisation/data/mrna.py
+++ b/gn_auth/auth/authorisation/data/mrna.py
@@ -6,10 +6,9 @@ from functools import reduce
 from dataclasses import asdict
 
 from gn_libs import mysqldb as gn3db
+from gn_libs import sqlite3 as authdb
 from MySQLdb.cursors import DictCursor
 
-from gn_auth.auth.db import sqlite3 as authdb
-
 from gn_auth.auth.authorisation.checks import authorised_p
 from gn_auth.auth.authorisation.resources.groups.models import Group
 
diff --git a/gn_auth/auth/authorisation/data/views.py b/gn_auth/auth/authorisation/data/views.py
index 1184d63..0ffc08e 100644
--- a/gn_auth/auth/authorisation/data/views.py
+++ b/gn_auth/auth/authorisation/data/views.py
@@ -14,6 +14,7 @@ from flask import request, jsonify, Response, Blueprint, current_app as app
 
 from gn_libs import mysqldb as gn3db
 from gn_libs import sqlite3 as db
+from gn_libs.sqlite3 import with_db_connection
 
 from gn_auth import jobs
 from gn_auth.commands import run_async_cmd
@@ -22,8 +23,6 @@ from gn_auth.auth.requests import request_json
 from gn_auth.auth.errors import InvalidData, NotFoundError
 from gn_auth.auth.authorisation.resources.groups.models import group_by_id
 
-from gn_auth.auth.db.sqlite3 import with_db_connection # Replace this with gn_libs alternative
-
 from ..checks import require_json
 
 from ...authentication.users import User
@@ -207,7 +206,7 @@ def __search_mrna__():
             ungrouped_mrna_data, gn3conn=gn3conn, search_query=query,
             selected=__request_key_list__("selected"),
             limit=limit, offset=offset)
-        return jsonify(with_db_connection(__ungrouped__))
+        return jsonify(with_db_connection(app.config["SQL_URI"], __ungrouped__))
 
 def __request_key__(key: str, default: Any = ""):
     if bool(request_json()):
@@ -232,7 +231,7 @@ def __search_genotypes__():
             ungrouped_genotype_data, gn3conn=gn3conn, search_query=query,
             selected=__request_key_list__("selected"),
             limit=limit, offset=offset)
-        return jsonify(with_db_connection(__ungrouped__))
+        return jsonify(with_db_connection(app.config["SQL_URI"], __ungrouped__))
 
 def __search_phenotypes__():
     # launch the external process to search for phenotypes
@@ -307,6 +306,7 @@ def link_genotypes() -> Response:
         return link_genotype_data(conn, group_by_id(conn, group_id), datasets)
 
     return jsonify(with_db_connection(
+        app.config["SQL_URI"],
         partial(__link__, **__values__(request_json()))))
 
 @data.route("/link/mrna", methods=["POST"])
@@ -332,6 +332,7 @@ def link_mrna() -> Response:
         return link_mrna_data(conn, group_by_id(conn, group_id), datasets)
 
     return jsonify(with_db_connection(
+        app.config["SQL_URI"],
         partial(__link__, **__values__(request_json()))))
 
 @data.route("/link/phenotype", methods=["POST"])
@@ -374,4 +375,5 @@ def link_phenotype() -> Response:
                                        pheno_traits_from_db(gn3conn, traits))
 
         return jsonify(with_db_connection(
+            app.config["SQL_URI"],
             partial(__link__, **__values__(request_json()))))
diff --git a/gn_auth/auth/authorisation/privileges/models.py b/gn_auth/auth/authorisation/privileges/models.py
index 77be7c0..cd23a0c 100644
--- a/gn_auth/auth/authorisation/privileges/models.py
+++ b/gn_auth/auth/authorisation/privileges/models.py
@@ -3,8 +3,8 @@ from dataclasses import dataclass
 from typing import Iterable, Optional
 
 import sqlite3
+from gn_libs import sqlite3 as db
 
-from gn_auth.auth.db import sqlite3 as db
 from gn_auth.auth.authentication.users import User
 
 
diff --git a/gn_auth/auth/authorisation/resources/checks.py b/gn_auth/auth/authorisation/resources/checks.py
index 252df2f..6dfd388 100644
--- a/gn_auth/auth/authorisation/resources/checks.py
+++ b/gn_auth/auth/authorisation/resources/checks.py
@@ -11,7 +11,6 @@ from gn_libs.privileges import check
 from .base import Resource
 from .system.models import system_resource
 
-from ...db import sqlite3 as db
 from ...authentication.users import User
 
 from ..privileges.models import db_row_to_privilege
@@ -31,7 +30,7 @@ def __organise_privileges_by_resource_id__(rows):
     return reduce(__organise__, rows, {})
 
 
-def authorised_for(conn: db.DbConnection,
+def authorised_for(conn: authdb.DbConnection,
                    user: User,
                    privileges: tuple[str, ...],
                    resource_ids: Sequence[uuid.UUID]) -> dict[uuid.UUID, bool]:
@@ -42,7 +41,7 @@ def authorised_for(conn: db.DbConnection,
     warnings.warn(DeprecationWarning(
         f"The function `{__name__}.authorised_for` is deprecated. Please use "
         f"`{__name__}.authorised_for_spec`"))
-    with db.cursor(conn) as cursor:
+    with authdb.cursor(conn) as cursor:
         cursor.execute(
             ("SELECT ur.*, rp.privilege_id FROM "
              "user_roles AS ur "
@@ -66,7 +65,7 @@ def authorised_for(conn: db.DbConnection,
 
 
 def authorised_for2(
-        conn: db.DbConnection,
+        conn: authdb.DbConnection,
         user: User,
         resource: Resource,
         privileges: tuple[str, ...]
@@ -77,7 +76,7 @@ def authorised_for2(
     warnings.warn(DeprecationWarning(
         f"The function `{__name__}.authorised_for2` is deprecated. Please use "
         f"`{__name__}.authorised_for_spec`"))
-    with db.cursor(conn) as cursor:
+    with authdb.cursor(conn) as cursor:
         _query = (
             "SELECT resources.resource_id, user_roles.user_id, roles.role_id, "
             "privileges.* "
@@ -101,7 +100,7 @@ def authorised_for2(
 
 
 def authorised_for_spec(
-        conn: db.DbConnection,
+        conn: authdb.DbConnection,
         user_id: uuid.UUID,
         resource_id: uuid.UUID,
         auth_spec: str
@@ -110,7 +109,7 @@ def authorised_for_spec(
     Check that a user, identified with `user_id`, has a set of privileges that
     satisfy the `auth_spec` for the resource identified with `resource_id`.
     """
-    with db.cursor(conn) as cursor:
+    with authdb.cursor(conn) as cursor:
         _query = (
             "SELECT resources.resource_id, user_roles.user_id, roles.role_id, "
             "privileges.* "
diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py
index 60d4634..79bead4 100644
--- a/gn_auth/auth/authorisation/resources/groups/models.py
+++ b/gn_auth/auth/authorisation/resources/groups/models.py
@@ -11,8 +11,8 @@ from flask import g
 from pymonad.maybe import Just, Maybe, Nothing
 from pymonad.either import Left, Right, Either
 from pymonad.tools import monad_from_none_or_value
+from gn_libs import sqlite3 as db
 
-from gn_auth.auth.db import sqlite3 as db
 from gn_auth.auth.authentication.users import User, user_by_id
 
 from gn_auth.auth.authorisation.checks import authorised_p
diff --git a/gn_auth/auth/authorisation/roles/models.py b/gn_auth/auth/authorisation/roles/models.py
index 89403f8..89556a6 100644
--- a/gn_auth/auth/authorisation/roles/models.py
+++ b/gn_auth/auth/authorisation/roles/models.py
@@ -4,12 +4,12 @@ from functools import reduce
 from dataclasses import dataclass
 from typing import Sequence, Iterable, Optional
 
+from gn_libs import sqlite3 as db
 from pymonad.either import Left, Right, Either
 
 from gn_auth.auth.errors import NotFoundError, AuthorisationError
 from gn_auth.auth.authorisation.resources.base import Resource
 
-from ...db import sqlite3 as db
 from ...authentication.users import User
 
 from ..checks import authorised_p
diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py
index 5cdb482..e454a80 100644
--- a/gn_auth/auth/authorisation/users/views.py
+++ b/gn_auth/auth/authorisation/users/views.py
@@ -23,6 +23,8 @@ from flask import (
     make_response,
     render_template)
 
+from gn_libs import sqlite3 as db
+from gn_libs.sqlite3 import with_db_connection
 from gn_libs.privileges.system import can_create_or_delete_user
 from gn_libs.privileges.resources import can_assign_role
 
@@ -30,8 +32,6 @@ from gn_auth.smtp import send_message, build_email_message
 
 from gn_auth.auth.requests import request_json
 
-from gn_auth.auth.db import sqlite3 as db
-from gn_auth.auth.db.sqlite3 import with_db_connection
 
 from gn_auth.auth.authorisation.resources.system.models import (
     system_resource,
@@ -366,8 +366,9 @@ def user_join_request_exists():
             "exists": False
         }
     with require_oauth.acquire("profile group") as the_token:
-        return jsonify(with_db_connection(partial(
-            __request_exists__, user=the_token.user)))
+        return jsonify(with_db_connection(
+            current_app.config["SQL_URI"],
+            partial(__request_exists__, user=the_token.user)))
 
 @users.route("/list", methods=["GET"])
 @require_oauth("profile user")