isAuthorized for the entire View

I have a button named "SET" on my view which I want to enable when an authorized person ("Administrator") is signed in on the session.
I have made a sign-in and sign-out button which can be used for authentication or to sign in in to the session, so when Admin is signed in, the SET button should be enabled and when signed out it should be disabled/grayed out.

For this I used 'isAuthorized' for the entire view rather than on the SET button, but for some reason it is not working properly. Could you be able to help me figure out with this....

This is the Configure Event script for the entire view

def runAction(self):
isAuthorized = system.perspective.isAuthorized(False, 'Authenticated/Roles/Administrator')
if (isAuthorized == False):
self.getChild("root").getChild("Button").props.enabled = isAuthorized

Thank you in advance!!

There is no such thing as system.perspective.isAuthorized(). isAuthorized() is an expression function, not a scripting function.

Don't use a script. Just use an expression binding on the button's props.enabled property.

2 Likes

Please see Wiki - how to post code on this forum.

1 Like

Thank you for the info. Yes, I used the expression binding which worked correctly.

If your button is writing to a tag, then I would recommend that you put the write permissions on the tag instead to centralise your security config. You can either leave the button as is and attempting to push it will result in a warning that the tag couldn't be written to (won't do this natively if you're writing it via script), or you can bind the button's enabled prop to the write tag's canWrite prop eg "tag/path.canWrite"

2 Likes