Customize filterUser function in UserManagement component

Hi,

I’m using the new “User management” component from Ignition 7.6. What I’m trying to achieve is to filter the users using this code:

def filterUser(self, user): if "Administrador" in system.security.getRoles(): return 1 else: return 0

The problem is that the code doesn’t work. However, this same code run from a button it works.
Do you know what the problem is?

It doesn’t work in what way?

Also - this is probably not the best idea. Just configure component security on the component like normal, and make it disabled or hidden.

We have a project to manage the users where the component must be always visible because the users who can access to this project are administrators or a second group called ‘supervisor’ with less permission than administrators. Both of them can manage the users but we need to restrict that supervisors can not see users with administrator permissions. So we have tried with this code:

def filterUser(self, user):
     if "Administrador" in system.security.getRoles():
             return 1
     else:
             return 0

But it seems that system.security.getRoles() is not working inside of ‘filterUser’ function so my question is if you know what can be the problem.

Thanks,

I think you're misunderstanding what's going on here.

system.security.getRoles() will return the roles of the currently logged in user. I think you're trying to look at the roles of the user that you're filtering! Look at the documentation provided for that extension function:

It seems that I have not explained well, regardless of what I 'm trying to achieve, the code above is a basic example that hide all users if the role of the logged user is not an administrator, is that correct? But the problem is that doesn’t work and I don’t understand what I’m doing wrong.

Ok, in that case the code looks fine.

Are you getting any errors in your designer or client console under the logger “Vision.Components.UserManagementPanel”?