Select to view content in your preferred language

Display Features Relevant to the Current User

1126
5
07-31-2024 01:48 PM

Display Features Relevant to the Current User

Hosted feature service settings enable the item owner to control who can see and edit features through the settings shown below. It’s very common that users need to see or edit more than “their own” but less than “all features”. For example, in a statewide dataset, a user from County A may need to see and edit all features associated with County A.

PaytenJarnagin_0-1722456219225.png

 

One way to support this need is by using the CURRENT_USER keyword that’s part of the REST API query operation. This can be applied to an ArcGIS Online hosted feature service view. Here are the steps on how to do this:

  1. Make sure your hosted feature layer has a field with a comma separated list of usernames that should have access to each record, like this example
    PaytenJarnagin_7-1722456219229.png

  2. In ArcGIS Online, navigate to your hosted feature service Item Details and click Create View Layer then follow the instructions here
    PaytenJarnagin_1-1722456219225.png

  3. Go to the Item Details of the hosted view layer. Scroll down and click View next to the URLPaytenJarnagin_2-1722456219226.png

  4. Click Admin at the top left of the window
    PaytenJarnagin_3-1722456219226.png

  5. Click on the layer name under Layers:
    PaytenJarnagin_4-1722456219227.png

  6. Scroll down to the bottom of the page and click Update DefinitionPaytenJarnagin_5-1722456219227.png
  7. Delete all the JSON in the Update Layer Definition dialog box
  8. Navigate to https://jsonlint.com to help define the JSON object to be passed
  9. Paste the following into the JSON validator, then the Update Layer Definition dialog box: 

    {"viewLayerQuery" : "POSITION(CURRENT_USER in ViewUser) > 0"}


  10. Replace ViewUser with the field in your data which contains a comma separated list of usernames that should have access to each record, like this example:PaytenJarnagin_7-1722456219229.png

  11. Click Update Service Definition.

PaytenJarnagin_6-1722456219228.png

 

 

 

 

 

Now, with the view definition applied, my user (payten_HAPS) can only see feature 1 and 2, while others would see “their” features.

PaytenJarnagin_8-1722456926358.png

 

I’m excited to hear about how you use this!
Stay tuned for subsequent posts/blogs with more details on considerations and use cases 😊

Comments
DataOfficer
Frequent Contributor

Thank you for posting this.

This could be extremely useful for us. Particularly in managing community user access to specific features that they have not created / do not 'own' themselves, but we need to give them access to. Currently we use various hosted views and Groups as a middle ground for achieving this, but being able to fine-tune the access at a feature level would be a significant improvement. 

Does the ViewUsers approach work regardless of organisation? I.e., if the user is from outside of the layer organisation, does that cause any issues?

From a practical point of view, we would be looking to manage access to 10's of features (from a pool of thousands) for each user, across several hundred different users. Therefore some way of automating the comma separated listed of users for each feature will be essential (e.g. pulling from a spreadsheet, or from Group membership).

PaytenJarnagin
Esri Contributor

Hi @DataOfficer - The CURRENT_USER keyword filter will work for users outside of the layer's organization. I've tested the above approach with my community members and other, external ArcGIS Online members 🙂 

Side note: hosted feature layer views with a current_user filter applied should NOT be shared publicly. The caching of public layers impacts the layer's ability to filter by the specific user. 

Agreed, you'll definitely need a way to efficiently manage the "access data" (field with string of usernames) for each feature.. We are working on another post or blog with some considerations / possible approaches. I will link it here when it's available! 

DataOfficer
Frequent Contributor

@PaytenJarnagin thank you that's great.

rakeshmodia585
New Explorer

Tried out but not working for me.

The "viewlayerquery" does not exist. Tried to add property using adddefinition function but no luck. 

rakeshmodia585
New Explorer

ViewDefinitionQuery property is working for me instead of ViewLayerQuery property.

Version history
Last update:
‎07-31-2024 02:56 PM
Updated by:
Contributors