Get user roles from gateway script?

From the scope of a Gateway script. . .

I have the username and want to query their roles?

Is there a way to retrieve (user roles) in a Gateway script?

system.user.getUser doesn’t return anything, I think maybe it requires session scope?

Show your code. (Note that you can only supply a blank for userSource in Vision scope.)

1 Like
		users = system.user.getUsers("")
		for user in users:
			logDebugMsg('foxtrot role', user.get('firstname'), user.get('lastname'))

You can’t supply a blank user source to .getUsers() either, unless in Vision scope. Where is this code?

1 Like

I’m working perspective. Tag Change script, Gateway.

Your first line of code is passing an empty string to .getUsers(). You can’t do that in Perspective. You have to give the name of the user source you wish to enumerate.

1 Like

What exactly is the (user source)? :grinning: I've tried passing it user names but nothing is returned

Let me look at this a bit further
system.user.getUsers

Start here:

https://docs.inductiveautomation.com/display/DOC81/Security

1 Like

This works (below) where user.getRoles() contains the data I need.

In this script the variable empID is the Username as it would appear in the Ignition Gateway’s “User Sources

The literal string userSource is the Name of the source as it appears in Gateway’s (Config)(Security)(User Source)

	empID = str(event.getValue().value)
		
	users = system.user.getUsers('userSource')
	for user in users:
		if user.get('username') == empID: 
			print user.getRoles()
1 Like