Set user permissions per user per area

Hi there,

I was looking for a way to prevent users to update features outside a designated area. The idea is to use the cloud_username variable as defining value. A cloud username is assigned to a certain area by a project manager so that user can only update features or add new features, etc. within that area.

My first idea was to use the Geofencing option and apply a filter to the geofencing layer. However, that doesn’t work. QGIS can not handle variables in a filter statement.

So, here is my workaround:
Use a polygon layer which defines the boundaries of working areas e.g. work_areas

Add an attribute, e.g. surveyor, and fill this attribute with the cloud username of the surveyor who is allowed to work in the respective areas.

Now consider a point layer to be updated out in the field.

For the editable layer set the permissions:
afbeelding
Use the following expression to disable certain actions:

CASE WHEN @cloud_username =
array_to_string(
overlay_within(‘work_areas’,surveyor))
THEN FALSE
ELSE TRUE
END

This expression will fetch the cloud username value in the field surveyor for the work area polygon that the point feature is in. Then it will check if your cloud_username is the same as the fetched value.

If it is the same, the result of the expression is FALSE, so the Disable function is not active.

I have not tested this with cases where the editable layer is a linestring or a polygon or when multiple users are allowed to edit within the same work area.

I do think this approach should work in those cases, but you have to change the expression accordingly. For linestrings and polygons you might need to use a different overlay function.
For multiple eligible users it is more tricky, because you have to check whether a specific cloud_username is mentioned in the string or array that is the result of the overlay function.

If you happen to be able to test and find working expressions for these use cases, please add them to this topic.

Happy QFielding.

2 Likes