Update opolka/ScoDoc from ScoDoc/ScoDoc #2

Merged
opolka merged 1272 commits from ScoDoc/ScoDoc:master into master 2024-05-27 09:11:04 +02:00
4 changed files with 42 additions and 31 deletions
Showing only changes of commit ac9b5722cf - Show all commits

View File

@ -77,6 +77,9 @@ class ScoDocConfigurationForm(FlaskForm):
Attention: si ce champ peut aussi être défini dans chaque département.""", Attention: si ce champ peut aussi être défini dans chaque département.""",
validators=[Optional(), Email()], 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( disable_bul_pdf = BooleanField(
"interdire les exports des bulletins en PDF (déconseillé)" "interdire les exports des bulletins en PDF (déconseillé)"
) )
@ -99,6 +102,7 @@ def configuration():
"month_debut_periode2": ScoDocSiteConfig.get_month_debut_periode2(), "month_debut_periode2": ScoDocSiteConfig.get_month_debut_periode2(),
"email_from_addr": ScoDocSiteConfig.get("email_from_addr"), "email_from_addr": ScoDocSiteConfig.get("email_from_addr"),
"disable_bul_pdf": ScoDocSiteConfig.is_bul_pdf_disabled(), "disable_bul_pdf": ScoDocSiteConfig.is_bul_pdf_disabled(),
"user_require_email_institutionnel": ScoDocSiteConfig.is_user_require_email_institutionnel_enabled(),
} }
) )
if request.method == "POST" and ( if request.method == "POST" and (
@ -151,6 +155,18 @@ def configuration():
"Exports PDF " "Exports PDF "
+ ("désactivés" if form_scodoc.data["disable_bul_pdf"] else "réactivés") + ("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 redirect(url_for("scodoc.index"))
return render_template( return render_template(

View File

@ -95,6 +95,7 @@ class ScoDocSiteConfig(db.Model):
"month_debut_annee_scolaire": int, "month_debut_annee_scolaire": int,
"month_debut_periode2": int, "month_debut_periode2": int,
"disable_bul_pdf": bool, "disable_bul_pdf": bool,
"user_require_email_institutionnel": bool,
# CAS # CAS
"cas_enable": bool, "cas_enable": bool,
"cas_server": str, "cas_server": str,
@ -243,6 +244,14 @@ class ScoDocSiteConfig(db.Model):
cfg = ScoDocSiteConfig.query.filter_by(name="enable_entreprises").first() cfg = ScoDocSiteConfig.query.filter_by(name="enable_entreprises").first()
return cfg is not None and cfg.value 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 @classmethod
def is_bul_pdf_disabled(cls) -> bool: def is_bul_pdf_disabled(cls) -> bool:
"""True si on interdit les exports PDF des bulltins""" """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 return cfg is not None and cfg.value
@classmethod @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.""" """Active (ou déactive) le module entreprises. True si changement."""
if enabled != ScoDocSiteConfig.is_entreprises_enabled(): return cls.set("enable_entreprises", "on" if enabled else "")
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
@classmethod @classmethod
def disable_bul_pdf(cls, enabled=True) -> bool: def disable_bul_pdf(cls, enabled=True) -> bool:
"""Interedit (ou autorise) les exports PDF. True si changement.""" """Interdit (ou autorise) les exports PDF. True si changement."""
if enabled != ScoDocSiteConfig.is_bul_pdf_disabled(): return cls.set("disable_bul_pdf", "on" if enabled else "")
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
@classmethod @classmethod
def get(cls, name: str, default: str = "") -> str: def get(cls, name: str, default: str = "") -> str:
@ -298,9 +285,10 @@ class ScoDocSiteConfig(db.Model):
if cfg is None: if cfg is None:
cfg = ScoDocSiteConfig(name=name, value=value_str) cfg = ScoDocSiteConfig(name=name, value=value_str)
else: else:
cfg.value = str(value or "") cfg.value = value_str
current_app.logger.info( 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.add(cfg)
db.session.commit() db.session.commit()

View File

@ -26,7 +26,7 @@
<div class="sco_help"><div style="font-style: normal;"> <div class="sco_help"><div style="font-style: normal;">
Heure: <b><tt>{{ time.strftime("%d/%m/%Y %H:%M") }}</tt></b> Heure: <b><tt>{{ time.strftime("%d/%m/%Y %H:%M") }}</tt></b>
<em>(devrait être l'heure de votre montre, sinon vérifiez que le serveur est bien en heure légale de votre pays)</em> <em>(devrait être l'heure aux montres des étudiants, sinon vérifiez que le serveur est bien en heure légale de votre pays)</em>
</div> </div>
</div> </div>

View File

@ -382,6 +382,9 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
cas_allow_login_default = int( cas_allow_login_default = int(
bool(ScoDocSiteConfig.get("cas_allow_for_new_users")) bool(ScoDocSiteConfig.get("cas_allow_for_new_users"))
) )
require_email_institutionnel = (
ScoDocSiteConfig.is_user_require_email_institutionnel_enabled()
)
descr += [ descr += [
( (
"email", "email",
@ -444,9 +447,13 @@ def create_user_form(user_name=None, edit=0, all_roles=True):
{ {
"title": "e-mail institutionnel", "title": "e-mail institutionnel",
"input_type": "text", "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, "size": 36,
"allow_null": True, "allow_null": not require_email_institutionnel,
"readonly": edit_only_roles, "readonly": edit_only_roles,
}, },
), ),