diff --git a/app/forms/main/config_main.py b/app/forms/main/config_main.py index 68b161eb..1b2c131c 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 6164de3a..0397c6a4 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 fe774303..604310fc 100644 --- a/app/templates/configuration.j2 +++ b/app/templates/configuration.j2 @@ -26,7 +26,7 @@