diff --git a/app/scodoc/sco_permissions_check.py b/app/scodoc/sco_permissions_check.py index 4145b7e06..a577135d6 100644 --- a/app/scodoc/sco_permissions_check.py +++ b/app/scodoc/sco_permissions_check.py @@ -65,9 +65,9 @@ def check_access_diretud(formsemestre: FormSemestre): return True, "" -def can_handle_passwd(user: User, allow_admindepts=False) -> bool: +def can_handle_passwd(user: User, allow_admin_depts=False) -> bool: """True if the current user can see or change passwd info of user. - If allow_admindepts, allow Admin from all depts (so they can view users from other depts + If allow_admin_depts, allow Admin from all depts (so they can view users from other depts and add roles to them). user is a User instance. """ @@ -81,9 +81,17 @@ def can_handle_passwd(user: User, allow_admindepts=False) -> bool: # If don't have permission in the current dept, abort if not current_user.has_permission(Permission.UsersAdmin, g.scodoc_dept): return False + # Si le compte est dans un département et que l'on est admin. user de ce dept: + if user.dept and current_user.has_permission(Permission.UsersAdmin, user.dept): + return True # Now check that current_user can manage users from this departement if not current_user.dept: - return True # if no dept, can access users from all depts ! - if (current_user.dept == user.dept) or allow_admindepts: + # if no dept, and perm. admin on g.scodoc_dept, can access users from all depts ! + return True + if ( + current_user.dept + and ((current_user.dept == user.dept) or allow_admin_depts) + and current_user.has_permission(Permission.UsersAdmin, current_user.dept) + ): return True return False diff --git a/app/scodoc/sco_users.py b/app/scodoc/sco_users.py index db27e0c76..98076a588 100644 --- a/app/scodoc/sco_users.py +++ b/app/scodoc/sco_users.py @@ -163,7 +163,7 @@ def list_users( rows = [] for u in users: # Can current user modify this user ? - can_modify = can_handle_passwd(u, allow_admindepts=True) + can_modify = can_handle_passwd(u, allow_admin_depts=True) d = u.to_dict() rows.append(d) diff --git a/app/templates/auth/user_info_page.j2 b/app/templates/auth/user_info_page.j2 index 882b5370b..6327542aa 100644 --- a/app/templates/auth/user_info_page.j2 +++ b/app/templates/auth/user_info_page.j2 @@ -7,7 +7,13 @@