Now I understand.
For your situation you have 2 options:
Doing what you did here ↑. However I belive that the error is occuring because that level hasn't loaded yet. Not sure.
Or simply copying and pasting the full code of the original level. I will not recommend doing this.
However, I would like to share what is our solution. We think it's a good aproach and maybe it could help you.
In our case, the users roles are also managed by the AD.
What we have as our security rules are only your "Actions".
Each rule calls the same script
runScript("core.has_role", 0, {attribute-source:idTokenClaims:roles}, "ID-Rule")
This script throws a query to our database. The table looks like this:
| SECURITY_ID |
NAME |
ROLES |
| PRESS_BUTTON_ERROR |
Allow to press the error button |
["Administrator","Agent","Security"] |
| PRESS_BUTTON_SAVE |
Allow to press the save button |
["Administrator","Agent","Operator"] |
| VISUALIZATION_ALARMS |
Allowed to enter the alarms view. |
["Administrator"] |
The script looks something like this:
has_role function
def has_role(role_list, rule):
rules_ds = system.db.runNamedQuery(
'GET_SECURITY_LEVEL_RULE',
{"SECURITY_LEVEL_ID": rule}
)
if len(rules_ds) != 1:
return False
rule_roles = system.util.jsonDecode(rules_ds.getValueAt(0, 0))
for role in role_list:
if role in rule_roles:
return True
return False
It will return true when the role is allowed to do that rule.
This way, you can link rules to independent roles. No need to have multiple roles or having that tree structure. You configure the security level rules (the actions) and you configure in the database what roles are allowed to do.
For your case:
When checking if it can press the button it will launch:
has_role(["PlantA/Manager", ... ], "canPressStartButton")
This will search in the database the specific rule:
| SECURITY_ID |
NAME |
ROLES |
| canPressStartButton |
Allow to press the start button |
["PlantA/Manager", "PlantB/Intern", "Manteinance", ... ] |
Because the rule allows PlantA/Managers to execute that, it will allow to press the button (it will return true).
A lot of this explanation has been done on the fly, so it will not be exactly like that.
Hope I helped on something and hope you find a solution.