diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a4992f48..9c96a50f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,11 +15,12 @@ repos: - id: end-of-file-fixer exclude: "\\.svg$|\\.map$|\\.min\\.css$|\\.min\\.js$|\\.po$|\\.pot$" - id: check-toml - - repo: https://github.com/asottile/reorder_python_imports - rev: v3.12.0 + - repo: https://github.com/pycqa/isort + rev: "5.13.2" hooks: - - id: reorder-python-imports - args: ["--application-directories", "b3desk"] + - id: isort + name: isort (python) + args: ["--force-single-line-imports", "--line-length", "120"] - repo: https://github.com/PyCQA/docformatter rev: v1.7.5 hooks: diff --git a/web/b3desk/__init__.py b/web/b3desk/__init__.py index 61ac6812..13f95d99 100644 --- a/web/b3desk/__init__.py +++ b/web/b3desk/__init__.py @@ -11,8 +11,6 @@ import logging import os -from b3desk.settings import MainSettings -from b3desk.utils import is_rie from flask import Flask from flask import render_template from flask import request @@ -25,6 +23,9 @@ from flask_wtf.csrf import CSRFProtect from jinja2 import StrictUndefined +from b3desk.settings import MainSettings +from b3desk.utils import is_rie + from .utils import model_converter __version__ = "1.1.3" @@ -107,8 +108,8 @@ def setup_database(app): def setup_jinja(app): - from b3desk.session import has_user_session from b3desk.session import get_current_user + from b3desk.session import has_user_session if app.debug or app.testing: app.jinja_env.undefined = StrictUndefined @@ -168,11 +169,11 @@ def internal_error(error): def setup_endpoints(app): with app.app_context(): - import b3desk.endpoints.public - import b3desk.endpoints.join - import b3desk.endpoints.meetings import b3desk.endpoints.api + import b3desk.endpoints.join import b3desk.endpoints.meeting_files + import b3desk.endpoints.meetings + import b3desk.endpoints.public app.register_blueprint(b3desk.endpoints.public.bp) app.register_blueprint(b3desk.endpoints.join.bp) diff --git a/web/b3desk/endpoints/api.py b/web/b3desk/endpoints/api.py index e62cd1f2..2ae3fe35 100644 --- a/web/b3desk/endpoints/api.py +++ b/web/b3desk/endpoints/api.py @@ -1,9 +1,9 @@ -from b3desk.models.users import get_or_create_user from flask import Blueprint from flask import request -from .. import auth +from b3desk.models.users import get_or_create_user +from .. import auth bp = Blueprint("api", __name__) diff --git a/web/b3desk/endpoints/join.py b/web/b3desk/endpoints/join.py index 85bc6e76..d5bc8865 100644 --- a/web/b3desk/endpoints/join.py +++ b/web/b3desk/endpoints/join.py @@ -1,13 +1,7 @@ from datetime import datetime -from b3desk.forms import JoinMailMeetingForm -from b3desk.forms import JoinMeetingForm -from b3desk.models import db -from b3desk.models.meetings import get_mail_meeting -from b3desk.models.meetings import get_meeting_from_meeting_id_and_user_id -from b3desk.models.meetings import Meeting -from flask import abort from flask import Blueprint +from flask import abort from flask import current_app from flask import flash from flask import redirect @@ -16,13 +10,19 @@ from flask import url_for from flask_babel import lazy_gettext as _ +from b3desk.forms import JoinMailMeetingForm +from b3desk.forms import JoinMeetingForm +from b3desk.models import db +from b3desk.models.meetings import Meeting +from b3desk.models.meetings import get_mail_meeting +from b3desk.models.meetings import get_meeting_from_meeting_id_and_user_id + from .. import auth from ..session import get_authenticated_attendee_fullname from ..session import get_current_user from ..session import has_user_session from ..session import meeting_owner_needed - bp = Blueprint("join", __name__) diff --git a/web/b3desk/endpoints/meeting_files.py b/web/b3desk/endpoints/meeting_files.py index c67c47ea..7e3879f4 100644 --- a/web/b3desk/endpoints/meeting_files.py +++ b/web/b3desk/endpoints/meeting_files.py @@ -7,13 +7,8 @@ import filetype import requests -from b3desk.forms import MeetingFilesForm -from b3desk.models import db -from b3desk.models.meetings import Meeting -from b3desk.models.meetings import MeetingFiles -from b3desk.models.meetings import MeetingFilesExternal -from flask import abort from flask import Blueprint +from flask import abort from flask import current_app from flask import flash from flask import jsonify @@ -30,11 +25,16 @@ from webdav3.exceptions import WebDavException from werkzeug.utils import secure_filename +from b3desk.forms import MeetingFilesForm +from b3desk.models import db +from b3desk.models.meetings import Meeting +from b3desk.models.meetings import MeetingFiles +from b3desk.models.meetings import MeetingFilesExternal + from .. import auth from ..session import get_current_user from ..session import meeting_owner_needed - bp = Blueprint("meeting_files", __name__) diff --git a/web/b3desk/endpoints/meetings.py b/web/b3desk/endpoints/meetings.py index 93960685..01340b7d 100644 --- a/web/b3desk/endpoints/meetings.py +++ b/web/b3desk/endpoints/meetings.py @@ -8,17 +8,8 @@ # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. -from b3desk.forms import EndMeetingForm -from b3desk.forms import MeetingForm -from b3desk.forms import MeetingWithRecordForm -from b3desk.forms import RecordingForm -from b3desk.forms import ShowMeetingForm -from b3desk.models import db -from b3desk.models.meetings import get_quick_meeting_from_user_and_random_string -from b3desk.models.meetings import Meeting -from b3desk.models.users import User -from flask import abort from flask import Blueprint +from flask import abort from flask import current_app from flask import flash from flask import redirect @@ -27,6 +18,16 @@ from flask import url_for from flask_babel import lazy_gettext as _ +from b3desk.forms import EndMeetingForm +from b3desk.forms import MeetingForm +from b3desk.forms import MeetingWithRecordForm +from b3desk.forms import RecordingForm +from b3desk.forms import ShowMeetingForm +from b3desk.models import db +from b3desk.models.meetings import Meeting +from b3desk.models.meetings import get_quick_meeting_from_user_and_random_string +from b3desk.models.users import User + from .. import auth from ..session import get_current_user from ..session import meeting_owner_needed @@ -34,7 +35,6 @@ from ..utils import is_valid_email from ..utils import send_quick_meeting_mail - bp = Blueprint("meetings", __name__) diff --git a/web/b3desk/endpoints/public.py b/web/b3desk/endpoints/public.py index 5d4c9a71..7f82f4b1 100644 --- a/web/b3desk/endpoints/public.py +++ b/web/b3desk/endpoints/public.py @@ -12,7 +12,6 @@ from ..templates.content import FAQ_CONTENT from .meetings import meeting_mailto_params - bp = Blueprint("public", __name__) diff --git a/web/b3desk/models/bbb.py b/web/b3desk/models/bbb.py index 0efa6cd1..9db7fd4a 100644 --- a/web/b3desk/models/bbb.py +++ b/web/b3desk/models/bbb.py @@ -14,11 +14,12 @@ from xml.etree import ElementTree import requests -from b3desk.tasks import background_upload from flask import current_app from flask import render_template from flask import url_for +from b3desk.tasks import background_upload + class BBB: """Interface to BBB API.""" diff --git a/web/b3desk/models/meetings.py b/web/b3desk/models/meetings.py index 4457c632..7b531454 100644 --- a/web/b3desk/models/meetings.py +++ b/web/b3desk/models/meetings.py @@ -12,12 +12,13 @@ from datetime import datetime from datetime import timedelta -from b3desk.utils import get_random_alphanumeric_string -from b3desk.utils import secret_key from flask import current_app from flask import url_for from sqlalchemy_utils import StringEncryptedType +from b3desk.utils import get_random_alphanumeric_string +from b3desk.utils import secret_key + from . import db from .users import User diff --git a/web/b3desk/models/users.py b/web/b3desk/models/users.py index 968946f3..c40d470f 100644 --- a/web/b3desk/models/users.py +++ b/web/b3desk/models/users.py @@ -15,9 +15,10 @@ from urllib.parse import urlunparse import requests -from b3desk.utils import secret_key from flask import current_app +from b3desk.utils import secret_key + from . import db diff --git a/web/b3desk/session.py b/web/b3desk/session.py index 9456faa0..2394e9b7 100644 --- a/web/b3desk/session.py +++ b/web/b3desk/session.py @@ -1,12 +1,13 @@ from functools import wraps -from b3desk.models.users import get_or_create_user from flask import abort from flask import current_app from flask import g from flask import session from flask_pyoidc.user_session import UserSession +from b3desk.models.users import get_or_create_user + def get_current_user(): if "user" not in g: diff --git a/web/b3desk/settings.py b/web/b3desk/settings.py index 7f3fd9b2..e238284f 100644 --- a/web/b3desk/settings.py +++ b/web/b3desk/settings.py @@ -4,14 +4,15 @@ from typing import List from typing import Optional -from b3desk.constants import DEFAULT_EMAIL_WHITELIST from flask_babel import lazy_gettext as _ +from pydantic import ValidationInfo from pydantic import computed_field from pydantic import field_validator -from pydantic import ValidationInfo from pydantic_settings import BaseSettings from pydantic_settings import SettingsConfigDict +from b3desk.constants import DEFAULT_EMAIL_WHITELIST + AVAILABLE_WORDINGS = { "MEETING": {"cours": "cours", "reunion": "réunion", "seminaire": "séminaire"}, "MEETINGS": {"cours": "cours", "reunion": "réunions", "seminaire": "séminaires"}, diff --git a/web/b3desk/utils.py b/web/b3desk/utils.py index 13790723..bbb01faa 100644 --- a/web/b3desk/utils.py +++ b/web/b3desk/utils.py @@ -5,7 +5,6 @@ from email.message import EmailMessage from email.mime.text import MIMEText -from b3desk.models import db from flask import abort from flask import current_app from flask import render_template @@ -15,6 +14,8 @@ from netaddr import IPNetwork from werkzeug.routing import BaseConverter +from b3desk.models import db + def secret_key(): return current_app.config["SECRET_KEY"] diff --git a/web/migrations/alembic_helpers.py b/web/migrations/alembic_helpers.py index 2c1b5266..8f510911 100644 --- a/web/migrations/alembic_helpers.py +++ b/web/migrations/alembic_helpers.py @@ -1,7 +1,7 @@ # Code based on https://github.com/talkpython/data-driven-web-apps-with-flask from alembic import op -from sqlalchemy import engine_from_config from sqlalchemy import MetaData +from sqlalchemy import engine_from_config def load_schema(): diff --git a/web/migrations/versions/1094e771bd3f_create_meeting_files_table.py b/web/migrations/versions/1094e771bd3f_create_meeting_files_table.py index a38376f2..bd7c607a 100644 --- a/web/migrations/versions/1094e771bd3f_create_meeting_files_table.py +++ b/web/migrations/versions/1094e771bd3f_create_meeting_files_table.py @@ -4,6 +4,7 @@ Revises: 8fe077ecfb10 Create Date: 2023-02-28 14:30:43.642893 """ + import os import sys @@ -16,7 +17,6 @@ import alembic_helpers - # revision identifiers, used by Alembic. revision = "1094e771bd3f" down_revision = "8fe077ecfb10" diff --git a/web/migrations/versions/54f71a7705a8_initial_tables2.py b/web/migrations/versions/54f71a7705a8_initial_tables2.py index 391dd6d3..979ab6cb 100644 --- a/web/migrations/versions/54f71a7705a8_initial_tables2.py +++ b/web/migrations/versions/54f71a7705a8_initial_tables2.py @@ -4,6 +4,7 @@ Revises: Create Date: 2023-01-03 18:01:03.770238 """ + import os import sys diff --git a/web/migrations/versions/65acbe9b0646_add_user_nextcloud_connection_info.py b/web/migrations/versions/65acbe9b0646_add_user_nextcloud_connection_info.py index b07622c1..df6c8065 100644 --- a/web/migrations/versions/65acbe9b0646_add_user_nextcloud_connection_info.py +++ b/web/migrations/versions/65acbe9b0646_add_user_nextcloud_connection_info.py @@ -4,6 +4,7 @@ Revises: 1094e771bd3f Create Date: 2023-02-28 14:35:21.691915 """ + import os import sys @@ -16,7 +17,6 @@ import alembic_helpers - # revision identifiers, used by Alembic. revision = "65acbe9b0646" down_revision = "1094e771bd3f" diff --git a/web/migrations/versions/7d80b9223a1e_guestpolicy_migration.py b/web/migrations/versions/7d80b9223a1e_guestpolicy_migration.py index 9748c37d..2c9467d4 100644 --- a/web/migrations/versions/7d80b9223a1e_guestpolicy_migration.py +++ b/web/migrations/versions/7d80b9223a1e_guestpolicy_migration.py @@ -4,6 +4,7 @@ Revises: 54f71a7705a8 Create Date: 2023-02-28 14:29:28.456201 """ + import os import sys @@ -16,7 +17,6 @@ import alembic_helpers - # revision identifiers, used by Alembic. revision = "7d80b9223a1e" down_revision = "54f71a7705a8" diff --git a/web/migrations/versions/8fe077ecfb10_add_last_connection_utc_datetime.py b/web/migrations/versions/8fe077ecfb10_add_last_connection_utc_datetime.py index 04bfd63a..08fa9abb 100644 --- a/web/migrations/versions/8fe077ecfb10_add_last_connection_utc_datetime.py +++ b/web/migrations/versions/8fe077ecfb10_add_last_connection_utc_datetime.py @@ -4,6 +4,7 @@ Revises: 9aac3b5e1582 Create Date: 2022-08-12 09:09:47.674373 """ + import os import sys @@ -16,7 +17,6 @@ import alembic_helpers - # revision identifiers, used by Alembic. revision = "8fe077ecfb10" down_revision = "9aac3b5e1582" diff --git a/web/migrations/versions/9aac3b5e1582_welcome_message_unbound.py b/web/migrations/versions/9aac3b5e1582_welcome_message_unbound.py index aeae1bb8..2292b2a3 100644 --- a/web/migrations/versions/9aac3b5e1582_welcome_message_unbound.py +++ b/web/migrations/versions/9aac3b5e1582_welcome_message_unbound.py @@ -4,6 +4,7 @@ Revises: 7d80b9223a1e Create Date: 2021-05-06 17:44:17.835474 """ + import os import sys diff --git a/web/migrations/versions/9d4ba8cf710a_remove_obsolete_meeting_attributes.py b/web/migrations/versions/9d4ba8cf710a_remove_obsolete_meeting_attributes.py index ad0cc2d2..ccdc4f30 100644 --- a/web/migrations/versions/9d4ba8cf710a_remove_obsolete_meeting_attributes.py +++ b/web/migrations/versions/9d4ba8cf710a_remove_obsolete_meeting_attributes.py @@ -4,10 +4,10 @@ Revises: 65acbe9b0646 Create Date: 2022-08-12 15:43:01.721995 """ + import sqlalchemy as sa from alembic import op - # revision identifiers, used by Alembic. revision = "9d4ba8cf710a" down_revision = "65acbe9b0646" diff --git a/web/misc/gunicorn.py b/web/misc/gunicorn.py index 89f4b8f0..658c5b05 100644 --- a/web/misc/gunicorn.py +++ b/web/misc/gunicorn.py @@ -202,8 +202,8 @@ def when_ready(server): def worker_int(worker): worker.log.info("worker received INT or QUIT signal") ## get traceback info - import threading import sys + import threading import traceback id2name = {th.ident: th.name for th in threading.enumerate()} diff --git a/web/tests/conftest.py b/web/tests/conftest.py index 5753c6ba..692b3a23 100644 --- a/web/tests/conftest.py +++ b/web/tests/conftest.py @@ -4,15 +4,16 @@ import wsgiref from pathlib import Path -import b3desk.utils import portpicker import pytest -from b3desk import create_app from flask_migrate import Migrate from flask_webtest import TestApp from wsgidav.fs_dav_provider import FilesystemProvider from wsgidav.wsgidav_app import WsgiDAVApp +import b3desk.utils +from b3desk import create_app + b3desk.utils.secret_key = lambda: "AZERTY" from b3desk.models import db diff --git a/web/tests/meeting/test_meeting.py b/web/tests/meeting/test_meeting.py index 73cc5a4b..f4ccbbcb 100644 --- a/web/tests/meeting/test_meeting.py +++ b/web/tests/meeting/test_meeting.py @@ -3,9 +3,10 @@ from urllib.parse import urlparse import pytest + from b3desk.models import db -from b3desk.models.meetings import Meeting from b3desk.models.meetings import MODERATOR_ONLY_MESSAGE_MAXLENGTH +from b3desk.models.meetings import Meeting @pytest.fixture() diff --git a/web/tests/test_authentication.py b/web/tests/test_authentication.py index d66031f0..0d03eecc 100644 --- a/web/tests/test_authentication.py +++ b/web/tests/test_authentication.py @@ -1,4 +1,5 @@ import requests + from b3desk.models import db from b3desk.models.users import User diff --git a/web/tests/test_user.py b/web/tests/test_user.py index a464e579..944f7aca 100644 --- a/web/tests/test_user.py +++ b/web/tests/test_user.py @@ -1,11 +1,12 @@ from datetime import date import pytest +from freezegun import freeze_time + from b3desk.models import db +from b3desk.models.users import User from b3desk.models.users import get_or_create_user from b3desk.models.users import make_nextcloud_credentials_request -from b3desk.models.users import User -from freezegun import freeze_time def test_get_or_create_user(client_app):