cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

check if user has visibility on a thing

lguagneli84
7-Bedrock

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

 

 

View solution in original post

5 REPLIES 5

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

 

 

 

PaiChung
22-Sapphire I
(To:CarlesColl)

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.

wposner-2
12-Amethyst
(To:PaiChung)

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.

Because we will have different customer and each customer will have his own set of things that he will be able to see and on which I will have to performe research on the related stream. 

Collecting things in a separate stream and searching on this, it allows me to increase the response speed by an order of magnitude compared to the getImplementedThing. 
 
 

This solution works but to increase performance I added a field in my infotable with unitVisibility then I have added a filter in my query specification

Top Tags