Skip to main content
13-Aquamarine
June 8, 2021
Solved

List a User's, Group's, or Org's Permissions

  • June 8, 2021
  • 1 reply
  • 1306 views

Hello, Is there a way to get that information programmatically, if so, could you please share sample script?

Best answer by yhan

General configuration idea is -- 1. Use the GetEntityList service of EntityServices resource. It will return a list of entities the user has visibility to; 2. Create a datashape that is used for listing the result of permission; 3. Use the CheckPermissionForUser service of the SecurityService resource. Then sort out the query result to an infotable with the defined datashape.

Take an example of listing user's permission:

 

var entities = Resources["EntityServices"].GetEntityList({
	maxItems: undefined /* NUMBER */,
	nameMask: "*Thing" /* STRING */,
	type: "Thing" /* STRING */,
	tags: undefined /* TAGS */
});
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(CheckPermissionDataShape)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "CheckPermissionDataShape"
});

var row = new Object();
for (var i=0;i<entities.length;i++){
 row.user=UserName;
 row.entity=entities[i].name;
 row.PropertyRead = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "PropertyRead" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.PropertyWrite = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "PropertyWrite" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.serviceInvoke = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "ServiceInvoke" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.EventInvoke = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "EventInvoke" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.EventSubscribe = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "EventInvoke" /* STRING */,
	user: UserName /* USERNAME */
	});
 result.AddRow(row);
}

 

The result looks like below:

6-9-2021 11-21-25 AM.jpg

1 reply

yhan17-PeridotAnswer
17-Peridot
June 9, 2021

General configuration idea is -- 1. Use the GetEntityList service of EntityServices resource. It will return a list of entities the user has visibility to; 2. Create a datashape that is used for listing the result of permission; 3. Use the CheckPermissionForUser service of the SecurityService resource. Then sort out the query result to an infotable with the defined datashape.

Take an example of listing user's permission:

 

var entities = Resources["EntityServices"].GetEntityList({
	maxItems: undefined /* NUMBER */,
	nameMask: "*Thing" /* STRING */,
	type: "Thing" /* STRING */,
	tags: undefined /* TAGS */
});
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(CheckPermissionDataShape)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "CheckPermissionDataShape"
});

var row = new Object();
for (var i=0;i<entities.length;i++){
 row.user=UserName;
 row.entity=entities[i].name;
 row.PropertyRead = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "PropertyRead" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.PropertyWrite = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "PropertyWrite" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.serviceInvoke = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "ServiceInvoke" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.EventInvoke = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "EventInvoke" /* STRING */,
	user: UserName /* USERNAME */
	});
 row.EventSubscribe = Resources["SecurityServices"].CheckPermissionForUser({
	name: entities[i].name /* STRING */,
	type: "EventInvoke" /* STRING */,
	user: UserName /* USERNAME */
	});
 result.AddRow(row);
}

 

The result looks like below:

6-9-2021 11-21-25 AM.jpg

15-Moonstone
June 10, 2021

@EM_9923519 : If the previous response answered your question, please mark it as the Accepted Solution for the benefit of others with the same question.