diff --git a/canaille/__init__.py b/canaille/__init__.py index e6ef0f59..2bdc96cb 100644 --- a/canaille/__init__.py +++ b/canaille/__init__.py @@ -115,16 +115,16 @@ def setup_themer(app): def setup_blueprints(app): - import canaille.account - import canaille.admin - import canaille.groups + import canaille.core.account + import canaille.core.admin + import canaille.core.groups import canaille.oidc.blueprints app.url_map.strict_slashes = False - app.register_blueprint(canaille.account.bp) - app.register_blueprint(canaille.admin.bp) - app.register_blueprint(canaille.groups.bp) + app.register_blueprint(canaille.core.account.bp) + app.register_blueprint(canaille.core.admin.bp) + app.register_blueprint(canaille.core.groups.bp) app.register_blueprint(canaille.oidc.blueprints.bp) @@ -174,7 +174,7 @@ def create_app(config=None, validate=True): try: from .oidc.oauth import setup_oauth from .ldap_backend.backend import init_backend - from .i18n import setup_i18n + from .utils.i18n import setup_i18n setup_logging(app) init_backend(app) diff --git a/canaille/commands.py b/canaille/commands.py index 82dd3841..43cc859b 100644 --- a/canaille/commands.py +++ b/canaille/commands.py @@ -112,7 +112,7 @@ if HAS_FAKER: # pragma: no branch Populate the database with generated random users. """ - from canaille.populate import fake_users + from canaille.core.populate import fake_users fake_users(ctx.obj["number"]) @@ -130,6 +130,6 @@ if HAS_FAKER: # pragma: no branch Populate the database with generated random groups. """ - from canaille.populate import fake_groups + from canaille.core.populate import fake_groups fake_groups(ctx.obj["number"], nb_users_max) diff --git a/canaille/core/__init__.py b/canaille/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/canaille/account.py b/canaille/core/account.py similarity index 97% rename from canaille/account.py rename to canaille/core/account.py index c603ec71..01a9c6f7 100644 --- a/canaille/account.py +++ b/canaille/core/account.py @@ -6,6 +6,18 @@ from typing import List import pkg_resources import wtforms +from canaille.utils import b64_to_obj +from canaille.utils import default_fields +from canaille.utils import login_placeholder +from canaille.utils import obj_to_b64 +from canaille.utils import profile_hash +from canaille.utils.flask import current_user +from canaille.utils.flask import permissions_needed +from canaille.utils.flask import render_htmx_template +from canaille.utils.flask import request_is_htmx +from canaille.utils.flask import smtp_needed +from canaille.utils.flask import user_needed +from canaille.utils.forms import TableForm from flask import abort from flask import Blueprint from flask import current_app @@ -33,18 +45,6 @@ from .mails import send_password_initialization_mail from .mails import send_password_reset_mail from .models import Group from .models import User -from .utils import b64_to_obj -from .utils import default_fields -from .utils import login_placeholder -from .utils import obj_to_b64 -from .utils import profile_hash -from .utils.flask import current_user -from .utils.flask import permissions_needed -from .utils.flask import render_htmx_template -from .utils.flask import request_is_htmx -from .utils.flask import smtp_needed -from .utils.flask import user_needed -from .utils.forms import TableForm bp = Blueprint("account", __name__) diff --git a/canaille/admin.py b/canaille/core/admin.py similarity index 98% rename from canaille/admin.py rename to canaille/core/admin.py index aca843a2..2e5cbdb6 100644 --- a/canaille/admin.py +++ b/canaille/core/admin.py @@ -1,5 +1,5 @@ -from canaille.mails import profile_hash -from canaille.mails import send_test_mail +from canaille.core.mails import profile_hash +from canaille.core.mails import send_test_mail from canaille.utils import obj_to_b64 from canaille.utils.flask import permissions_needed from canaille.utils.forms import HTMXForm diff --git a/canaille/forms.py b/canaille/core/forms.py similarity index 98% rename from canaille/forms.py rename to canaille/core/forms.py index 181c7e72..faacf1c1 100644 --- a/canaille/forms.py +++ b/canaille/core/forms.py @@ -1,16 +1,16 @@ import wtforms.form +from canaille.utils.forms import HTMXBaseForm +from canaille.utils.forms import HTMXForm +from canaille.utils.forms import is_uri +from canaille.utils.i18n import native_language_name_from_code from flask import current_app from flask import g from flask_babel import lazy_gettext as _ from flask_wtf.file import FileAllowed from flask_wtf.file import FileField -from .i18n import native_language_name_from_code from .models import Group from .models import User -from .utils.forms import HTMXBaseForm -from .utils.forms import HTMXForm -from .utils.forms import is_uri def unique_login(form, field): diff --git a/canaille/groups.py b/canaille/core/groups.py similarity index 95% rename from canaille/groups.py rename to canaille/core/groups.py index d468314d..e871bd22 100644 --- a/canaille/groups.py +++ b/canaille/core/groups.py @@ -1,3 +1,6 @@ +from canaille.utils.flask import permissions_needed +from canaille.utils.flask import render_htmx_template +from canaille.utils.forms import TableForm from flask import abort from flask import Blueprint from flask import flash @@ -11,9 +14,6 @@ from .forms import CreateGroupForm from .forms import EditGroupForm from .models import Group from .models import User -from .utils.flask import permissions_needed -from .utils.flask import render_htmx_template -from .utils.forms import TableForm bp = Blueprint("groups", __name__, url_prefix="/groups") diff --git a/canaille/mails.py b/canaille/core/mails.py similarity index 99% rename from canaille/mails.py rename to canaille/core/mails.py index 1568cbb1..c5414f12 100644 --- a/canaille/mails.py +++ b/canaille/core/mails.py @@ -1,3 +1,4 @@ +from canaille.utils import profile_hash from canaille.utils.mails import logo from canaille.utils.mails import send_email from flask import current_app @@ -5,8 +6,6 @@ from flask import url_for from flask_babel import gettext as _ from flask_themer import render_template -from .utils import profile_hash - def send_test_mail(email): base_url = url_for("account.index", _external=True) diff --git a/canaille/models.py b/canaille/core/models.py similarity index 99% rename from canaille/models.py rename to canaille/core/models.py index 0e79ed4d..da46538d 100644 --- a/canaille/models.py +++ b/canaille/core/models.py @@ -1,9 +1,8 @@ import ldap.filter +from canaille.ldap_backend.ldapobject import LDAPObject from flask import current_app from flask import session -from .ldap_backend.ldapobject import LDAPObject - class User(LDAPObject): DEFAULT_OBJECT_CLASS = "inetOrgPerson" diff --git a/canaille/populate.py b/canaille/core/populate.py similarity index 93% rename from canaille/populate.py rename to canaille/core/populate.py index daa6b8f9..984e0304 100644 --- a/canaille/populate.py +++ b/canaille/core/populate.py @@ -2,9 +2,9 @@ import random import faker import ldap -from canaille.i18n import available_language_codes -from canaille.models import Group -from canaille.models import User +from canaille.core.models import Group +from canaille.core.models import User +from canaille.utils.i18n import available_language_codes from faker.config import AVAILABLE_LOCALES diff --git a/canaille/ldap_backend/backend.py b/canaille/ldap_backend/backend.py index fd87a84e..05a2ac2f 100644 --- a/canaille/ldap_backend/backend.py +++ b/canaille/ldap_backend/backend.py @@ -11,8 +11,8 @@ from flask_babel import gettext as _ def setup_ldap_models(config): from .ldapobject import LDAPObject - from ..models import Group - from ..models import User + from canaille.core.models import Group + from canaille.core.models import User LDAPObject.root_dn = config["LDAP"]["ROOT_DN"] @@ -112,7 +112,8 @@ def init_backend(app): def validate_configuration(config): - from canaille.models import User, Group + from canaille.core.models import Group + from canaille.core.models import User try: conn = ldap.initialize(config["LDAP"]["URI"]) diff --git a/canaille/oidc/endpoints.py b/canaille/oidc/endpoints.py index 0e22d065..68503cb3 100644 --- a/canaille/oidc/endpoints.py +++ b/canaille/oidc/endpoints.py @@ -6,6 +6,8 @@ from authlib.jose import JsonWebKey from authlib.jose import jwt from authlib.oauth2 import OAuth2Error from canaille import csrf +from canaille.core.forms import FullLoginForm +from canaille.core.models import User from flask import abort from flask import Blueprint from flask import current_app @@ -19,8 +21,6 @@ from flask_babel import gettext as _ from flask_themer import render_template from werkzeug.datastructures import CombinedMultiDict -from ..forms import FullLoginForm -from ..models import User from ..utils.flask import current_user from ..utils.flask import set_parameter_in_url_query from .forms import AuthorizeForm diff --git a/canaille/oidc/oauth.py b/canaille/oidc/oauth.py index 634db4ce..25421ec5 100644 --- a/canaille/oidc/oauth.py +++ b/canaille/oidc/oauth.py @@ -26,11 +26,11 @@ from authlib.oidc.core.grants import OpenIDCode as _OpenIDCode from authlib.oidc.core.grants import OpenIDHybridGrant as _OpenIDHybridGrant from authlib.oidc.core.grants import OpenIDImplicitGrant as _OpenIDImplicitGrant from authlib.oidc.core.grants.util import generate_id_token +from canaille.core.models import User from flask import current_app from flask import request from werkzeug.security import gen_salt -from ..models import User from .models import AuthorizationCode from .models import Client from .models import Token diff --git a/canaille/utils/__init__.py b/canaille/utils/__init__.py index 27a1ff0e..e127c52b 100644 --- a/canaille/utils/__init__.py +++ b/canaille/utils/__init__.py @@ -3,7 +3,7 @@ import hashlib import json import re -from canaille.models import User +from canaille.core.models import User from flask import current_app from flask import request from flask_babel import gettext as _ diff --git a/canaille/utils/flask.py b/canaille/utils/flask.py index fdf31a3f..6b832ada 100644 --- a/canaille/utils/flask.py +++ b/canaille/utils/flask.py @@ -3,7 +3,7 @@ from functools import wraps from urllib.parse import urlsplit from urllib.parse import urlunsplit -from canaille.models import User +from canaille.core.models import User from flask import abort from flask import current_app from flask import render_template diff --git a/canaille/utils/forms.py b/canaille/utils/forms.py index f80f0b1e..7891cd57 100644 --- a/canaille/utils/forms.py +++ b/canaille/utils/forms.py @@ -1,8 +1,8 @@ import math import wtforms -from canaille.i18n import DEFAULT_LANGUAGE_CODE -from canaille.i18n import locale_selector +from canaille.utils.i18n import DEFAULT_LANGUAGE_CODE +from canaille.utils.i18n import locale_selector from flask import abort from flask import current_app from flask import make_response diff --git a/canaille/i18n.py b/canaille/utils/i18n.py similarity index 97% rename from canaille/i18n.py rename to canaille/utils/i18n.py index 1b09e40d..5f945ce6 100644 --- a/canaille/i18n.py +++ b/canaille/utils/i18n.py @@ -27,7 +27,7 @@ def setup_i18n(app): def locale_selector(): - from .utils.flask import current_user + from .flask import current_user user = current_user() available_language_codes = getattr(g, "available_language_codes", []) diff --git a/tests/commands/test_populate.py b/tests/commands/test_populate.py index 69b03e8f..49ac69d8 100644 --- a/tests/commands/test_populate.py +++ b/tests/commands/test_populate.py @@ -1,7 +1,7 @@ from canaille.commands import cli -from canaille.models import Group -from canaille.models import User -from canaille.populate import fake_users +from canaille.core.models import Group +from canaille.core.models import User +from canaille.core.populate import fake_users def test_populate_users(testclient, slapd_connection): diff --git a/tests/conftest.py b/tests/conftest.py index 62dda704..3402878e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,9 @@ import ldap.ldapobject import pytest import slapd from canaille import create_app +from canaille.core.models import Group +from canaille.core.models import User from canaille.ldap_backend.backend import setup_ldap_models -from canaille.models import Group -from canaille.models import User from canaille.oidc.installation import setup_ldap_tree from flask import g from flask_webtest import TestApp diff --git a/tests/core/__init__.py b/tests/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_about.py b/tests/core/test_about.py similarity index 100% rename from tests/test_about.py rename to tests/core/test_about.py diff --git a/tests/test_account.py b/tests/core/test_account.py similarity index 99% rename from tests/test_account.py rename to tests/core/test_account.py index 1fb09350..d31c89b8 100644 --- a/tests/test_account.py +++ b/tests/core/test_account.py @@ -1,6 +1,6 @@ from unittest import mock -from canaille.models import User +from canaille.core.models import User def test_index(testclient, user): diff --git a/tests/test_forgotten_password.py b/tests/core/test_forgotten_password.py similarity index 100% rename from tests/test_forgotten_password.py rename to tests/core/test_forgotten_password.py diff --git a/tests/test_groups.py b/tests/core/test_groups.py similarity index 97% rename from tests/test_groups.py rename to tests/core/test_groups.py index 8d676b9e..ad206fcb 100644 --- a/tests/test_groups.py +++ b/tests/core/test_groups.py @@ -1,7 +1,7 @@ -from canaille.models import Group -from canaille.models import User -from canaille.populate import fake_groups -from canaille.populate import fake_users +from canaille.core.models import Group +from canaille.core.models import User +from canaille.core.populate import fake_groups +from canaille.core.populate import fake_users def test_no_group(app, slapd_connection): diff --git a/tests/test_invitation.py b/tests/core/test_invitation.py similarity index 99% rename from tests/test_invitation.py rename to tests/core/test_invitation.py index ff9358c6..730982b2 100644 --- a/tests/test_invitation.py +++ b/tests/core/test_invitation.py @@ -1,7 +1,7 @@ import datetime -from canaille.account import Invitation -from canaille.models import User +from canaille.core.account import Invitation +from canaille.core.models import User def test_invitation(testclient, logged_admin, foo_group, smtpd): diff --git a/tests/test_password_reset.py b/tests/core/test_password_reset.py similarity index 97% rename from tests/test_password_reset.py rename to tests/core/test_password_reset.py index 0272684a..a459c9b0 100644 --- a/tests/test_password_reset.py +++ b/tests/core/test_password_reset.py @@ -1,4 +1,4 @@ -from canaille.account import profile_hash +from canaille.core.account import profile_hash def test_password_reset(testclient, user): diff --git a/tests/test_profile_creation.py b/tests/core/test_profile_creation.py similarity index 99% rename from tests/test_profile_creation.py rename to tests/core/test_profile_creation.py index 1f59c328..8bca6e15 100644 --- a/tests/test_profile_creation.py +++ b/tests/core/test_profile_creation.py @@ -1,4 +1,4 @@ -from canaille.models import User +from canaille.core.models import User def test_user_creation_edition_and_deletion( diff --git a/tests/test_profile_edition.py b/tests/core/test_profile_edition.py similarity index 99% rename from tests/test_profile_edition.py rename to tests/core/test_profile_edition.py index 4eec077d..ad4cfe6e 100644 --- a/tests/test_profile_edition.py +++ b/tests/core/test_profile_edition.py @@ -1,4 +1,4 @@ -from canaille.populate import fake_users +from canaille.core.populate import fake_users from webtest import Upload diff --git a/tests/test_profile_photo.py b/tests/core/test_profile_photo.py similarity index 99% rename from tests/test_profile_photo.py rename to tests/core/test_profile_photo.py index b7111be9..cce7b6bd 100644 --- a/tests/test_profile_photo.py +++ b/tests/core/test_profile_photo.py @@ -1,6 +1,6 @@ import datetime -from canaille.models import User +from canaille.core.models import User from webtest import Upload diff --git a/tests/test_profile_settings.py b/tests/core/test_profile_settings.py similarity index 99% rename from tests/test_profile_settings.py rename to tests/core/test_profile_settings.py index df5f4bb4..c20517bb 100644 --- a/tests/test_profile_settings.py +++ b/tests/core/test_profile_settings.py @@ -1,6 +1,6 @@ from unittest import mock -from canaille.models import User +from canaille.core.models import User def test_edition( diff --git a/tests/ldap/test_utils.py b/tests/ldap/test_utils.py index 9baf3ecd..a57a732d 100644 --- a/tests/ldap/test_utils.py +++ b/tests/ldap/test_utils.py @@ -1,14 +1,14 @@ import datetime import ldap.dn +from canaille.core.models import Group +from canaille.core.models import User from canaille.ldap_backend.backend import setup_ldap_models from canaille.ldap_backend.ldapobject import LDAPObject from canaille.ldap_backend.ldapobject import python_attrs_to_ldap from canaille.ldap_backend.utils import ldap_to_python from canaille.ldap_backend.utils import python_to_ldap from canaille.ldap_backend.utils import Syntax -from canaille.models import Group -from canaille.models import User def test_object_creation(slapd_connection): diff --git a/tests/oidc/test_authorization_code_flow.py b/tests/oidc/test_authorization_code_flow.py index fabf8b1d..017a9c19 100644 --- a/tests/oidc/test_authorization_code_flow.py +++ b/tests/oidc/test_authorization_code_flow.py @@ -5,7 +5,7 @@ from urllib.parse import urlsplit import freezegun from authlib.jose import jwt from authlib.oauth2.rfc7636 import create_s256_code_challenge -from canaille.models import User +from canaille.core.models import User from canaille.oidc.models import AuthorizationCode from canaille.oidc.models import Consent from canaille.oidc.models import Token diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 32938ed8..5ad554da 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -36,7 +36,7 @@ def test_ldap_connection_remote_ldap_wrong_credentials(testclient, configuration def test_ldap_cannot_create_users(testclient, configuration, slapd_connection): - from canaille.models import User + from canaille.core.models import User def fake_init(*args, **kwarg): raise ldap.INSUFFICIENT_ACCESS @@ -50,7 +50,7 @@ def test_ldap_cannot_create_users(testclient, configuration, slapd_connection): def test_ldap_cannot_create_groups(testclient, configuration, slapd_connection): - from canaille.models import Group + from canaille.core.models import Group def fake_init(*args, **kwarg): raise ldap.INSUFFICIENT_ACCESS diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_apputils.py b/tests/utils/test_apputils.py similarity index 100% rename from tests/test_apputils.py rename to tests/utils/test_apputils.py diff --git a/tests/test_flaskutils.py b/tests/utils/test_flaskutils.py similarity index 100% rename from tests/test_flaskutils.py rename to tests/utils/test_flaskutils.py