Skip to main content
1-Visitor
Sep 4, 2018 10:27 AM UTC
Solved

check if user has visibility on a thing

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.
1-Visitor
Sep 5, 2018 12:10 PM UTC

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
Sep 5, 2018 12:10 PM UTC

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); }

 

 

 

Translate
22-Sapphire I
Sep 6, 2018 6:35 PM UTC

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.

Translate
1-Visitor
Sep 6, 2018 7:51 PM UTC

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.

Translate