From ac9b5722cf8291fd098d988813ea2abcf2e6e0a3 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 9 Jan 2024 19:56:05 +0100 Subject: [PATCH] Option de config globale pour imposer saisie du mail institutionnel dans le formulaire --- app/forms/main/config_main.py | 16 +++++++++++++ app/models/config.py | 44 +++++++++++++--------------------- app/templates/configuration.j2 | 2 +- app/views/users.py | 11 +++++++-- 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/app/forms/main/config_main.py b/app/forms/main/config_main.py index 68b161ebb..1b2c131c7 100644 --- a/app/forms/main/config_main.py +++ b/app/forms/main/config_main.py @@ -77,6 +77,9 @@ class ScoDocConfigurationForm(FlaskForm): Attention: si ce champ peut aussi être défini dans chaque département.""", validators=[Optional(), Email()], ) + user_require_email_institutionnel = BooleanField( + "imposer la saisie du mail institutionnel dans le formulaire de création utilisateur" + ) disable_bul_pdf = BooleanField( "interdire les exports des bulletins en PDF (déconseillé)" ) @@ -99,6 +102,7 @@ def configuration(): "month_debut_periode2": ScoDocSiteConfig.get_month_debut_periode2(), "email_from_addr": ScoDocSiteConfig.get("email_from_addr"), "disable_bul_pdf": ScoDocSiteConfig.is_bul_pdf_disabled(), + "user_require_email_institutionnel": ScoDocSiteConfig.is_user_require_email_institutionnel_enabled(), } ) if request.method == "POST" and ( @@ -151,6 +155,18 @@ def configuration(): "Exports PDF " + ("désactivés" if form_scodoc.data["disable_bul_pdf"] else "réactivés") ) + if ScoDocSiteConfig.set( + "user_require_email_institutionnel", + "on" if form_scodoc.data["user_require_email_institutionnel"] else "", + ): + flash( + ( + "impose" + if form_scodoc.data["user_require_email_institutionnel"] + else "n'impose pas" + ) + + " la saisie du mail institutionnel des utilisateurs" + ) return redirect(url_for("scodoc.index")) return render_template( diff --git a/app/models/config.py b/app/models/config.py index 6164de3ad..0397c6a4e 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -95,6 +95,7 @@ class ScoDocSiteConfig(db.Model): "month_debut_annee_scolaire": int, "month_debut_periode2": int, "disable_bul_pdf": bool, + "user_require_email_institutionnel": bool, # CAS "cas_enable": bool, "cas_server": str, @@ -243,6 +244,14 @@ class ScoDocSiteConfig(db.Model): cfg = ScoDocSiteConfig.query.filter_by(name="enable_entreprises").first() return cfg is not None and cfg.value + @classmethod + def is_user_require_email_institutionnel_enabled(cls) -> bool: + """True si impose saisie email_institutionnel""" + cfg = ScoDocSiteConfig.query.filter_by( + name="user_require_email_institutionnel" + ).first() + return cfg is not None and cfg.value + @classmethod def is_bul_pdf_disabled(cls) -> bool: """True si on interdit les exports PDF des bulltins""" @@ -250,36 +259,14 @@ class ScoDocSiteConfig(db.Model): return cfg is not None and cfg.value @classmethod - def enable_entreprises(cls, enabled=True) -> bool: + def enable_entreprises(cls, enabled: bool = True) -> bool: """Active (ou déactive) le module entreprises. True si changement.""" - if enabled != ScoDocSiteConfig.is_entreprises_enabled(): - cfg = ScoDocSiteConfig.query.filter_by(name="enable_entreprises").first() - if cfg is None: - cfg = ScoDocSiteConfig( - name="enable_entreprises", value="on" if enabled else "" - ) - else: - cfg.value = "on" if enabled else "" - db.session.add(cfg) - db.session.commit() - return True - return False + return cls.set("enable_entreprises", "on" if enabled else "") @classmethod def disable_bul_pdf(cls, enabled=True) -> bool: - """Interedit (ou autorise) les exports PDF. True si changement.""" - if enabled != ScoDocSiteConfig.is_bul_pdf_disabled(): - cfg = ScoDocSiteConfig.query.filter_by(name="disable_bul_pdf").first() - if cfg is None: - cfg = ScoDocSiteConfig( - name="disable_bul_pdf", value="on" if enabled else "" - ) - else: - cfg.value = "on" if enabled else "" - db.session.add(cfg) - db.session.commit() - return True - return False + """Interdit (ou autorise) les exports PDF. True si changement.""" + return cls.set("disable_bul_pdf", "on" if enabled else "") @classmethod def get(cls, name: str, default: str = "") -> str: @@ -298,9 +285,10 @@ class ScoDocSiteConfig(db.Model): if cfg is None: cfg = ScoDocSiteConfig(name=name, value=value_str) else: - cfg.value = str(value or "") + cfg.value = value_str current_app.logger.info( - f"""ScoDocSiteConfig: recording {cfg.name}='{cfg.value[:32]}...'""" + f"""ScoDocSiteConfig: recording {cfg.name}='{cfg.value[:32]}{ + '...' if len(cfg.value)>32 else ''}'""" ) db.session.add(cfg) db.session.commit() diff --git a/app/templates/configuration.j2 b/app/templates/configuration.j2 index fe7743035..604310fcd 100644 --- a/app/templates/configuration.j2 +++ b/app/templates/configuration.j2 @@ -26,7 +26,7 @@
Heure: {{ time.strftime("%d/%m/%Y %H:%M") }} -(devrait être l'heure de votre montre, sinon vérifiez que le serveur est bien en heure légale de votre pays) +(devrait être l'heure aux montres des étudiants, sinon vérifiez que le serveur est bien en heure légale de votre pays)
diff --git a/app/views/users.py b/app/views/users.py index 03785d759..241190111 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -382,6 +382,9 @@ def create_user_form(user_name=None, edit=0, all_roles=True): cas_allow_login_default = int( bool(ScoDocSiteConfig.get("cas_allow_for_new_users")) ) + require_email_institutionnel = ( + ScoDocSiteConfig.is_user_require_email_institutionnel_enabled() + ) descr += [ ( "email", @@ -444,9 +447,13 @@ def create_user_form(user_name=None, edit=0, all_roles=True): { "title": "e-mail institutionnel", "input_type": "text", - "explanation": "facultatif" if not edit_only_roles else "", + "explanation": ( + "requis" if require_email_institutionnel else "facultatif" + ) + if not edit_only_roles + else "", "size": 36, - "allow_null": True, + "allow_null": not require_email_institutionnel, "readonly": edit_only_roles, }, ),