From c44ec8c6194f9125ad8168f73c83060be3589947 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 14 Mar 2023 20:06:12 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20gestion=20erreur=20lors=20impor?= =?UTF-8?q?t=20utilisateurs=20CAS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/auth/cas.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/auth/cas.py b/app/auth/cas.py index e031a231..4aac61b1 100644 --- a/app/auth/cas.py +++ b/app/auth/cas.py @@ -116,6 +116,7 @@ CAS_USER_INFO_IDS = ( "cas_id", "cas_allow_login", "cas_allow_scodoc_login", + "email_institutionnel", ) CAS_USER_INFO_COMMENTS = ( """user_name: @@ -143,6 +144,9 @@ CAS_USER_INFO_COMMENTS = ( """cas_allow_scodoc_login autorise connexion via ScoDoc même si CAS obligatoire (optionnel, faux par défaut) """, + """email_institutionnel + optionnel, le mail officiel de l'utilisateur. + Maximum 120 caractères.""", ) @@ -202,9 +206,16 @@ def cas_users_import_data(users_infos: list[dict]) -> int: for info in users_infos: user: User = User.query.filter_by(user_name=info["user_name"]).first() if not user: - return False, f"utilisateur {info['user_name']} inexistant", 0 + db.session.rollback() # au cas où auto-flush + raise ScoValueError(f"""Utilisateur '{info["user_name"]}' inexistant""") modif = False - if info["cas_id"].strip() != (user.cas_id or ""): + new_cas_id = info["cas_id"].strip() + if new_cas_id != (user.cas_id or ""): + # check unicity + other = User.query.filter_by(cas_id=new_cas_id).first() + if other and other.id != user.id: + db.session.rollback() # au cas où auto-flush + raise ScoValueError(f"cas_id {new_cas_id} dupliqué") user.cas_id = info["cas_id"].strip() or None modif = True val = scu.to_bool(info["cas_allow_login"])