Show or hide menu icons based on User role

Hi everyone here,

     In my app ,I have three icons in one menu ,These icons are related to three dashboard views.I want to show or hide each icon based on the user role in my User Manager table which is structured like that: 

UIDTeamEmailRole
1Aaaa@gmail.comAdmin
2Bbbb@gmail.comDispatch
3Cccc@gmail.comLogistics
4Dddd@gmail.comActing As D
5Eeee@gmail.comViewer

The three icons are related to three views in my menu ,which is structured like that:

IDNameImage
1New Action 
2Supervisor Dashboard 
3Report with Filter 

I want to enable Logistics" ,"Dispatch" and "Acting As D" to see New Action and Supervisor Dashboard icons ,while Viewer can only see Supervisor Dashboard view icon .Admin can see them all.

Thank you in advance.

Solved Solved
0 28 1,494
1 ACCEPTED SOLUTION

Hello there,

Here's how you can solve your issue:

But before you start reading, you should look into implementing a current user system if you haven't already:

https://www.googlecloudcommunity.com/gc/Tips-Tricks/Current-User-Slice-How-to-conform-your-app-aroun...

Now the solution:

1- Create a new table only for the "User Roles", and in it add a column called "Allowed Views", make it an EnumList base type text, and populate it with the name of your options.

2- For every role, use the Allowed Views column to choose which views are allowed for their role.

3- For this to work the "Role" column in your users table should be of type REF to your newly created "User Roles" table

4- Add a virtual column called "_allowedViews" with an expression of [Role].[Allowed Views] to make the upcoming expression easier to make.

5- Create a slice of your menu table, you'll use this slice as the table for the menu view

6- Once you have all that, you can use an expression like this on the filter condition of the slice you just created, the one on which your menu will be built on:

 

 

 

IN(
 [name],
 INDEX(currentUser[_allowedViews],1)
)

 

 

 

This lets you dynamically change just from within the app which roles have access to which views, and it is easily scalable to multiple roles and views.

OR

Just add an EnumList column to your menu table, the options for this column should be all your roles, then you can populate each row in your menu with the roles that would be allowed to see each view, and then you'll use instead this expression in the menu slice:

 

IN(
 INDEX(currentUser[Role],1),
 [allowedRoles]
)

Personally I like the other option more, even if it is more work.

 

View solution in original post

28 REPLIES 28