From 6d9c61dc0072b96b12153e64940b465306f25bfb Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 7 Aug 2023 07:58:09 +0300 Subject: Change imports to new unified db module. --- .../authentication/oauth2/endpoints/revocation.py | 2 +- .../authentication/oauth2/endpoints/utilities.py | 2 +- .../oauth2/grants/authorisation_code_grant.py | 4 +- .../authentication/oauth2/grants/password_grant.py | 2 +- .../oauth2/models/authorization_code.py | 2 +- .../authentication/oauth2/models/oauth2client.py | 2 +- .../authentication/oauth2/models/oauth2token.py | 2 +- .../auth/authentication/oauth2/resource_server.py | 2 +- gn_auth/auth/authentication/oauth2/server.py | 2 +- gn_auth/auth/authentication/oauth2/views.py | 4 +- gn_auth/auth/authentication/users.py | 2 +- gn_auth/auth/authorisation/checks.py | 2 +- gn_auth/auth/authorisation/data/genotypes.py | 4 +- gn_auth/auth/authorisation/data/mrna.py | 4 +- gn_auth/auth/authorisation/data/phenotypes.py | 10 +-- gn_auth/auth/authorisation/data/views.py | 6 +- gn_auth/auth/authorisation/groups/data.py | 14 ++-- gn_auth/auth/authorisation/groups/models.py | 2 +- gn_auth/auth/authorisation/groups/views.py | 8 +-- gn_auth/auth/authorisation/privileges.py | 2 +- gn_auth/auth/authorisation/resources/checks.py | 2 +- gn_auth/auth/authorisation/resources/models.py | 4 +- gn_auth/auth/authorisation/resources/views.py | 2 +- gn_auth/auth/authorisation/roles/models.py | 2 +- gn_auth/auth/authorisation/roles/views.py | 2 +- gn_auth/auth/authorisation/users/admin/ui.py | 2 +- gn_auth/auth/authorisation/users/admin/views.py | 4 +- .../auth/authorisation/users/collections/views.py | 4 +- .../auth/authorisation/users/masquerade/models.py | 2 +- .../auth/authorisation/users/masquerade/views.py | 2 +- gn_auth/auth/authorisation/users/models.py | 2 +- gn_auth/auth/authorisation/users/views.py | 4 +- gn_auth/templates/admin/dashboard.html | 24 +++++++ gn_auth/templates/admin/list-oauth2-clients.html | 56 ++++++++++++++++ gn_auth/templates/admin/login.html | 32 +++++++++ gn_auth/templates/admin/register-client.html | 78 ++++++++++++++++++++++ gn_auth/templates/admin/registered-client.html | 21 ++++++ gn_auth/templates/admin/view-oauth2-client.html | 75 +++++++++++++++++++++ gn_auth/templates/base.html | 24 +++++++ gn_auth/templates/common-macros.html | 7 ++ gn_auth/templates/oauth2/authorise-user.html | 48 +++++++++++++ gn_auth/templates/oauth2/oauth2_error.html | 16 +++++ main.py | 2 +- tests/unit/auth/fixtures/group_fixtures.py | 2 +- tests/unit/auth/fixtures/migration_fixtures.py | 2 +- tests/unit/auth/fixtures/oauth2_client_fixtures.py | 2 +- tests/unit/auth/fixtures/resource_fixtures.py | 2 +- tests/unit/auth/fixtures/role_fixtures.py | 2 +- tests/unit/auth/fixtures/user_fixtures.py | 2 +- tests/unit/auth/test_credentials.py | 2 +- tests/unit/auth/test_groups.py | 2 +- .../unit/auth/test_migrations_add_data_to_table.py | 2 +- .../auth/test_migrations_add_remove_columns.py | 2 +- tests/unit/auth/test_migrations_create_tables.py | 2 +- tests/unit/auth/test_migrations_drop_tables.py | 2 +- tests/unit/auth/test_migrations_indexes.py | 2 +- ...tions_init_data_in_resource_categories_table.py | 2 +- tests/unit/auth/test_privileges.py | 2 +- tests/unit/auth/test_resources.py | 2 +- tests/unit/auth/test_roles.py | 2 +- tests/unit/auth/test_token.py | 2 +- 61 files changed, 455 insertions(+), 74 deletions(-) create mode 100644 gn_auth/templates/admin/dashboard.html create mode 100644 gn_auth/templates/admin/list-oauth2-clients.html create mode 100644 gn_auth/templates/admin/login.html create mode 100644 gn_auth/templates/admin/register-client.html create mode 100644 gn_auth/templates/admin/registered-client.html create mode 100644 gn_auth/templates/admin/view-oauth2-client.html create mode 100644 gn_auth/templates/base.html create mode 100644 gn_auth/templates/common-macros.html create mode 100644 gn_auth/templates/oauth2/authorise-user.html create mode 100644 gn_auth/templates/oauth2/oauth2_error.html diff --git a/gn_auth/auth/authentication/oauth2/endpoints/revocation.py b/gn_auth/auth/authentication/oauth2/endpoints/revocation.py index ad9e67c..240ca30 100644 --- a/gn_auth/auth/authentication/oauth2/endpoints/revocation.py +++ b/gn_auth/auth/authentication/oauth2/endpoints/revocation.py @@ -3,7 +3,7 @@ from flask import current_app from authlib.oauth2.rfc7009 import RevocationEndpoint as _RevocationEndpoint -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.oauth2.models.oauth2token import ( save_token, OAuth2Token, revoke_token) diff --git a/gn_auth/auth/authentication/oauth2/endpoints/utilities.py b/gn_auth/auth/authentication/oauth2/endpoints/utilities.py index d32f9b3..29ace7c 100644 --- a/gn_auth/auth/authentication/oauth2/endpoints/utilities.py +++ b/gn_auth/auth/authentication/oauth2/endpoints/utilities.py @@ -4,7 +4,7 @@ from typing import Any, Optional from flask import current_app from pymonad.maybe import Nothing -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.oauth2.models.oauth2token import ( OAuth2Token, token_by_access_token, token_by_refresh_token) diff --git a/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py b/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py index 6d8112e..e866c41 100644 --- a/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py +++ b/gn_auth/auth/authentication/oauth2/grants/authorisation_code_grant.py @@ -9,8 +9,8 @@ from flask import current_app as app from authlib.oauth2.rfc6749 import grants from authlib.oauth2.rfc7636 import create_s256_code_challenge -from gn_auth.auth import db -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db import sqlite3 as db +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authentication.users import User from ..models.oauth2client import OAuth2Client diff --git a/gn_auth/auth/authentication/oauth2/grants/password_grant.py b/gn_auth/auth/authentication/oauth2/grants/password_grant.py index 75fc122..79382fd 100644 --- a/gn_auth/auth/authentication/oauth2/grants/password_grant.py +++ b/gn_auth/auth/authentication/oauth2/grants/password_grant.py @@ -3,7 +3,7 @@ from flask import current_app as app from authlib.oauth2.rfc6749 import grants -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import valid_login, user_by_email from gn_auth.auth.authorisation.errors import NotFoundError diff --git a/gn_auth/auth/authentication/oauth2/models/authorization_code.py b/gn_auth/auth/authentication/oauth2/models/authorization_code.py index 98b5d0f..6c586f3 100644 --- a/gn_auth/auth/authentication/oauth2/models/authorization_code.py +++ b/gn_auth/auth/authentication/oauth2/models/authorization_code.py @@ -5,7 +5,7 @@ from typing import NamedTuple from pymonad.maybe import Just, Maybe, Nothing -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from .oauth2client import OAuth2Client diff --git a/gn_auth/auth/authentication/oauth2/models/oauth2client.py b/gn_auth/auth/authentication/oauth2/models/oauth2client.py index 07618dd..ea86772 100644 --- a/gn_auth/auth/authentication/oauth2/models/oauth2client.py +++ b/gn_auth/auth/authentication/oauth2/models/oauth2client.py @@ -6,7 +6,7 @@ from typing import Sequence, Optional, NamedTuple from pymonad.maybe import Just, Maybe, Nothing -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import User, users, user_by_id, same_password from gn_auth.auth.authorisation.errors import NotFoundError diff --git a/gn_auth/auth/authentication/oauth2/models/oauth2token.py b/gn_auth/auth/authentication/oauth2/models/oauth2token.py index 725c096..6f9dc12 100644 --- a/gn_auth/auth/authentication/oauth2/models/oauth2token.py +++ b/gn_auth/auth/authentication/oauth2/models/oauth2token.py @@ -5,7 +5,7 @@ from typing import NamedTuple, Optional from pymonad.maybe import Just, Maybe, Nothing -from gn_auth.auth import 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.errors import NotFoundError diff --git a/gn_auth/auth/authentication/oauth2/resource_server.py b/gn_auth/auth/authentication/oauth2/resource_server.py index 32c463f..c062b28 100644 --- a/gn_auth/auth/authentication/oauth2/resource_server.py +++ b/gn_auth/auth/authentication/oauth2/resource_server.py @@ -4,7 +4,7 @@ from flask import current_app as app from authlib.oauth2.rfc6750 import BearerTokenValidator as _BearerTokenValidator from authlib.integrations.flask_oauth2 import ResourceProtector -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.oauth2.models.oauth2token import token_by_access_token class BearerTokenValidator(_BearerTokenValidator): diff --git a/gn_auth/auth/authentication/oauth2/server.py b/gn_auth/auth/authentication/oauth2/server.py index b085219..12366a6 100644 --- a/gn_auth/auth/authentication/oauth2/server.py +++ b/gn_auth/auth/authentication/oauth2/server.py @@ -8,7 +8,7 @@ from authlib.oauth2.rfc6749.errors import InvalidClientError from authlib.integrations.flask_oauth2 import AuthorizationServer # from authlib.oauth2.rfc7636 import CodeChallenge -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from .models.oauth2client import client from .models.oauth2token import OAuth2Token, save_token diff --git a/gn_auth/auth/authentication/oauth2/views.py b/gn_auth/auth/authentication/oauth2/views.py index 43d9e49..ac74739 100644 --- a/gn_auth/auth/authentication/oauth2/views.py +++ b/gn_auth/auth/authentication/oauth2/views.py @@ -14,8 +14,8 @@ from flask import ( render_template, current_app as app) -from gn_auth.auth import db -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db import sqlite3 as db +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authorisation.errors import ForbiddenAccess from .resource_server import require_oauth diff --git a/gn_auth/auth/authentication/users.py b/gn_auth/auth/authentication/users.py index 327820e..46cd838 100644 --- a/gn_auth/auth/authentication/users.py +++ b/gn_auth/auth/authentication/users.py @@ -5,7 +5,7 @@ from typing import Any, Tuple, NamedTuple from argon2 import PasswordHasher from argon2.exceptions import VerifyMismatchError -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.errors import NotFoundError class User(NamedTuple): diff --git a/gn_auth/auth/authorisation/checks.py b/gn_auth/auth/authorisation/checks.py index 02c6810..46a51fe 100644 --- a/gn_auth/auth/authorisation/checks.py +++ b/gn_auth/auth/authorisation/checks.py @@ -4,7 +4,7 @@ from typing import Callable from flask import request, current_app as app -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from . import privileges as auth_privs from .errors import InvalidData, AuthorisationError diff --git a/gn_auth/auth/authorisation/data/genotypes.py b/gn_auth/auth/authorisation/data/genotypes.py index 41822a1..61963a6 100644 --- a/gn_auth/auth/authorisation/data/genotypes.py +++ b/gn_auth/auth/authorisation/data/genotypes.py @@ -5,7 +5,7 @@ from typing import Iterable from MySQLdb.cursors import DictCursor import gn_auth.auth.db as authdb -import gn_auth.db_utils as gn3db +import gn_auth.auth.db.mariadb as gn3db from gn_auth.auth.dictify import dictify from gn_auth.auth.authorisation.checks import authorised_p from gn_auth.auth.authorisation.groups.models import Group @@ -22,7 +22,7 @@ def linked_genotype_data(conn: authdb.DbConnection) -> Iterable[dict]: "group(s)."), oauth2_scope="profile group resource") def ungrouped_genotype_data(# pylint: disable=[too-many-arguments] - authconn: authdb.DbConnection, gn3conn: gn3db.Connection, + authconn: authdb.DbConnection, gn3conn: gn3db.DbConnection, search_query: str, selected: tuple[dict, ...] = tuple(), limit: int = 10000, offset: int = 0) -> tuple[ dict, ...]: diff --git a/gn_auth/auth/authorisation/data/mrna.py b/gn_auth/auth/authorisation/data/mrna.py index 0b08571..79ea7c0 100644 --- a/gn_auth/auth/authorisation/data/mrna.py +++ b/gn_auth/auth/authorisation/data/mrna.py @@ -4,7 +4,7 @@ from typing import Iterable from MySQLdb.cursors import DictCursor import gn_auth.auth.db as authdb -import gn_auth.db_utils as gn3db +import gn_auth.auth.db.mariadb as gn3db from gn_auth.auth.dictify import dictify from gn_auth.auth.authorisation.checks import authorised_p from gn_auth.auth.authorisation.groups.models import Group @@ -21,7 +21,7 @@ def linked_mrna_data(conn: authdb.DbConnection) -> Iterable[dict]: "group(s)."), oauth2_scope="profile group resource") def ungrouped_mrna_data(# pylint: disable=[too-many-arguments] - authconn: authdb.DbConnection, gn3conn: gn3db.Connection, + authconn: authdb.DbConnection, gn3conn: gn3db.DbConnection, search_query: str, selected: tuple[dict, ...] = tuple(), limit: int = 10000, offset: int = 0) -> tuple[ dict, ...]: diff --git a/gn_auth/auth/authorisation/data/phenotypes.py b/gn_auth/auth/authorisation/data/phenotypes.py index 2f4c564..d3cc33a 100644 --- a/gn_auth/auth/authorisation/data/phenotypes.py +++ b/gn_auth/auth/authorisation/data/phenotypes.py @@ -5,13 +5,13 @@ from typing import Any, Iterable from MySQLdb.cursors import DictCursor import gn_auth.auth.db as authdb -import gn_auth.db_utils as gn3db +import gn_auth.auth.db.mariadb as gn3db from gn_auth.auth.dictify import dictify from gn_auth.auth.authorisation.checks import authorised_p from gn_auth.auth.authorisation.groups.models import Group def linked_phenotype_data( - authconn: authdb.DbConnection, gn3conn: gn3db.Connection, + authconn: authdb.DbConnection, gn3conn: gn3db.DbConnection, species: str = "") -> Iterable[dict[str, Any]]: """Retrieve phenotype data linked to user groups.""" authkeys = ("SpeciesId", "InbredSetId", "PublishFreezeId", "PublishXRefId") @@ -52,7 +52,7 @@ def linked_phenotype_data( "group(s)."), oauth2_scope="profile group resource") def ungrouped_phenotype_data( - authconn: authdb.DbConnection, gn3conn: gn3db.Connection): + authconn: authdb.DbConnection, gn3conn: gn3db.DbConnection): """Retrieve phenotype data that is not linked to any user group.""" with gn3conn.cursor() as cursor: params = tuple( @@ -82,7 +82,7 @@ def ungrouped_phenotype_data( return tuple() -def __traits__(gn3conn: gn3db.Connection, params: tuple[dict, ...]) -> tuple[dict, ...]: +def __traits__(gn3conn: gn3db.DbConnection, params: tuple[dict, ...]) -> tuple[dict, ...]: """An internal utility function. Don't use outside of this module.""" if len(params) < 1: return tuple() @@ -115,7 +115,7 @@ def __traits__(gn3conn: gn3db.Connection, params: tuple[dict, ...]) -> tuple[dic "group(s)."), oauth2_scope="profile group resource") def link_phenotype_data( - authconn:authdb.DbConnection, gn3conn: gn3db.Connection, group: Group, + authconn:authdb.DbConnection, gn3conn: gn3db.DbConnection, group: Group, traits: tuple[dict, ...]) -> dict: """Link phenotype traits to a user group.""" with authdb.cursor(authconn) as cursor: diff --git a/gn_auth/auth/authorisation/data/views.py b/gn_auth/auth/authorisation/data/views.py index a25e9a2..9e55dd8 100644 --- a/gn_auth/auth/authorisation/data/views.py +++ b/gn_auth/auth/authorisation/data/views.py @@ -10,13 +10,13 @@ from MySQLdb.cursors import DictCursor from authlib.integrations.flask_oauth2.errors import _HTTPException from flask import request, jsonify, Response, Blueprint, current_app as app -import gn_auth.db_utils as gn3db +import gn_auth.auth.db.mariadb as gn3db from gn_auth import jobs from gn_auth.commands import run_async_cmd from gn_auth.db.traits import build_trait_name -from gn_auth.auth import db -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db import sqlite3 as db +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authorisation.checks import require_json from gn_auth.auth.authorisation.errors import InvalidData, NotFoundError diff --git a/gn_auth/auth/authorisation/groups/data.py b/gn_auth/auth/authorisation/groups/data.py index d05747b..2d9ddb5 100644 --- a/gn_auth/auth/authorisation/groups/data.py +++ b/gn_auth/auth/authorisation/groups/data.py @@ -1,14 +1,14 @@ """Handles the resource objects' data.""" from MySQLdb.cursors import DictCursor -from gn_auth import db_utils as gn3db -from gn_auth.auth import db as authdb +from gn_auth.auth.db import mariadb as gn3db +from gn_auth.auth.db import sqlite3 as authdb from gn_auth.auth.authorisation.groups import Group from gn_auth.auth.authorisation.checks import authorised_p from gn_auth.auth.authorisation.errors import NotFoundError def __fetch_mrna_data_by_ids__( - conn: gn3db.Connection, dataset_ids: tuple[str, ...]) -> tuple[ + conn: gn3db.DbConnection, dataset_ids: tuple[str, ...]) -> tuple[ dict, ...]: """Fetch mRNA Assay data by ID.""" with conn.cursor(DictCursor) as cursor: @@ -26,7 +26,7 @@ def __fetch_mrna_data_by_ids__( raise NotFoundError("Could not find mRNA Assay data with the given ID.") def __fetch_geno_data_by_ids__( - conn: gn3db.Connection, dataset_ids: tuple[str, ...]) -> tuple[ + conn: gn3db.DbConnection, dataset_ids: tuple[str, ...]) -> tuple[ dict, ...]: """Fetch genotype data by ID.""" with conn.cursor(DictCursor) as cursor: @@ -44,7 +44,7 @@ def __fetch_geno_data_by_ids__( raise NotFoundError("Could not find Genotype data with the given ID.") def __fetch_pheno_data_by_ids__( - conn: gn3db.Connection, dataset_ids: tuple[str, ...]) -> tuple[ + conn: gn3db.DbConnection, dataset_ids: tuple[str, ...]) -> tuple[ dict, ...]: """Fetch phenotype data by ID.""" with conn.cursor(DictCursor) as cursor: @@ -66,7 +66,7 @@ def __fetch_pheno_data_by_ids__( "Could not find Phenotype/Publish data with the given IDs.") def __fetch_data_by_id( - conn: gn3db.Connection, dataset_type: str, + conn: gn3db.DbConnection, dataset_type: str, dataset_ids: tuple[str, ...]) -> tuple[dict, ...]: """Fetch data from MySQL by IDs.""" fetch_fns = { @@ -82,7 +82,7 @@ def __fetch_data_by_id( "group(s)."), oauth2_scope="profile group resource") def link_data_to_group( - authconn: authdb.DbConnection, gn3conn: gn3db.Connection, + authconn: authdb.DbConnection, gn3conn: gn3db.DbConnection, dataset_type: str, dataset_ids: tuple[str, ...], group: Group) -> tuple[ dict, ...]: """Link the given data to the specified group.""" diff --git a/gn_auth/auth/authorisation/groups/models.py b/gn_auth/auth/authorisation/groups/models.py index 9008bef..0ffd3a7 100644 --- a/gn_auth/auth/authorisation/groups/models.py +++ b/gn_auth/auth/authorisation/groups/models.py @@ -7,7 +7,7 @@ from typing import Any, Sequence, Iterable, Optional, NamedTuple from flask import g from pymonad.maybe import Just, Maybe, Nothing -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.dictify import dictify from gn_auth.auth.authentication.users import User, user_by_id diff --git a/gn_auth/auth/authorisation/groups/views.py b/gn_auth/auth/authorisation/groups/views.py index d1724cc..a63e09d 100644 --- a/gn_auth/auth/authorisation/groups/views.py +++ b/gn_auth/auth/authorisation/groups/views.py @@ -7,11 +7,11 @@ from functools import partial from MySQLdb.cursors import DictCursor from flask import request, jsonify, Response, Blueprint, current_app -from gn_auth.auth import db -from gn_auth import db_utils as gn3db +from gn_auth.auth.db import sqlite3 as db +from gn_auth.auth.db import mariadb as gn3db from gn_auth.auth.dictify import dictify -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db.sqlite3 import with_db_connection from .data import link_data_to_group from .models import ( @@ -169,7 +169,7 @@ def unlinked_genotype_data( return tuple(dict(row) for row in cursor.fetchall()) def unlinked_phenotype_data( - authconn: db.DbConnection, gn3conn: gn3db.Connection, + authconn: db.DbConnection, gn3conn: gn3db.DbConnection, group: Group) -> tuple[dict, ...]: """ Retrieve all phenotype data linked to a group but not linked to any diff --git a/gn_auth/auth/authorisation/privileges.py b/gn_auth/auth/authorisation/privileges.py index 1b0f06c..a348b92 100644 --- a/gn_auth/auth/authorisation/privileges.py +++ b/gn_auth/auth/authorisation/privileges.py @@ -1,7 +1,7 @@ """Handle privileges""" from typing import Any, Iterable, NamedTuple -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import User class Privilege(NamedTuple): diff --git a/gn_auth/auth/authorisation/resources/checks.py b/gn_auth/auth/authorisation/resources/checks.py index a341dbd..0c57b17 100644 --- a/gn_auth/auth/authorisation/resources/checks.py +++ b/gn_auth/auth/authorisation/resources/checks.py @@ -3,7 +3,7 @@ from uuid import UUID from functools import reduce from typing import Sequence -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import User def __organise_privileges_by_resource_id__(rows): diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py index d96979f..8c035c9 100644 --- a/gn_auth/auth/authorisation/resources/models.py +++ b/gn_auth/auth/authorisation/resources/models.py @@ -5,10 +5,10 @@ from uuid import UUID, uuid4 from functools import reduce, partial from typing import Any, Dict, Sequence, Optional, NamedTuple -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.dictify import dictify from gn_auth.auth.authentication.users import User -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db.sqlite3 import with_db_connection from .checks import authorised_for diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py index 9645303..157d5a3 100644 --- a/gn_auth/auth/authorisation/resources/views.py +++ b/gn_auth/auth/authorisation/resources/views.py @@ -6,7 +6,7 @@ from functools import reduce from flask import request, jsonify, Response, Blueprint, current_app as app -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db.sqlite3 import with_db_connection from .checks import authorised_for from .models import ( diff --git a/gn_auth/auth/authorisation/roles/models.py b/gn_auth/auth/authorisation/roles/models.py index 742a90e..0fecfc1 100644 --- a/gn_auth/auth/authorisation/roles/models.py +++ b/gn_auth/auth/authorisation/roles/models.py @@ -5,7 +5,7 @@ from typing import Any, Sequence, Iterable, NamedTuple from pymonad.either import Left, Right, Either -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.dictify import dictify from gn_auth.auth.authentication.users import User from gn_auth.auth.authorisation.errors import AuthorisationError diff --git a/gn_auth/auth/authorisation/roles/views.py b/gn_auth/auth/authorisation/roles/views.py index 6510365..4fc51f7 100644 --- a/gn_auth/auth/authorisation/roles/views.py +++ b/gn_auth/auth/authorisation/roles/views.py @@ -3,7 +3,7 @@ import uuid from flask import jsonify, Response, Blueprint, current_app -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.dictify import dictify from .models import user_role diff --git a/gn_auth/auth/authorisation/users/admin/ui.py b/gn_auth/auth/authorisation/users/admin/ui.py index 4351a68..9087412 100644 --- a/gn_auth/auth/authorisation/users/admin/ui.py +++ b/gn_auth/auth/authorisation/users/admin/ui.py @@ -3,7 +3,7 @@ from functools import wraps from flask import flash, url_for, redirect from gn_auth.auth.authentication.users import User -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authorisation.roles.models import user_roles from gn_auth.session import logged_in, session_user, clear_session_info diff --git a/gn_auth/auth/authorisation/users/admin/views.py b/gn_auth/auth/authorisation/users/admin/views.py index ab04f91..4a37bc5 100644 --- a/gn_auth/auth/authorisation/users/admin/views.py +++ b/gn_auth/auth/authorisation/users/admin/views.py @@ -18,8 +18,8 @@ from flask import ( from gn_auth import session -from gn_auth.auth import db -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db import sqlite3 as db +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authentication.oauth2.models.oauth2client import ( save_client, diff --git a/gn_auth/auth/authorisation/users/collections/views.py b/gn_auth/auth/authorisation/users/collections/views.py index 3dcc10f..9900205 100644 --- a/gn_auth/auth/authorisation/users/collections/views.py +++ b/gn_auth/auth/authorisation/users/collections/views.py @@ -4,8 +4,8 @@ from uuid import UUID from redis import Redis from flask import jsonify, request, Response, Blueprint, current_app -from gn_auth.auth import db -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db import sqlite3 as db +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authorisation.checks import require_json from gn_auth.auth.authorisation.errors import NotFoundError diff --git a/gn_auth/auth/authorisation/users/masquerade/models.py b/gn_auth/auth/authorisation/users/masquerade/models.py index c45d761..9779764 100644 --- a/gn_auth/auth/authorisation/users/masquerade/models.py +++ b/gn_auth/auth/authorisation/users/masquerade/models.py @@ -5,7 +5,7 @@ from datetime import datetime from flask import current_app as app -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.errors import ForbiddenAccess from gn_auth.auth.authorisation.roles.models import user_roles diff --git a/gn_auth/auth/authorisation/users/masquerade/views.py b/gn_auth/auth/authorisation/users/masquerade/views.py index 9e42945..7bd8ddb 100644 --- a/gn_auth/auth/authorisation/users/masquerade/views.py +++ b/gn_auth/auth/authorisation/users/masquerade/views.py @@ -4,7 +4,7 @@ from functools import partial from flask import request, jsonify, Response, Blueprint -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db.sqlite3 import with_db_connection from gn_auth.auth.authorisation.errors import InvalidData from gn_auth.auth.authorisation.checks import require_json diff --git a/gn_auth/auth/authorisation/users/models.py b/gn_auth/auth/authorisation/users/models.py index 71fa390..61489cf 100644 --- a/gn_auth/auth/authorisation/users/models.py +++ b/gn_auth/auth/authorisation/users/models.py @@ -2,7 +2,7 @@ import uuid from functools import reduce -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.roles.models import Role from gn_auth.auth.authorisation.checks import authorised_p from gn_auth.auth.authorisation.privileges import Privilege diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index 7783dca..0646e3a 100644 --- a/gn_auth/auth/authorisation/users/views.py +++ b/gn_auth/auth/authorisation/users/views.py @@ -7,9 +7,9 @@ import sqlite3 from email_validator import validate_email, EmailNotValidError from flask import request, jsonify, Response, Blueprint, current_app -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.dictify import dictify -from gn_auth.auth.db_utils import with_db_connection +from gn_auth.auth.db.sqlite3 import with_db_connection from .models import list_users from .masquerade.views import masq diff --git a/gn_auth/templates/admin/dashboard.html b/gn_auth/templates/admin/dashboard.html new file mode 100644 index 0000000..7798022 --- /dev/null +++ b/gn_auth/templates/admin/dashboard.html @@ -0,0 +1,24 @@ +{%extends "base.html"%} + +{%block title%}Genenetwork3: Admin Dashboard{%endblock%} + +{%block pagetitle%}Admin Dashboard{%endblock%} + +{%block content%} +{{flash_messages()}} + +
+{%endblock%} diff --git a/gn_auth/templates/admin/list-oauth2-clients.html b/gn_auth/templates/admin/list-oauth2-clients.html new file mode 100644 index 0000000..0104f0d --- /dev/null +++ b/gn_auth/templates/admin/list-oauth2-clients.html @@ -0,0 +1,56 @@ +{%extends "base.html"%} + +{%block title%}Genenetwork3: OAuth2 Clients{%endblock%} + +{%block pagetitle%}OAuth2 Clients{%endblock%} + +{%block content%} +{{flash_messages()}} + +Client ID | +Client Name | +Default Redirect URI | +Owner | +Actions | +|
---|---|---|---|---|---|
{{client.client_id}} | +{{client.client_metadata.client_name}} | +{{client.client_metadata.default_redirect_uri}} | +{{client.user.name}} ({{client.user.email}}) | ++ + View/Edit + + | ++ + | +
+ No registered OAuth2 clients! + | +
Client has been registered successfully.
+ +Please save the following client details somewhere. There is no way to + retrieve the the CLIENT_SECRET once you leave this page.
+ +No such client
+{%else%} +{%set client = client.value%} + +{%endif%} +{%endblock%} diff --git a/gn_auth/templates/base.html b/gn_auth/templates/base.html new file mode 100644 index 0000000..db08545 --- /dev/null +++ b/gn_auth/templates/base.html @@ -0,0 +1,24 @@ +{% from "common-macros.html" import flash_messages%} + + + + + + ++ {{error.error}}: + {{error.description}} +
+{%endblock%} diff --git a/main.py b/main.py index 4a4850c..7f3b256 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ from yoyo import get_backend, read_migrations from gn_auth import migrations from gn_auth import create_app -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import hash_password from scripts import register_sys_admin as rsysadm# type: ignore[import] diff --git a/tests/unit/auth/fixtures/group_fixtures.py b/tests/unit/auth/fixtures/group_fixtures.py index b2bae24..c7775d9 100644 --- a/tests/unit/auth/fixtures/group_fixtures.py +++ b/tests/unit/auth/fixtures/group_fixtures.py @@ -3,7 +3,7 @@ import uuid import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.groups import Group, GroupRole from gn_auth.auth.authorisation.resources import Resource, ResourceCategory diff --git a/tests/unit/auth/fixtures/migration_fixtures.py b/tests/unit/auth/fixtures/migration_fixtures.py index 2a67c01..16a31cd 100644 --- a/tests/unit/auth/fixtures/migration_fixtures.py +++ b/tests/unit/auth/fixtures/migration_fixtures.py @@ -4,7 +4,7 @@ from yoyo.backends import DatabaseBackend from yoyo import get_backend, read_migrations from yoyo.migrations import Migration, MigrationList -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import apply_migrations, rollback_migrations @pytest.fixture(scope="session") diff --git a/tests/unit/auth/fixtures/oauth2_client_fixtures.py b/tests/unit/auth/fixtures/oauth2_client_fixtures.py index 70cd2c2..263fc94 100644 --- a/tests/unit/auth/fixtures/oauth2_client_fixtures.py +++ b/tests/unit/auth/fixtures/oauth2_client_fixtures.py @@ -5,7 +5,7 @@ import datetime import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import hash_password from gn_auth.auth.authentication.oauth2.models.oauth2client import OAuth2Client diff --git a/tests/unit/auth/fixtures/resource_fixtures.py b/tests/unit/auth/fixtures/resource_fixtures.py index efe617e..af22733 100644 --- a/tests/unit/auth/fixtures/resource_fixtures.py +++ b/tests/unit/auth/fixtures/resource_fixtures.py @@ -1,7 +1,7 @@ """Fixtures and utilities for resource-related tests""" import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from .group_fixtures import TEST_RESOURCES diff --git a/tests/unit/auth/fixtures/role_fixtures.py b/tests/unit/auth/fixtures/role_fixtures.py index c97716f..ddcbba5 100644 --- a/tests/unit/auth/fixtures/role_fixtures.py +++ b/tests/unit/auth/fixtures/role_fixtures.py @@ -3,7 +3,7 @@ import uuid import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.roles import Role from gn_auth.auth.authorisation.privileges import Privilege diff --git a/tests/unit/auth/fixtures/user_fixtures.py b/tests/unit/auth/fixtures/user_fixtures.py index 21708a5..531a321 100644 --- a/tests/unit/auth/fixtures/user_fixtures.py +++ b/tests/unit/auth/fixtures/user_fixtures.py @@ -3,7 +3,7 @@ import uuid import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import User, hash_password TEST_USERS = ( diff --git a/tests/unit/auth/test_credentials.py b/tests/unit/auth/test_credentials.py index 8011ec2..1953228 100644 --- a/tests/unit/auth/test_credentials.py +++ b/tests/unit/auth/test_credentials.py @@ -3,7 +3,7 @@ import pytest from yoyo.migrations import MigrationList from hypothesis import given, settings, strategies, HealthCheck -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication import credentials_in_database from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations diff --git a/tests/unit/auth/test_groups.py b/tests/unit/auth/test_groups.py index 8a47cf8..af33f85 100644 --- a/tests/unit/auth/test_groups.py +++ b/tests/unit/auth/test_groups.py @@ -4,7 +4,7 @@ from uuid import UUID import pytest from pymonad.maybe import Nothing -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authentication.users import User from gn_auth.auth.authorisation.roles import Role from gn_auth.auth.authorisation.privileges import Privilege diff --git a/tests/unit/auth/test_migrations_add_data_to_table.py b/tests/unit/auth/test_migrations_add_data_to_table.py index fa46cc9..b686f25 100644 --- a/tests/unit/auth/test_migrations_add_data_to_table.py +++ b/tests/unit/auth/test_migrations_add_data_to_table.py @@ -1,7 +1,7 @@ """Test data insertion when migrations are run.""" import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_add_remove_columns.py b/tests/unit/auth/test_migrations_add_remove_columns.py index a44563a..af85652 100644 --- a/tests/unit/auth/test_migrations_add_remove_columns.py +++ b/tests/unit/auth/test_migrations_add_remove_columns.py @@ -1,7 +1,7 @@ """Test migrations that alter tables adding/removing columns.""" import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_create_tables.py b/tests/unit/auth/test_migrations_create_tables.py index f56489a..bd0164e 100644 --- a/tests/unit/auth/test_migrations_create_tables.py +++ b/tests/unit/auth/test_migrations_create_tables.py @@ -1,7 +1,7 @@ """Test migrations that create tables""" import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_drop_tables.py b/tests/unit/auth/test_migrations_drop_tables.py index 4ce0d45..6fa6f2f 100644 --- a/tests/unit/auth/test_migrations_drop_tables.py +++ b/tests/unit/auth/test_migrations_drop_tables.py @@ -2,7 +2,7 @@ import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_indexes.py b/tests/unit/auth/test_migrations_indexes.py index dcec7c4..1c543c4 100644 --- a/tests/unit/auth/test_migrations_indexes.py +++ b/tests/unit/auth/test_migrations_indexes.py @@ -1,7 +1,7 @@ """Test that indexes are created and removed.""" import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py b/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py index 8a92ae1..c34a549 100644 --- a/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py +++ b/tests/unit/auth/test_migrations_init_data_in_resource_categories_table.py @@ -3,7 +3,7 @@ Test that the `resource_categories` table is initialised with the startup data. """ import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.migrations import get_migration, apply_migrations, rollback_migrations from tests.unit.auth.conftest import ( apply_single_migration, rollback_single_migration, migrations_up_to) diff --git a/tests/unit/auth/test_privileges.py b/tests/unit/auth/test_privileges.py index a40e875..b37a1a7 100644 --- a/tests/unit/auth/test_privileges.py +++ b/tests/unit/auth/test_privileges.py @@ -1,7 +1,7 @@ """Test the privileges module""" import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.privileges import Privilege, user_privileges from tests.unit.auth import conftest diff --git a/tests/unit/auth/test_resources.py b/tests/unit/auth/test_resources.py index 12b8d95..9d2671c 100644 --- a/tests/unit/auth/test_resources.py +++ b/tests/unit/auth/test_resources.py @@ -3,7 +3,7 @@ import uuid import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.groups import Group from gn_auth.auth.authorisation.errors import AuthorisationError diff --git a/tests/unit/auth/test_roles.py b/tests/unit/auth/test_roles.py index 31d5e8e..67654d8 100644 --- a/tests/unit/auth/test_roles.py +++ b/tests/unit/auth/test_roles.py @@ -3,7 +3,7 @@ import uuid import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db from gn_auth.auth.authorisation.privileges import Privilege from gn_auth.auth.authorisation.errors import AuthorisationError from gn_auth.auth.authorisation.roles.models import Role, user_roles, create_role diff --git a/tests/unit/auth/test_token.py b/tests/unit/auth/test_token.py index 4a864fe..f66954f 100644 --- a/tests/unit/auth/test_token.py +++ b/tests/unit/auth/test_token.py @@ -2,7 +2,7 @@ import pytest -from gn_auth.auth import db +from gn_auth.auth.db import sqlite3 as db SUCCESS_RESULT = { "status_code": 200, -- cgit v1.2.3