From e7937ade8d91f7741a649de24faacbe194a3c0d0 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 8 Aug 2023 06:48:14 +0300 Subject: Use relative imports to break circular import errors --- gn_auth/__init__.py | 3 +-- gn_auth/auth/__init__.py | 3 --- gn_auth/auth/authorisation/checks.py | 3 +-- gn_auth/auth/authorisation/data/genotypes.py | 11 ++++---- gn_auth/auth/authorisation/data/mrna.py | 11 ++++---- gn_auth/auth/authorisation/data/phenotypes.py | 12 +++++---- gn_auth/auth/authorisation/data/views.py | 30 ++++++++++------------ gn_auth/auth/authorisation/groups/data.py | 11 ++++---- gn_auth/auth/authorisation/groups/models.py | 6 ++--- gn_auth/auth/authorisation/groups/views.py | 8 +++--- gn_auth/auth/authorisation/privileges.py | 4 +-- gn_auth/auth/authorisation/resources/checks.py | 4 +-- gn_auth/auth/authorisation/resources/models.py | 8 +++--- gn_auth/auth/authorisation/resources/views.py | 4 +-- gn_auth/auth/authorisation/roles/models.py | 9 +++---- gn_auth/auth/authorisation/roles/views.py | 4 +-- gn_auth/auth/authorisation/users/__init__.py | 1 + gn_auth/auth/authorisation/users/admin/ui.py | 9 ++++--- gn_auth/auth/authorisation/users/admin/views.py | 8 +++--- .../auth/authorisation/users/collections/models.py | 2 +- .../auth/authorisation/users/collections/views.py | 13 +++++----- .../auth/authorisation/users/masquerade/models.py | 10 ++++---- .../auth/authorisation/users/masquerade/views.py | 10 ++++---- gn_auth/auth/authorisation/users/models.py | 10 ++++---- gn_auth/auth/authorisation/users/views.py | 6 ++--- 25 files changed, 100 insertions(+), 100 deletions(-) (limited to 'gn_auth') diff --git a/gn_auth/__init__.py b/gn_auth/__init__.py index 9b0264c..446ba19 100644 --- a/gn_auth/__init__.py +++ b/gn_auth/__init__.py @@ -1,5 +1,4 @@ """Application initialisation module.""" - import os import sys import logging @@ -7,8 +6,8 @@ from typing import Optional from flask import Flask -from gn_auth.auth import oauth2 from gn_auth.misc_views import misc +from gn_auth.auth.views import oauth2 from gn_auth.auth.authentication.oauth2.server import setup_oauth2_server diff --git a/gn_auth/auth/__init__.py b/gn_auth/auth/__init__.py index a28498d..4f1d960 100644 --- a/gn_auth/auth/__init__.py +++ b/gn_auth/auth/__init__.py @@ -1,5 +1,2 @@ """Top-Level `Auth` module""" -from . import authorisation -from . import authentication -from .views import oauth2 diff --git a/gn_auth/auth/authorisation/checks.py b/gn_auth/auth/authorisation/checks.py index 46a51fe..55af0b1 100644 --- a/gn_auth/auth/authorisation/checks.py +++ b/gn_auth/auth/authorisation/checks.py @@ -4,11 +4,10 @@ from typing import Callable from flask import request, current_app as app -from gn_auth.auth.db import sqlite3 as db - from . import privileges as auth_privs from .errors import InvalidData, AuthorisationError +from ..db import sqlite3 as db from ..authentication.oauth2.resource_server import require_oauth def __system_privileges_in_roles__(conn, user): diff --git a/gn_auth/auth/authorisation/data/genotypes.py b/gn_auth/auth/authorisation/data/genotypes.py index f5cf11c..818f72d 100644 --- a/gn_auth/auth/authorisation/data/genotypes.py +++ b/gn_auth/auth/authorisation/data/genotypes.py @@ -4,11 +4,12 @@ from typing import Iterable from MySQLdb.cursors import DictCursor -import gn_auth.auth.db.sqlite3 as authdb -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 +from ..checks import authorised_p +from ..groups.models import Group + +from ...dictify import dictify +from ...db import mariadb as gn3db +from ...db import sqlite3 as authdb def linked_genotype_data(conn: authdb.DbConnection) -> Iterable[dict]: """Retrive genotype data that is linked to user groups.""" diff --git a/gn_auth/auth/authorisation/data/mrna.py b/gn_auth/auth/authorisation/data/mrna.py index b80ffe5..53f9bf9 100644 --- a/gn_auth/auth/authorisation/data/mrna.py +++ b/gn_auth/auth/authorisation/data/mrna.py @@ -3,11 +3,12 @@ import uuid from typing import Iterable from MySQLdb.cursors import DictCursor -import gn_auth.auth.db.sqlite3 as authdb -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 +from ..checks import authorised_p +from ..groups.models import Group + +from ...dictify import dictify +from ...db import sqlite3 as authdb +from ...db import mariadb as gn3db def linked_mrna_data(conn: authdb.DbConnection) -> Iterable[dict]: """Retrieve mRNA Assay data that is linked to user groups.""" diff --git a/gn_auth/auth/authorisation/data/phenotypes.py b/gn_auth/auth/authorisation/data/phenotypes.py index 0220201..84fc089 100644 --- a/gn_auth/auth/authorisation/data/phenotypes.py +++ b/gn_auth/auth/authorisation/data/phenotypes.py @@ -4,11 +4,13 @@ from typing import Any, Iterable from MySQLdb.cursors import DictCursor -import gn_auth.auth.db.sqlite3 as authdb -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 + +from ..checks import authorised_p +from ..groups.models import Group + +from ...dictify import dictify +from ...db import sqlite3 as authdb +from ...db import mariadb as gn3db def linked_phenotype_data( authconn: authdb.DbConnection, gn3conn: gn3db.DbConnection, diff --git a/gn_auth/auth/authorisation/data/views.py b/gn_auth/auth/authorisation/data/views.py index 03b416f..3c49ae5 100644 --- a/gn_auth/auth/authorisation/data/views.py +++ b/gn_auth/auth/authorisation/data/views.py @@ -10,32 +10,30 @@ 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.auth.db.mariadb as gn3db - from gn_auth import jobs from gn_auth.commands import run_async_cmd -from gn_auth.auth.db import sqlite3 as db -from gn_auth.auth.db.sqlite3 import with_db_connection +from ...db import sqlite3 as db +from ...db import mariadb as gn3db +from ...db.sqlite3 import with_db_connection -from gn_auth.auth.authorisation.checks import require_json -from gn_auth.auth.authorisation.errors import InvalidData, NotFoundError +from ..checks import require_json +from ..errors import InvalidData, NotFoundError -from gn_auth.auth.authorisation.groups.models import group_by_id +from ..groups.models import group_by_id -from gn_auth.auth.authorisation.users.models import user_resource_roles +from ..users.models import user_resource_roles -from gn_auth.auth.authorisation.resources.checks import authorised_for -from gn_auth.auth.authorisation.resources.models import ( +from ..resources.checks import authorised_for +from ..resources.models import ( user_resources, public_resources, attach_resources_data) -from gn_auth.auth.authentication.users import User -from gn_auth.auth.authentication.oauth2.resource_server import require_oauth +from ...authentication.users import User +from ...authentication.oauth2.resource_server import require_oauth -from gn_auth.auth.authorisation.data.phenotypes import link_phenotype_data -from gn_auth.auth.authorisation.data.mrna import link_mrna_data, ungrouped_mrna_data -from gn_auth.auth.authorisation.data.genotypes import ( - link_genotype_data, ungrouped_genotype_data) +from ..data.phenotypes import link_phenotype_data +from ..data.mrna import link_mrna_data, ungrouped_mrna_data +from ..data.genotypes import link_genotype_data, ungrouped_genotype_data data = Blueprint("data", __name__) diff --git a/gn_auth/auth/authorisation/groups/data.py b/gn_auth/auth/authorisation/groups/data.py index a73ae3d..1650405 100644 --- a/gn_auth/auth/authorisation/groups/data.py +++ b/gn_auth/auth/authorisation/groups/data.py @@ -1,11 +1,12 @@ """Handles the resource objects' data.""" from MySQLdb.cursors import DictCursor -from gn_auth.auth.db import mariadb as gn3db -import gn_auth.auth.db.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 +from ..groups import Group +from ..checks import authorised_p +from ..errors import NotFoundError + +from ...db import mariadb as gn3db +from ...db import sqlite3 as authdb def __fetch_mrna_data_by_ids__( conn: gn3db.DbConnection, dataset_ids: tuple[str, ...]) -> tuple[ diff --git a/gn_auth/auth/authorisation/groups/models.py b/gn_auth/auth/authorisation/groups/models.py index 0ffd3a7..6a39681 100644 --- a/gn_auth/auth/authorisation/groups/models.py +++ b/gn_auth/auth/authorisation/groups/models.py @@ -7,9 +7,9 @@ from typing import Any, Sequence, Iterable, Optional, NamedTuple from flask import g from pymonad.maybe import Just, Maybe, Nothing -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 +from ...db import sqlite3 as db +from ...dictify import dictify +from ...authentication.users import User, user_by_id from ..checks import authorised_p from ..privileges import Privilege diff --git a/gn_auth/auth/authorisation/groups/views.py b/gn_auth/auth/authorisation/groups/views.py index a63e09d..4dc17e0 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.db import sqlite3 as db -from gn_auth.auth.db import mariadb as gn3db +from ...db import sqlite3 as db +from ...db import mariadb as gn3db -from gn_auth.auth.dictify import dictify -from gn_auth.auth.db.sqlite3 import with_db_connection +from ...dictify import dictify +from ...db.sqlite3 import with_db_connection from .data import link_data_to_group from .models import ( diff --git a/gn_auth/auth/authorisation/privileges.py b/gn_auth/auth/authorisation/privileges.py index a348b92..bba6258 100644 --- a/gn_auth/auth/authorisation/privileges.py +++ b/gn_auth/auth/authorisation/privileges.py @@ -1,8 +1,8 @@ """Handle privileges""" from typing import Any, Iterable, NamedTuple -from gn_auth.auth.db import sqlite3 as db -from gn_auth.auth.authentication.users import User +from ..db import sqlite3 as db +from ..authentication.users import User class Privilege(NamedTuple): """Class representing a privilege: creates immutable objects.""" diff --git a/gn_auth/auth/authorisation/resources/checks.py b/gn_auth/auth/authorisation/resources/checks.py index 0c57b17..db975de 100644 --- a/gn_auth/auth/authorisation/resources/checks.py +++ b/gn_auth/auth/authorisation/resources/checks.py @@ -3,8 +3,8 @@ from uuid import UUID from functools import reduce from typing import Sequence -from gn_auth.auth.db import sqlite3 as db -from gn_auth.auth.authentication.users import User +from ...db import sqlite3 as db +from ...authentication.users import User def __organise_privileges_by_resource_id__(rows): def __organise__(privs, row): diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py index 8c035c9..e4c3cab 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.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.sqlite3 import with_db_connection +from ...db import sqlite3 as db +from ...dictify import dictify +from ...authentication.users import User +from ...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 e7af9b9..bf7e6f5 100644 --- a/gn_auth/auth/authorisation/resources/views.py +++ b/gn_auth/auth/authorisation/resources/views.py @@ -6,8 +6,8 @@ from functools import reduce from flask import request, jsonify, Response, Blueprint, current_app as app -from gn_auth.auth.db import sqlite3 as db -from gn_auth.auth.db.sqlite3 import with_db_connection +from ...db import sqlite3 as db +from ...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 0fecfc1..e1b0d6b 100644 --- a/gn_auth/auth/authorisation/roles/models.py +++ b/gn_auth/auth/authorisation/roles/models.py @@ -5,14 +5,13 @@ from typing import Any, Sequence, Iterable, NamedTuple from pymonad.either import Left, Right, Either -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 +from ...db import sqlite3 as db +from ...dictify import dictify +from ...authentication.users import User from ..checks import authorised_p from ..privileges import Privilege -from ..errors import NotFoundError +from ..errors import NotFoundError, AuthorisationError class Role(NamedTuple): """Class representing a role: creates immutable objects.""" diff --git a/gn_auth/auth/authorisation/roles/views.py b/gn_auth/auth/authorisation/roles/views.py index 4fc51f7..29d0991 100644 --- a/gn_auth/auth/authorisation/roles/views.py +++ b/gn_auth/auth/authorisation/roles/views.py @@ -3,8 +3,8 @@ import uuid from flask import jsonify, Response, Blueprint, current_app -from gn_auth.auth.db import sqlite3 as db -from gn_auth.auth.dictify import dictify +from ...dictify import dictify +from ...db import sqlite3 as db from .models import user_role diff --git a/gn_auth/auth/authorisation/users/__init__.py b/gn_auth/auth/authorisation/users/__init__.py index e69de29..dbc6482 100644 --- a/gn_auth/auth/authorisation/users/__init__.py +++ b/gn_auth/auth/authorisation/users/__init__.py @@ -0,0 +1 @@ +"""Users module.""" diff --git a/gn_auth/auth/authorisation/users/admin/ui.py b/gn_auth/auth/authorisation/users/admin/ui.py index 9087412..68e1ba5 100644 --- a/gn_auth/auth/authorisation/users/admin/ui.py +++ b/gn_auth/auth/authorisation/users/admin/ui.py @@ -2,12 +2,13 @@ from functools import wraps from flask import flash, url_for, redirect -from gn_auth.auth.authentication.users import User -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 +from ....authentication.users import User +from ....db.sqlite3 import with_db_connection + +from ...roles.models import user_roles + def is_admin(func): """Verify user is a system admin.""" @wraps(func) diff --git a/gn_auth/auth/authorisation/users/admin/views.py b/gn_auth/auth/authorisation/users/admin/views.py index 4a37bc5..6ace0e5 100644 --- a/gn_auth/auth/authorisation/users/admin/views.py +++ b/gn_auth/auth/authorisation/users/admin/views.py @@ -18,16 +18,16 @@ from flask import ( from gn_auth import session -from gn_auth.auth.db import sqlite3 as db -from gn_auth.auth.db.sqlite3 import with_db_connection +from ....db import sqlite3 as db +from ....db.sqlite3 import with_db_connection -from gn_auth.auth.authentication.oauth2.models.oauth2client import ( +from ....authentication.oauth2.models.oauth2client import ( save_client, OAuth2Client, oauth2_clients, client as oauth2_client, delete_client as _delete_client) -from gn_auth.auth.authentication.users import ( +from ....authentication.users import ( User, user_by_id, valid_login, diff --git a/gn_auth/auth/authorisation/users/collections/models.py b/gn_auth/auth/authorisation/users/collections/models.py index eb9b188..9157100 100644 --- a/gn_auth/auth/authorisation/users/collections/models.py +++ b/gn_auth/auth/authorisation/users/collections/models.py @@ -6,7 +6,7 @@ from datetime import datetime from redis import Redis from email_validator import validate_email, EmailNotValidError -from gn_auth.auth.authorisation.errors import InvalidData, NotFoundError +from ...errors import InvalidData, NotFoundError from ..models import User diff --git a/gn_auth/auth/authorisation/users/collections/views.py b/gn_auth/auth/authorisation/users/collections/views.py index 9900205..a1cc30d 100644 --- a/gn_auth/auth/authorisation/users/collections/views.py +++ b/gn_auth/auth/authorisation/users/collections/views.py @@ -4,13 +4,14 @@ from uuid import UUID from redis import Redis from flask import jsonify, request, Response, Blueprint, current_app -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 +from ....db import sqlite3 as db +from ....db.sqlite3 import with_db_connection -from gn_auth.auth.authentication.users import User, user_by_id -from gn_auth.auth.authentication.oauth2.resource_server import require_oauth +from ....authentication.users import User, user_by_id +from ....authentication.oauth2.resource_server import require_oauth + +from ...checks import require_json +from ...errors import NotFoundError from .models import ( add_traits, diff --git a/gn_auth/auth/authorisation/users/masquerade/models.py b/gn_auth/auth/authorisation/users/masquerade/models.py index 9779764..86b9e53 100644 --- a/gn_auth/auth/authorisation/users/masquerade/models.py +++ b/gn_auth/auth/authorisation/users/masquerade/models.py @@ -5,13 +5,13 @@ from datetime import datetime from flask import current_app as app -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 +from ...errors import ForbiddenAccess +from ...roles.models import user_roles -from gn_auth.auth.authentication.users import User -from gn_auth.auth.authentication.oauth2.models.oauth2token import ( +from ....db import sqlite3 as db +from ....authentication.users import User +from ....authentication.oauth2.models.oauth2token import ( OAuth2Token, save_token) __FIVE_HOURS__ = (60 * 60 * 5) diff --git a/gn_auth/auth/authorisation/users/masquerade/views.py b/gn_auth/auth/authorisation/users/masquerade/views.py index 7bd8ddb..259cdfe 100644 --- a/gn_auth/auth/authorisation/users/masquerade/views.py +++ b/gn_auth/auth/authorisation/users/masquerade/views.py @@ -4,12 +4,12 @@ from functools import partial from flask import request, jsonify, Response, Blueprint -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 +from ...errors import InvalidData +from ...checks import require_json -from gn_auth.auth.authentication.users import user_by_id -from gn_auth.auth.authentication.oauth2.resource_server import require_oauth +from ....db.sqlite3 import with_db_connection +from ....authentication.users import user_by_id +from ....authentication.oauth2.resource_server import require_oauth from .models import masquerade_as diff --git a/gn_auth/auth/authorisation/users/models.py b/gn_auth/auth/authorisation/users/models.py index 61489cf..9fb9d9e 100644 --- a/gn_auth/auth/authorisation/users/models.py +++ b/gn_auth/auth/authorisation/users/models.py @@ -2,12 +2,12 @@ import uuid from functools import reduce -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 +from ..roles.models import Role +from ..checks import authorised_p +from ..privileges import Privilege -from gn_auth.auth.authentication.users import User +from ...db import sqlite3 as db +from ...authentication.users import User @authorised_p( ("system:user:list",), diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index 0646e3a..6de30da 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.db import sqlite3 as db -from gn_auth.auth.dictify import dictify -from gn_auth.auth.db.sqlite3 import with_db_connection +from ...db import sqlite3 as db +from ...dictify import dictify +from ...db.sqlite3 import with_db_connection from .models import list_users from .masquerade.views import masq -- cgit v1.2.3