Hi All,
I am attempting to implement a custom permission system in our Ignition app.
I have implemented a script to verify that a user role matches against a permission in our database. The user role is taken from the Ignition users.
I have this working when running the script via a "runScript" expression, and I pass the permission key, and user roles list to the function. No problem. As seen here:
runScript("permission.isAuthorised", 0, "LOUNP", {session.props.auth.user.roles})
This calls the following code:
def roleHasPermission(role, permission):
if role == "Administrator":
return True
query = "Permissions/SelectUserPermission"
params = {
"role": role,
"permission": permission
}
result = system.db.runNamedQuery(query, params)
return result > 0
def isAuthorised(permission, roles):
hasPermission = False
try:
values = [qv.value for qv in roles]
for role in values:
hasPermission = roleHasPermission(role, permission)
except:
pass
try:
if not hasPermission:
return not system.db.runNamedQuery("Permissions/SelectIsEnforced", {"key": permission})
except:
pass
return hasPermission
This works fine, the list of roles passed in is of type:
array(com.inductiveautomation.ignition.common.model.values.QualifiedValue, ...)
My problem is when I try to get the same list of roles from a transform script the type I receive is now different.
def transform(self, value, quality, timestamp):
if not permission.isAuthorised("STSCR", self.session.props.auth.user.roles):
return False
return value
Using "self.session.props.auth.user.roles" results in a list of type ArrayWrapper:
<ArrayWrapper>: [u'Administrator']
Is this supposed to be the case, or do I need to retrieve the roles from somewhere else? I'd like both arrays to be of type
array(com.inductiveautomation.ignition.common.model.values.QualifiedValue, ...)
I am assuming that it won't be easy to convert an ArrayWrapper to my desired type.
Any guidance is appreciated.
Thanks,
Tom