Notes from user gateway

Hello!

In order to aply some filters on my project depending on the user logging in I would need to add some notes on each user.

To get the userName Perspective use: session.props.auth.user.userName

how to fetch the notes from User Properties?

Use the user name to call system.user.getUser(userSource, username)

You should get the notes from the return user object.

1 Like

system.user.getUser() only works with Ignition User Sources, not Identity Providers. While you can use Ignition's native Identity Provider to work through a user source, external identity providers are popular.

1 Like

Hi,

in Ignition Vision we had access to Notes with:

import re
import app.misc

app.misc.userName = system.security.getUsername()

oUser = system.user.getUser(app.misc.strUserSource, app.misc.userName)
app.misc.userRoles = oUser.getRoles()

try:
	cNotes = oUser.getOrDefault(oUser.Notes)
	if (cNotes == "") or (cNotes == None):
		cNotes = "level:0;groups:0;zones:8;mainGroup:-1"
except:
	cNotes = "level:0;groups:0;zones:8"

if ('Administrador' in app.misc.userRoles) or ('Direccion' in app.misc.userRoles):
	cNotes = "access:9999999999;zones:0,1,2,3,4,5,6"
	

In ignition perspective can have access to notes??? with:

	from com.inductiveautomation.ignition.common import BasicDataset
	

	userSource = "default"
	userName = session.props.auth.user.userName
	
	try:
	    if userName:
	
	        user = system.user.getUser(userSource, userName)
	
	        if user is not None:
	          
	            notes = user.get("notes")
	            if notes is None:
	                notes = "No notes available for this user."
	        else:
	            notes = "User not found."
	
	     
	        session.custom.userNotes = notes
	    else:
	        session.custom.userNotes = "User not logged in."

or should I try using ?
image

If you are using Ignition's internal IdP, you can use system.user.getUser(). If using any other IdP, you must work with the data the IdP supplied. In recent versions of Ignition the complete data packet is supplied to a session property, but you will probably want to use attribute mapping:

1 Like

Right now I using Ignition Idp. But for some reason I don´t reach notes with my fetch:

from com.inductiveautomation.ignition.common import BasicDataset
	

	userSource = "default"
	userName = session.props.auth.user.userName
	
	try:
	    if userName:
	
	        user = system.user.getUser(userSource, userName)
	
	        if user is not None:
	          
	            notes = user.get("notes")
	            if notes is None:
	                notes = "No notes available for this user."
	        else:
	            notes = "User not found."
	
	     
	        session.custom.userNotes = notes
	    else:
	        session.custom.userNotes = "User not logged in."

Ok, now working after restart the gateway, thank you!