forked from ScoDoc/ScoDoc
Edition compte user: améliore message erreur si cas_id dupliqué
This commit is contained in:
parent
16e96c24ef
commit
3c5117c2d0
@ -67,14 +67,6 @@ def is_valid_user_name(user_name: str) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_new_cas_id(cas_id: str) -> bool:
|
|
||||||
"Check that cas_id is a valid new id (uniqueness, allow nulls)"
|
|
||||||
if not cas_id:
|
|
||||||
return True
|
|
||||||
nb_with_this_id = db.session.query(User).filter_by(cas_id=cas_id).count()
|
|
||||||
return nb_with_this_id == 0
|
|
||||||
|
|
||||||
|
|
||||||
class User(UserMixin, ScoDocModel):
|
class User(UserMixin, ScoDocModel):
|
||||||
"""ScoDoc users, handled by Flask / SQLAlchemy"""
|
"""ScoDoc users, handled by Flask / SQLAlchemy"""
|
||||||
|
|
||||||
@ -435,11 +427,18 @@ class User(UserMixin, ScoDocModel):
|
|||||||
if cas_id:
|
if cas_id:
|
||||||
new_cas_id = cas_id
|
new_cas_id = cas_id
|
||||||
if new_cas_id != self.cas_id:
|
if new_cas_id != self.cas_id:
|
||||||
if is_new_cas_id(new_cas_id):
|
existing: User = (
|
||||||
|
db.session.query(User).filter_by(cas_id=new_cas_id).first()
|
||||||
|
if new_cas_id is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
if not existing:
|
||||||
self.cas_id = new_cas_id
|
self.cas_id = new_cas_id
|
||||||
else:
|
else:
|
||||||
log(f"User.from_dict: CAS id invalide pour {self.user_name}")
|
msg = f"""CAS id invalide pour {self.user_name
|
||||||
raise ScoValueError(f"CAS id invalide pour {self.user_name}")
|
}, déjà utilisé par {existing.user_name}"""
|
||||||
|
log(f"User.from_dict: {msg}")
|
||||||
|
raise ScoValueError(msg)
|
||||||
|
|
||||||
def get_token(self, expires_in=3600):
|
def get_token(self, expires_in=3600):
|
||||||
"Un jeton pour cet user. Stocké en base, non commité."
|
"Un jeton pour cet user. Stocké en base, non commité."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user