# Implementing User-Based Permissions in Query Parameters for Area Filtering

**URL:** <https://forum.inductiveautomation.com/t/implementing-user-based-permissions-in-query-parameters-for-area-filtering/98472>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 11, 2024, 4:43pm UTC](https://forum.inductiveautomation.com/t/implementing-user-based-permissions-in-query-parameters-for-area-filtering/98472 "2024-11-11T16:43:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [November 11, 2024, 4:43pm UTC](https://forum.inductiveautomation.com/t/implementing-user-based-permissions-in-query-parameters-for-area-filtering/98472/1 "2024-11-11T16:43:00Z")

</div>

In Ignition Perspective, I have a query that includes the following line:

sql

```python
AND Asset.companyLevel IN ({nivelFilter})

```

The variable `nivelFilter` represents an area code, which can have values of 1, 2, 3, 4, 5, or 6.

now I will get the user zone from the gateway like  
userRoles = self.session.auth.user.roles

```python
userRoles = self.session.auth.user.roles

if "Zone_1" in userRoles:
    nivelFilter = 1
elif "Zone_2" in userRoles:
    nivelFilter = 2
# Other zones

return nivelFilter

```

and aply it to the filter...

Is this a good way to aply security Levels on a query?

---

<div class="post-metadata">

**Author:** ![Benjamin\_Furlani](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/benjamin_furlani/32/66084_2.png) [@Benjamin\_Furlani](https://forum.inductiveautomation.com/u/Benjamin_Furlani)\
**Post date:** [November 11, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/implementing-user-based-permissions-in-query-parameters-for-area-filtering/98472/2 "2024-11-11T17:46:43Z")

</div>

I would say this is in general fine.

If you need to use this in multiple places put it into a project script and pass in the user roles to make it more scalable.

Another option could be to just use an expression with a map transform to get what the `nivelFilter` is and then always pass in the transformed value into your query. Technically I think the expression is more efficient.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [November 11, 2024, 5:55pm UTC](https://forum.inductiveautomation.com/t/implementing-user-based-permissions-in-query-parameters-for-area-filtering/98472/3 "2024-11-11T17:55:23Z")

</div>

Thanks for your explanation Benjamin.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [November 11, 2024, 6:59pm UTC](https://forum.inductiveautomation.com/t/implementing-user-based-permissions-in-query-parameters-for-area-filtering/98472/4 "2024-11-11T18:59:08Z")

</div>

Can the user have multiple roles?  
If so you will want to build the list and use that in your IN clause.  
Otherwise the code is fine, but I would change the query to  
`AND Asset.companylevel = {nivelFilter}`
