Showing content to only certain permission groups

This is a continuation of the thread here, but describing a separate issue, which is why I posted it in a new thread.

Using @Hyperbytes video as a guide, I created a user/permission system. I need to only display certain links in my navigation to users of certain permission groups. A user may have multiple types of permissions.

I have a query that retrieves the list of permissions associated with the logged in user and placed it on the page. I have tried various ways of trying to show the navigation link for only the permission group that needs to see it without success. In the App Connect > Dynamic Attributes > Show, I have tried == the value and contains the value without any luck.

In the dev tools, I see that the query is returning the appropriate values from the permission table.
permissions

So what I need to do is to show content, navigation links, based on each permission group.

Get the user details

Add the data source to the page

Show the item(s) on the page

@ben that does not work for me. It might work for a singular item, but does not work for multiple items from the same query.

When testing it, I have multiple shows from the same query. As I explained above, my user has five permissions associated with it that are being retrieved from the query.

I have tried:

<a class="dropdown-item" href="office/home" dmx-show="sc_logged_in.data.query1[0].webp_id_webp_permissions_fk == '2'">Administration</a>
<a class="dropdown-item" href="promoter/home" dmx-show="sc_logged_in.data.query1[0].webp_id_webp_permissions_fk == '3'">Promoter</a>

and I have tried:

<a class="dropdown-item" href="office/home" dmx-show="sc_logged_in.data.query1[0].webp_id_webp_permissions_fk.contains(&quot;'2'&quot;)">Administration</a>
<a class="dropdown-item" href="promoter/home" dmx-show="sc_logged_in.data.query1[0].webp_id_webp_permissions_fk.contains(&quot;'3'&quot;)">Promoter</a>

In the alternative, is there an “IN” option on the App Structure side that I can use?

On the server side, there is an “IN” option that is used in the Security Provider Users & Permissions.

How about inserting an or or and operator as in

I’m not sure that would work in my situation.

A user may be an Administrator or a Promoter, and while in my case they would be both, normally they typically would not be both so they would not need access to the same links.

Hi Scott,

How about a where clause on the collection, and evaluate the count?

dmx-show="sc_logged_in.data.query1.where('webp_id_webp_permissions_fk', '2', '==').count() > 0"

Just replace the “2” with tbe specific permission you are evaluating.

I’ve manually typing this out, so use the GUI to make site you get your exact code.

–Ken

Hello Scott,
Are you sure you logic here is right? Why this separate query which returns some permissions?

You need to check the logged user permissions / role or whatever is you use for this. Then you can use dmx-show/hide attributes just as Ben explains.

So, i a link should be displayed to Admin and Moderator but not User you do the following

dmx-show="serveconnect.data.users[0].level == 'Admin' || serveconnect.data.users[0].level == 'Moderator'"

If you want to show the link to Moderator only …

serveconnect.data.users[0].level == 'Moderator' 

etc.

Hi @mebeingken, I do not see a where clause in the data picker. :frowning:

Good Morning @Teodor,

I am beginning to doubt my logic now.

The query returns the permissions of the logged in user.

Which returns the permission values for the logged in user. In my case, I have all permissions:
permissions

I changed the code back to what Ben suggested.

<div class="dropdown-menu" aria-labelledby="dropdown1">
<a class="dropdown-item" href="dashboard" dmx-show="sc_logged_in.data.query1[0].webp_id_webp_permissions_fk == '1'">Dashboard</a>
<a class="dropdown-item" href="office/home" dmx-show="sc_logged_in.data.query1[0].webp_id_webp_permissions_fk == '2">Administration</a>
<a class="dropdown-item" href="promoter/home" dmx-show="sc_logged_in.data.query1[0].webp_id_webp_permissions_fk == '3'">Promoter</a>
<a class="dropdown-item" href="logoff">Log Off</a>
</div>

And it does not work…how do I know it does not work?

Because I only see the Log Off link when there should be three links above it.
permissions3

What does this query return exactly? How is it related to your user?

I have three tables: users, permissions, and a join table.

In my user table, I am #1.
permissions4

In the permissions table, I have five permission levels.
permissions6

In my join table, I have my user associated with each permission level.
permissions5

The query pulls the permission from the join table where the user id matches the security provider identity.