diff --git a/pyproject.toml b/pyproject.toml index cc62512e..04b5d2eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,8 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.poetry] -version = "1.2.0" +name = "b3desk" +version = "1.2.1" description = "Outil de visioconférence pour les agents de l'Education Nationale et de l'Etat en général." authors = ["Your Name "] readme = "README.md" diff --git a/web/b3desk/__init__.py b/web/b3desk/__init__.py index 3bb75fc6..085eb43f 100644 --- a/web/b3desk/__init__.py +++ b/web/b3desk/__init__.py @@ -29,7 +29,7 @@ from .utils import enum_converter from .utils import model_converter -__version__ = "1.2.0" +__version__ = "1.2.1" LANGUAGES = ["en", "fr"] diff --git a/web/b3desk/settings.py b/web/b3desk/settings.py index df22b93d..32d6a318 100644 --- a/web/b3desk/settings.py +++ b/web/b3desk/settings.py @@ -1,11 +1,13 @@ import datetime import json +from typing import Annotated from typing import Any from typing import Dict from typing import List from typing import Optional from flask_babel import lazy_gettext as _ +from pydantic import BeforeValidator from pydantic import ValidationInfo from pydantic import computed_field from pydantic import field_validator @@ -14,6 +16,17 @@ from b3desk.constants import DEFAULT_EMAIL_WHITELIST + +def split_comma_separated_strings(value): + if not isinstance(value, str): + return value + + return map(str.strip, value.split(",")) + + +ListOfStrings = Annotated[List[str], BeforeValidator(split_comma_separated_strings)] + + AVAILABLE_WORDINGS = { "MEETING": {"cours": "cours", "reunion": "réunion", "seminaire": "séminaire"}, "MEETINGS": {"cours": "cours", "reunion": "réunions", "seminaire": "séminaires"}, @@ -289,7 +302,7 @@ def get_allowed_mime_types_server_side( OIDC_OPENID_REALM: str = "apps" """Probablement un relicat de flask-oidc, semble inutilisé.""" - OIDC_SCOPES: List[str] = ["openid", "email", "profile"] + OIDC_SCOPES: ListOfStrings = ["openid", "email", "profile"] """Liste des scopes OpenID Connect pour lesquels une autorisation sera demandée au serveur d’identité, séparés par des virgules. @@ -297,10 +310,6 @@ def get_allowed_mime_types_server_side( Plus d’infos sur https://flask-pyoidc.readthedocs.io/en/latest/api.html#module-flask_pyoidc.provider_configuration """ - @field_validator("OIDC_SCOPES", mode="before") - def get_oidc_scopes(cls, oidc_scopes: List[str], info: ValidationInfo) -> str: - return oidc_scopes.split(",") if isinstance(oidc_scopes, str) else oidc_scopes - OIDC_USERINFO_HTTP_METHOD: str = "POST" """Méthode ``GET`` ou ``POST`` à utiliser pour les requêtes sur le point d’entrée *UserInfo* du serveur d’identité. @@ -415,7 +424,7 @@ def get_oidc_scopes(cls, oidc_scopes: List[str], info: ValidationInfo) -> str: Si non renseigné, prend la valeur de ``OIDC_SERVICE_NAME``. """ - OIDC_ATTENDEE_SCOPES: Optional[List[str]] = None + OIDC_ATTENDEE_SCOPES: Optional[ListOfStrings] = None """Liste des scopes OpenID Connect pour lesquels une autorisation sera demandée au serveur d’identité des participants authentifiés, séparés par des virgules. @@ -474,8 +483,7 @@ def get_attendee_attendee_service_name( def get_attendee_attendee_scopes( cls, attendee_scopes: str, info: ValidationInfo ) -> str: - scopes = attendee_scopes or info.data.get("OIDC_SCOPES") - return scopes.split(",") if isinstance(scopes, str) else scopes + return attendee_scopes or info.data.get("OIDC_SCOPES") DOCUMENTATION_LINK_URL: Optional[str] = None """Surcharge l’adresse de la page de documentation si renseigné.""" @@ -967,23 +975,13 @@ def get_email_whitelist( https://docs.bigbluebutton.org/development/api/#create """ - RIE_NETWORK_IPS: Optional[List[str]] = None + RIE_NETWORK_IPS: Optional[ListOfStrings] = None """Plages d’adresses IP du réseau interministériel de l'État. Affiche un encart particulier pour les utilisateurs se connectant depuis ce réseau. """ - @field_validator("RIE_NETWORK_IPS", mode="before") - def get_rie_network_ips( - cls, rie_network_ips: List[str], info: ValidationInfo - ) -> str: - return ( - rie_network_ips.split(",") - if isinstance(rie_network_ips, str) - else rie_network_ips - ) - MAX_PARTICIPANTS: int = 200 """Nombre moyen de participants indicatif sur la plateforme. diff --git a/web/tests/test_settings.py b/web/tests/test_settings.py new file mode 100644 index 00000000..a85dc767 --- /dev/null +++ b/web/tests/test_settings.py @@ -0,0 +1,11 @@ +from b3desk.settings import MainSettings + + +def test_list_of_strings_type(configuration): + configuration["OIDC_SCOPES"] = "openid, profile, ect.scope.cv" + configuration["OIDC_ATTENDEE_SCOPES"] = "openid, profile, ect.scope.cv" + + config_obj = MainSettings.model_validate(configuration) + + assert config_obj.OIDC_SCOPES == ["openid", "profile", "ect.scope.cv"] + assert config_obj.OIDC_ATTENDEE_SCOPES == ["openid", "profile", "ect.scope.cv"]