From 656c8a9f2294f6ea9d32662ca4b3cff59db61c1b Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 28 Sep 2021 16:20:15 +0200 Subject: [PATCH] Fix: edition user sans dept --- app/auth/models.py | 4 ++-- app/views/users.py | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/auth/models.py b/app/auth/models.py index d71ecf3f..117dd7c5 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -329,7 +329,7 @@ class Role(db.Model): """Roles for ScoDoc""" id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(64), unique=True) + name = db.Column(db.String(64), unique=True) # TODO: , nullable=False)) default = db.Column(db.Boolean, default=False, index=True) permissions = db.Column(db.BigInteger) # 64 bits users = db.relationship("User", secondary="user_role", viewonly=True) @@ -388,7 +388,7 @@ class UserRole(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) role_id = db.Column(db.Integer, db.ForeignKey("role.id")) - dept = db.Column(db.String(64)) # dept acronym + dept = db.Column(db.String(64)) # dept acronym ou NULL user = db.relationship( User, backref=db.backref("user_roles", cascade="all, delete-orphan") ) diff --git a/app/views/users.py b/app/views/users.py index 3e3e7e8d..e3326e6b 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -171,15 +171,17 @@ def create_user_form(user_name=None, edit=0, all_roles=1): } if not initvalues["active"]: editable_roles_set = set() # can't change roles of a disabled user - editable_roles_strings = {r.name + "_" + dept for (r, dept) in editable_roles_set} - orig_roles_strings = {r.name + "_" + dept for (r, dept) in orig_roles} + editable_roles_strings = { + r.name + "_" + (dept or "") for (r, dept) in editable_roles_set + } + orig_roles_strings = {r.name + "_" + (dept or "") for (r, dept) in orig_roles} # add existing user roles displayed_roles = list(editable_roles_set.union(orig_roles)) displayed_roles.sort(key=lambda x: (x[1], x[0].name)) - displayed_roles_strings = [r.name + "_" + dept for (r, dept) in displayed_roles] - displayed_roles_labels = [ - "{dept}: {r.name}".format(dept=dept, r=r) for (r, dept) in displayed_roles + displayed_roles_strings = [ + r.name + "_" + (dept or "") for (r, dept) in displayed_roles ] + displayed_roles_labels = [f"{dept}: {r.name}" for (r, dept) in displayed_roles] disabled_roles = {} # pour desactiver les roles que l'on ne peut pas editer for i in range(len(displayed_roles_strings)): if displayed_roles_strings[i] not in editable_roles_strings: