Widget runtime permissions
Hello Community,
As I have started working more with permissions in Thingworx recently.
I was wondering how other people in the community use permissions when setting visibility or disabling widgets in mashups.
My current thought is to set some different session parameters when the master mashup loads like;
Master loads -> SetGlobalSessionPermissions
The service SetGlobalSessionPermissions could look something like this:
const userGroups = Resources["CurrentSessionInfo"].GetCurrentUserGroups();
const isAdmin = userGroups.rows.toArray().find(e => e.name === 'Admin');
if(isAdmin) {
Resources["CurrentSessionInfo"].SetGlobalSessionBooleanValue({
name: "IsAdmin",
value: true,
});
}
const isViewer = userGroups.rows.toArray().find((e => e.name === "Viewer"));
if (isViewer) {
Resources["CurrentSessionInfo"].SetGlobalSessionBooleanValue({
name: "IsViewer",
value: true,
});
}
Then in any mashup we could use these session parameters to set visibility or enable/disable widgets.
This approach minimize the need for creating services in each mashup to check what permissions a user has.
However, there seems to be one drawback with it. The mashup that is loaded in the masters ("Page Mashup") widget gets loaded at the same time(?) as the master. So if you have anything that uses this session parameter there it wont work correctly.
I was wondering if perhaps there was any way to make sure that the master loads before anything else starts loading?
My current thought for a workaround would be to use the "Refresh" event on the "Page Mashup" widget in the master after the service to set the session parameters has run.
This does increase the load some and for my first (and only test so far) it didn't really work as I thought.
I think it would be great if we could get some inspiration or lessons learned from the community.
Thanks,
Jens

