Skip to main content
1-Visitor
September 4, 2018
Solved

check if user has visibility on a thing

  • September 4, 2018
  • 5 replies
  • 2788 views

Hi all,

 I have a set of things (collected in a infotable) and I would like to know if the current user logged has visibility for each thing in order to show just his thing.

I would like to avoid to use GetImplementingThing function because if I will have a large number of Thing, the service will respond slowly.

Please see code below:

 

for (var x = 0; x < listLength; x++) {
 var rowPos = list.rows[x];
 var posInstance = Things[rowPos.PosThingName];
 try {
 if(posInstance.name) { result.AddRow(rowPos); }
 } catch(err) {
 }
}

  This will work because the "posInstance.name" will return error 

User does not have visibility permission for....THING_NAME

but this cause a large number of log error in monitoring and I would like to avoid that.

Is there a way to know if current user has visibility permission on a Thing?

 

 

This topic has been closed for replies.
Best answer by CarlesColl

You can use spotlightsearch instead (I don't know the performance...)

 

Istead of:

 

try {
 if(posInstance.name) { result.AddRow(rowPos); }
 } catch(err) {
 }

Use:

 

 

var any = Resources["SearchFunctions"].SpotlightSearch({
 maxItems: 1,
 searchExpression: rowPos.PosThingName,
 types: { items: ["Thing"] }
 
 });
if (any.rows.length==1) { result.AddRow(rowPos); }

 

 

 

5 replies

1-Visitor
September 5, 2018

You can use spotlightsearch instead (I don't know the performance...)

 

Istead of:

 

try {
 if(posInstance.name) { result.AddRow(rowPos); }
 } catch(err) {
 }

Use:

 

 

var any = Resources["SearchFunctions"].SpotlightSearch({
 maxItems: 1,
 searchExpression: rowPos.PosThingName,
 types: { items: ["Thing"] }
 
 });
if (any.rows.length==1) { result.AddRow(rowPos); }

 

 

 

22-Sapphire I
September 6, 2018

I don't see why GetImplementingThings would be any slower, one way or another you are determining all potential Things and then pulling the ones that are visible.

1-Visitor
September 6, 2018

Carles answer is correct.  I've validated and implemented in my current project.  The search services automatically determine user visibility and only return entities to which a user has access.