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 +++++ 42 files changed, 436 insertions(+), 55 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 (limited to 'gn_auth') 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()}} + + + + + + + + + + + + + + + {%for client in clients%} + + + + + + + + + {%else%} + + + + {%endfor%} + + +{%endblock%} diff --git a/gn_auth/templates/admin/login.html b/gn_auth/templates/admin/login.html new file mode 100644 index 0000000..ac217ab --- /dev/null +++ b/gn_auth/templates/admin/login.html @@ -0,0 +1,32 @@ +{%extends "base.html"%} + +{%block title%}Log in to Genenetwork3{%endblock%} + +{%block pagetitle%}Admin Log In{%endblock%} + +{%block content%} +{{flash_messages()}} + +
+ +
+ User Credentials + + + +
+ + +
+ +
+ + +
+
+ + +
+{%endblock%} diff --git a/gn_auth/templates/admin/register-client.html b/gn_auth/templates/admin/register-client.html new file mode 100644 index 0000000..daac977 --- /dev/null +++ b/gn_auth/templates/admin/register-client.html @@ -0,0 +1,78 @@ +{%extends "base.html"%} + +{%block title%}Genenetwork3: Register OAuth2 Client{%endblock%} + +{%block pagetitle%}Register OAuth2 Client{%endblock%} + +{%block content%} +{{flash_messages()}} + +
+ +
+ Select client scope + + {%for scp in scope%} + +
+ {%endfor%} + +
+ +
+ Basic OAuth2 client information + + + + +

+ + + +

+ + +
+ +

+
+ Supported grant types + + +

+ + + +
+
+ +
+ User information + +

The user to register this client for

+ +
+ + +
+{%endblock%} diff --git a/gn_auth/templates/admin/registered-client.html b/gn_auth/templates/admin/registered-client.html new file mode 100644 index 0000000..5c46f4d --- /dev/null +++ b/gn_auth/templates/admin/registered-client.html @@ -0,0 +1,21 @@ +{%extends "base.html"%} + +{%block title%}Genenetwork3: Register OAuth2 Client{%endblock%} + +{%block pagetitle%}Register OAuth2 Client{%endblock%} + +{%block content%} +{{flash_messages()}} + +

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.

+ +
+
CLIENT_ID
+
{{client.client_id}}
+
CLIENT_SECRET
+
{{client_secret}}
+
+{%endblock%} diff --git a/gn_auth/templates/admin/view-oauth2-client.html b/gn_auth/templates/admin/view-oauth2-client.html new file mode 100644 index 0000000..b90428d --- /dev/null +++ b/gn_auth/templates/admin/view-oauth2-client.html @@ -0,0 +1,75 @@ +{%extends "base.html"%} + +{%block title%}Genenetwork3: View OAuth2 Client{%endblock%} + +{%block pagetitle%}View OAuth2 Client{%endblock%} + +{%block content%} +{{flash_messages()}} + +{%if client.is_nothing()%} +

No such client

+{%else%} +{%set client = client.value%} +
+ View/Edit Oauth2 Client + +
+

Client ID: {{client.client_id}}

+

Client Name: {{client.client_metadata.client_name}}

+
+
+ Scope + {%for scp in scope%} + +
+ {%endfor%} +
+ +
+ Redirect URIs + +
+ +

+ + +
+ +
+ +
+ Grants + + +

+ + + +
+ + + +{%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%} + + + + + + + Genenetwork 3: {%block title%}{%endblock%} + + + + {%block css%}{%endblock%} + + + +

Genenetwork3: {%block pagetitle%}{%endblock%}

+ +
+ {%block content%}{%endblock%} +
+ {%block js%}{%endblock%} + + diff --git a/gn_auth/templates/common-macros.html b/gn_auth/templates/common-macros.html new file mode 100644 index 0000000..1d9f302 --- /dev/null +++ b/gn_auth/templates/common-macros.html @@ -0,0 +1,7 @@ +{%macro flash_messages()%} +
+ {%for category,message in get_flashed_messages(with_categories=true)%} + + {%endfor%} +
+{%endmacro%} diff --git a/gn_auth/templates/oauth2/authorise-user.html b/gn_auth/templates/oauth2/authorise-user.html new file mode 100644 index 0000000..b9284e5 --- /dev/null +++ b/gn_auth/templates/oauth2/authorise-user.html @@ -0,0 +1,48 @@ +{%extends "base.html"%} + +{%block title%}Authorise User{%endblock%} + +{%block pagetitle%}Authenticate to the API Server{%endblock%} + +{%block content%} +{{flash_messages()}} + +
+ + + +

+ You are authorising "{{client.client_metadata.client_name}}" to access + Genenetwork 3 with the following scope: +

+
+ Scope + {%for scp in scope%} +
+ +
+ {%endfor%} +
+ +
+ User Credentials +
+ + +
+ +
+ + +
+
+ + +
+{%endblock%} diff --git a/gn_auth/templates/oauth2/oauth2_error.html b/gn_auth/templates/oauth2/oauth2_error.html new file mode 100644 index 0000000..ec9a500 --- /dev/null +++ b/gn_auth/templates/oauth2/oauth2_error.html @@ -0,0 +1,16 @@ +{%extends "base.html"%} + +{%block title%}OAuth2 Error{%endblock%} + +{%block pagetitle%}Error: {{error.status_code}}{%endblock%} + +{%block content%} +{{flash_messages()}} + +There was an error trying to fulfill your request: + +

+ {{error.error}}: + {{error.description}} +

+{%endblock%} -- cgit v1.2.3