How to restrict users to only certain Views?

Hello,

  1. I have an app with following total of 4 views:  Inventory, Orders, RMA, Dashboard.
  2. I have a table with following structure.
UIDUsernameUSEREMAILAccess to Views
1User1User1@email.comInventory
2User2User1@email.comOrders , RMA
3User3User1@email.comALL

3.  I would like to put an expression in the "Show if: constraint for each view where it checks if the logged in user has access to the view defined in the table above.  For example User1 only should see the Inventory View, User2 should see both Orders and RMA views and User3 should see ALL views.  I am trying to write an expression that will reference each view and show if allowed access in the Access to Views column.  I do not want to hard code the View names in the expression so in case the view name changes, it automatically checks view names.  Here is what I came up with, but it is not working:

ISNOTBLANK(
                           FILTER(
                                          "RBAC",
                                                        AND(
                                                                  [Email]=USEREMAIL(),
                                                                  OR(
                                                                          IN("ALL",[Access to Views]),
                                                                          IN(CONTEXT(View)), [Access to Views])
                                                                            )
                                                                  )
                                         )
                         )

1 1 110
1 REPLY 1

A secondary issue , there is a minor syntax issue in the expression IN(CONTEXT(View)), [Access to Views]). There is an extra parenthesis and it is better to enclose the text "View" in double quotes. So the expression could be 

IN(CONTEXT("View"), [Access to Views])

So you may test after the above correction. 

CONTEXT() - AppSheet Help

Other community colleagues may have their input as well. I have not tested the below response in a test app.

In my opinion, the primary issue could be the part of the expression  IN(CONTEXT("View"), [Access to Views])

I believe this is kind of circular reference type issue. I think the expression is trying to say , if the current context of the view is in the list of views allowed for a user, then show the user that view. However CONTEXT("View") will capture the view name only after that particular view is shown.

So till the view is shown to the user, the CONTEXT("View") will not populate and  IN(CONTEXT(View)), [Access to Views]) will not become true.  And in turn since  IN(CONTEXT(View)), [Access to Views]) is not true, the expression will not show the view to the user.

 

 

Top Labels in this Space