forked from ScoDoc/ScoDoc
Fix: edition user sans dept
This commit is contained in:
parent
5dfdf4265e
commit
656c8a9f22
@ -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")
|
||||
)
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user