From 8c0c4139dfd51b7c23b7be90e6a2eb4c6d35fe45 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Thu, 2 Mar 2023 23:29:25 +0100 Subject: [PATCH] CAS: config routes login/logout/validate --- app/auth/cas.py | 7 +++++++ app/forms/main/config_cas.py | 15 +++++++++++++++ app/models/config.py | 11 ++++++++--- app/views/scodoc.py | 6 ++++++ app/views/scolar.py | 25 +++++++++++++++++++++++++ flask_cas/routing.py | 1 - 6 files changed, 61 insertions(+), 4 deletions(-) diff --git a/app/auth/cas.py b/app/auth/cas.py index 2f231d2a..01b6c10f 100644 --- a/app/auth/cas.py +++ b/app/auth/cas.py @@ -85,6 +85,13 @@ def set_cas_configuration(app: flask.app.Flask = None): if ScoDocSiteConfig.is_cas_enabled(): current_app.logger.debug("CAS: set_cas_configuration") app.config["CAS_SERVER"] = ScoDocSiteConfig.get("cas_server") + app.config["CAS_LOGIN_ROUTE"] = ScoDocSiteConfig.get("cas_login_route", "/cas") + app.config["CAS_LOGOUT_ROUTE"] = ScoDocSiteConfig.get( + "cas_logout_route", "/cas/logout" + ) + app.config["CAS_VALIDATE_ROUTE"] = ScoDocSiteConfig.get( + "cas_validate_route", "/cas/serviceValidate" + ) app.config["CAS_AFTER_LOGIN"] = "auth.after_cas_login" app.config["CAS_AFTER_LOGOUT"] = "auth.after_cas_logout" app.config["CAS_ERROR_CALLBACK"] = cas_error_callback diff --git a/app/forms/main/config_cas.py b/app/forms/main/config_cas.py index 5b6020b8..0c6baac4 100644 --- a/app/forms/main/config_cas.py +++ b/app/forms/main/config_cas.py @@ -45,6 +45,21 @@ class ConfigCASForm(FlaskForm): label="URL du serveur CAS", description="""url complète. Commence en général par https://.""", ) + cas_login_route = StringField( + label="Route du login CAS", + description="""ajouté à l'URL du serveur: exemple /cas (si commence par /, part de la racine)""", + default="/cas", + ) + cas_logout_route = StringField( + label="Route du logout CAS", + description="""ajouté à l'URL du serveur: exemple /cas/logout""", + default="/cas/logout", + ) + cas_validate_route = StringField( + label="Route de validation CAS", + description="""ajouté à l'URL du serveur: exemple /cas/serviceValidate""", + default="/cas/serviceValidate", + ) cas_attribute_id = StringField( label="Attribut CAS utilisé comme id (laissez vide pour prendre l'id par défaut)", diff --git a/app/models/config.py b/app/models/config.py index de46f95b..09699cf7 100644 --- a/app/models/config.py +++ b/app/models/config.py @@ -90,6 +90,9 @@ class ScoDocSiteConfig(db.Model): # CAS "cas_enable": bool, "cas_server": str, + "cas_login_route": str, + "cas_logout_route": str, + "cas_valmidate_route": str, "cas_attribute_id": str, } @@ -237,10 +240,12 @@ class ScoDocSiteConfig(db.Model): return False @classmethod - def get(cls, name: str) -> str: - "Get configuration param; empty string if unset" + def get(cls, name: str, default: str = "") -> str: + "Get configuration param; empty string or specified default if unset" cfg = ScoDocSiteConfig.query.filter_by(name=name).first() - return (cfg.value or "") if cfg else "" + if cfg is None: + return default + return cfg.value or "" @classmethod def set(cls, name: str, value: str) -> bool: diff --git a/app/views/scodoc.py b/app/views/scodoc.py index f298026a..915287f0 100644 --- a/app/views/scodoc.py +++ b/app/views/scodoc.py @@ -150,6 +150,12 @@ def config_cas(): flash("CAS " + ("forcé" if form.data["cas_force"] else "non forcé")) if ScoDocSiteConfig.set("cas_server", form.data["cas_server"]): flash("Serveur CAS enregistré") + if ScoDocSiteConfig.set("cas_login_route", form.data["cas_login_route"]): + flash("Serveur CAS enregistré") + if ScoDocSiteConfig.set("cas_logout_route", form.data["cas_logout_route"]): + flash("Serveur CAS enregistré") + if ScoDocSiteConfig.set("cas_validate_route", form.data["cas_validate_route"]): + flash("Serveur CAS enregistré") if ScoDocSiteConfig.set("cas_attribute_id", form.data["cas_attribute_id"]): flash("Serveur CAS enregistré") if ScoDocSiteConfig.set("cas_ssl_verify", form.data["cas_ssl_verify"]): diff --git a/app/views/scolar.py b/app/views/scolar.py index 03e158c4..62006616 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -928,6 +928,31 @@ def partition_editor(formsemestre_id: int): return "\n".join(H) +# Future page pour répartition parcours +@bp.route("/students_groups_auto_assignment", methods=["GET", "POST"]) +@scodoc +@permission_required(Permission.ScoView) +@scodoc7func +def students_groups_auto_assignment(formsemestre_id: int): + """En cours de dev.""" + formsemestre: FormSemestre = FormSemestre.query.get_or_404(formsemestre_id) + H = [ + html_sco_header.sco_header( + page_title=f"DEV", + ), + f"""

+

+ """, + render_template( + "scolar/students_groups_auto_assignment.j2", + formsemestre=formsemestre, + ), + html_sco_header.sco_footer(), + ] + + return "\n".join(H) + + @bp.route("/create_partition_parcours", methods=["GET", "POST"]) @scodoc @permission_required(Permission.ScoView) diff --git a/flask_cas/routing.py b/flask_cas/routing.py index 689530e7..11b7f24d 100644 --- a/flask_cas/routing.py +++ b/flask_cas/routing.py @@ -49,7 +49,6 @@ def login(): _external=True, ), ) - if "ticket" in flask.request.args: flask.session[cas_token_session_key] = flask.request.args["ticket"]