I’m trying to filter some users in the User Management component using the filterUser extension function but can’t get it to work for me. I’m sure i’m doing something wrong, just can’t see what it is!
I want to look at the logged in user and basically hide all roles above them in the hierarchy, so Administrator>Lead>Operator where an Admin can sell all users a Lead logged in can only see the same other users with the Lead role and below etc.
I have the following code in the filterUser extension function;
[code]userName = system.security.getUsername() # logged in user
userIn = system.user.getUser("", userName)
rolesIn = userIn.roles # roles for current user
roleNames = user.getRoles() # inspect user role loaded in management table
if “Administrator” in rolesIn:
elif “Lead” in rolesIn:
if roleNames == “Administrator”:
print roleNames #here my console window shows all roles in management table
I have the print roleNames to help me debug - basically the console window will proceed to display the roles of each user in the management table.
I have 5 users and get the following in the console when logged in with a user with the “Lead” role;
For reference, if logged in as Admin, i get [Admin] in the console 5 times as expected