From bd0df7c50308e1279813a4abc389f32e74fc0c89 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 2 Sep 2023 22:49:21 +0200 Subject: [PATCH] Option pour autoriser le CAS aux nouveaux utilisateurs: implements #701 --- app/forms/main/config_cas.py | 3 +++ app/templates/config_cas.j2 | 1 + app/views/scodoc.py | 10 ++++++++++ app/views/users.py | 7 +++++++ 4 files changed, 21 insertions(+) diff --git a/app/forms/main/config_cas.py b/app/forms/main/config_cas.py index 9ebf2d871..f68aa3ccb 100644 --- a/app/forms/main/config_cas.py +++ b/app/forms/main/config_cas.py @@ -40,6 +40,9 @@ class ConfigCASForm(FlaskForm): cas_force = BooleanField( "Forcer l'utilisation de CAS (tous les utilisateurs seront redirigés vers le CAS)" ) + cas_allow_for_new_users = BooleanField( + "Par défaut, autoriser le CAS aux nouveaux utilisateurs" + ) cas_server = StringField( label="URL du serveur CAS", diff --git a/app/templates/config_cas.j2 b/app/templates/config_cas.j2 index 6ca3020ba..ce45cfa67 100644 --- a/app/templates/config_cas.j2 +++ b/app/templates/config_cas.j2 @@ -17,6 +17,7 @@ {{ wtf.form_field(form.cas_enable) }} {{ wtf.form_field(form.cas_force) }} + {{ wtf.form_field(form.cas_allow_for_new_users) }} {{ wtf.form_field(form.cas_server) }} {{ wtf.form_field(form.cas_login_route) }} {{ wtf.form_field(form.cas_logout_route) }} diff --git a/app/views/scodoc.py b/app/views/scodoc.py index 41af54d6d..214ea4261 100644 --- a/app/views/scodoc.py +++ b/app/views/scodoc.py @@ -156,6 +156,13 @@ def config_cas(): flash("CAS " + ("activé" if form.data["cas_enable"] else "désactivé")) if ScoDocSiteConfig.set("cas_force", form.data["cas_force"]): flash("CAS " + ("forcé" if form.data["cas_force"] else "non forcé")) + if ScoDocSiteConfig.set( + "cas_allow_for_new_users", form.data["cas_allow_for_new_users"] + ): + flash( + f"""CAS {'' if form.data['cas_allow_for_new_users'] else 'non' + } autorisé par défaut aux nouveaux""" + ) if ScoDocSiteConfig.set("cas_server", form.data["cas_server"]): flash("URL du serveur CAS enregistrée") if ScoDocSiteConfig.set("cas_login_route", form.data["cas_login_route"]): @@ -182,6 +189,9 @@ def config_cas(): elif request.method == "GET": form.cas_enable.data = ScoDocSiteConfig.get("cas_enable") form.cas_force.data = ScoDocSiteConfig.get("cas_force") + form.cas_allow_for_new_users.data = ScoDocSiteConfig.get( + "cas_allow_for_new_users" + ) form.cas_server.data = ScoDocSiteConfig.get("cas_server") form.cas_login_route.data = ScoDocSiteConfig.get("cas_login_route") form.cas_logout_route.data = ScoDocSiteConfig.get("cas_logout_route") diff --git a/app/views/users.py b/app/views/users.py index 31c6bf45d..6b179532b 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -371,6 +371,12 @@ def create_user_form(user_name=None, edit=0, all_roles=True): ) ] cas_enabled = ScoDocSiteConfig.is_cas_enabled() + if edit: + cas_allow_login_default = the_user.cas_allow_login + else: + cas_allow_login_default = int( + bool(ScoDocSiteConfig.get("cas_allow_for_new_users")) + ) descr += [ ( "email", @@ -408,6 +414,7 @@ def create_user_form(user_name=None, edit=0, all_roles=True): "explanation": """ si CAS est activé. Seul le super-administrateur peut changer ce réglage.""", "enabled": current_user.is_administrator(), + "default": cas_allow_login_default, }, ), (