From c14684a1dcc3dd66d373deba9cb31d34603e1eab Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 30 Aug 2021 16:55:07 +0200 Subject: [PATCH] fix: affiche role SuperAdmin --- app/auth/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/auth/models.py b/app/auth/models.py index 02b0c5e72..8b3597565 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -250,7 +250,7 @@ class User(UserMixin, db.Model): """string repr. of user's roles (with depts) e.g. "Ens_RT, Ens_Info, Secr_CJ" """ - return ",".join("{r.role.name}_{r.dept}".format(r=r) for r in self.user_roles) + return ",".join(f"{r.role.name}_{r.dept or ''}" for r in self.user_roles) def is_administrator(self): "True if i'm an active SuperAdmin" @@ -400,15 +400,17 @@ class UserRole(db.Model): return "".format(self.user, self.role, self.dept) @staticmethod - def role_dept_from_string(role_dept): + def role_dept_from_string(role_dept: str): """Return tuple (role, dept) from the string role_dept, of the forme "Role_Dept". - role is a Role instance, dept is a string. + role is a Role instance, dept is a string, or None. """ fields = role_dept.split("_", 1) # maxsplit=1, le dept peut contenir un "_" if len(fields) != 2: raise ScoValueError("Invalid role_dept") role_name, dept = fields + if dept == "": + dept = None role = Role.query.filter_by(name=role_name).first() if role is None: raise ScoValueError("role %s does not exists" % role_name)