about summary refs log tree commit diff
path: root/gn_auth/auth/authorisation
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-09-29 11:36:21 -0500
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-09-29 11:36:21 -0500
commit7ae019865d6b7cfd39aeddf14109ece29598bb78 (patch)
treeb9d65d3993e4fdca999f06636b5b6ce8fec919b7 /gn_auth/auth/authorisation
parent6e37dde5dadcc1609db81c212018c76d0891731c (diff)
downloadgn-auth-7ae019865d6b7cfd39aeddf14109ece29598bb78.tar.gz
Replace deprecated module and functions with newer versions.
Diffstat (limited to 'gn_auth/auth/authorisation')
-rw-r--r--gn_auth/auth/authorisation/resources/views.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py
index b8c7e24..b359a83 100644
--- a/gn_auth/auth/authorisation/resources/views.py
+++ b/gn_auth/auth/authorisation/resources/views.py
@@ -21,11 +21,11 @@ from flask import (request,
                    make_response,
                    current_app as app)
 import gn_libs.privileges.resources
+from gn_libs import sqlite3 as db
+from gn_libs.sqlite3 import with_db_connection
 
 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.jwks import newest_jwk, jwks_directory
 
 from gn_auth.auth.authorisation.roles import Role
@@ -225,7 +225,7 @@ def link_data():
                     form["dataset_type"],
                     tuple(UUID(dlinkid) for dlinkid in form["data_link_ids"]))
 
-            return jsonify(with_db_connection(__link__))
+            return jsonify(with_db_connection(app.config["AUTH_DB"], __link__))
     except AssertionError as aserr:
         raise InvalidData(aserr.args[0]) from aserr
 
@@ -245,7 +245,7 @@ def unlink_data():
                 return unlink_data_from_resource(
                     conn, the_token.user, UUID(form["resource_id"]),
                     UUID(form["data_link_id"]))
-            return jsonify(with_db_connection(__unlink__))
+            return jsonify(with_db_connection(app.config["AUTH_DB"], __unlink__))
     except AssertionError as aserr:
         raise InvalidData(aserr.args[0]) from aserr
 
@@ -307,7 +307,7 @@ def resource_users(resource_id: UUID):
                 "roles": tuple(asdict(role) for role in row["roles"])
             } for row in (
                 user_row for user_id, user_row
-                in with_db_connection(__the_users__).items()))
+                in with_db_connection(app.config["AUTH_DB"], __the_users__).items()))
         return jsonify(tuple(results))
 
 @resources.route("<uuid:resource_id>/user/assign", methods=["POST"])
@@ -348,7 +348,7 @@ def assign_role_to_user(resource_id: UUID) -> Response:
             user_id=str(_token.user.user_id)
         ).replace(str(_token.user.user_id), "<uuid:user_id>")
         return jsonify({
-            **with_db_connection(__assign__),
+            **with_db_connection(app.config["AUTH_DB"], __assign__),
             "DeprecationWarning": (
                 "This endpoint is deprecated and will be removed. Please use "
                 f"the {new_uri} endpoint.")})
@@ -390,7 +390,7 @@ def unassign_role_to_user(resource_id: UUID) -> Response:
             user_id=str(_token.user.user_id)
         ).replace(str(_token.user.user_id), "<uuid:user_id>")
         return jsonify({
-            **with_db_connection(__assign__),
+            **with_db_connection(app.config["AUTH_DB"], __assign__),
             "DeprecationWarning": (
                 "This endpoint is deprecated and will be removed. Please use "
                 f"the {new_uri} endpoint.")})
@@ -468,7 +468,7 @@ def toggle_public(resource_id: UUID) -> Response:
                 return new_resource
             return new_resource
 
-        resource = with_db_connection(__toggle__)
+        resource = with_db_connection(app.config["AUTH_DB"], __toggle__)
         return jsonify({
             "resource": asdict(resource),
             "description": (
@@ -506,7 +506,7 @@ def resource_roles(resource_id: UUID) -> Response:
 
             return assigned_to_user + user_created
 
-        return jsonify(with_db_connection(__roles__))
+        return jsonify(with_db_connection(app.config["AUTH_DB"], __roles__))
 
 
 @resources.route("/authorisation", methods=["POST"])
@@ -517,11 +517,13 @@ def resources_authorisation():
         assert (data and "resource-ids" in data)
         resource_ids = tuple(UUID(resid) for resid in data["resource-ids"])
         pubres = tuple(
-            res.resource_id for res in with_db_connection(public_resources)
+            res.resource_id for res in with_db_connection(
+                app.config["AUTH_DB"], public_resources)
             if res.resource_id in resource_ids)
         with require_oauth.acquire("profile resource") as the_token:
-            the_resources = with_db_connection(lambda conn: user_roles_on_resources(
-                conn, the_token.user, resource_ids))
+            the_resources = with_db_connection(
+                app.config["AUTH_DB"], lambda conn: user_roles_on_resources(
+                    conn, the_token.user, resource_ids))
             resp = jsonify({
                 str(resid): {
                     "public-read": resid in pubres,
@@ -561,7 +563,7 @@ def resources_authorisation():
 def get_user_roles_on_resource(name) -> Response:
     """Get user authorisation for a given resource given it's name"""
     resid = with_db_connection(
-        lambda conn: get_resource_id(conn, name)
+        app.config["AUTH_DB"], lambda conn: get_resource_id(conn, name)
     )
     def _extract_privilege_id(privileges):
         return tuple(
@@ -570,6 +572,7 @@ def get_user_roles_on_resource(name) -> Response:
 
     with require_oauth.acquire("profile resource") as _token:
         resources_ = with_db_connection(
+            app.config["AUTH_DB"],
             lambda conn: user_roles_on_resources(
                 conn, _token.user, (resid,)
             )