Each table has the option to set whether it allows updates, adds, deletes, or just read-only access.
I would like to manage these permissions dynamically.
Here are the tables I have:
-
Users: This table manages users. Each user has a unique userID, their email used for logging in, and their user roles (EnumList + ref to the Roles table). A user can have multiple roles, such as Admin, Editor, User, etc.
-
Table_Restrictions: This table defines which roles have which permissions for all the tables used in the AppSheet application. The Table_Restrictions table has columns for Adds, Updates, and Deletes. Each column uses an EnumList + ref to the Roles table to define the user roles that are allowed to perform the respective operations on the table. If all three columns are empty, the table is read-only for all roles.
Is it possible, in the table settings under the condition “Are updates allowed?”, to achieve the following:
- Verify the roles assigned to the user based on their email from the Users table.
- Check if the roles the user has are permitted to perform Adds, Updates, or Deletes. If they are, the table should be set accordingly for the user’s permissions. If not, it should be read-only.
I am trying to accomplish this but am slowly giving up.
Could someone guide me to the correct logic?
Thank you.
I’m done with similar craziness like this code…
SWITCH(
CONTEXT("ViewType"),
"Form",
IFS(
IN(
"SuperAdmin",
SPLIT(LOOKUP(USEREMAIL(), "Custom_Users", "Email", "AllUserRoles"), ", ")
),
"ALL_CHANGES",
NOT(ISBLANK(
INTERSECT(
SPLIT(
LOOKUP(
"Persons",
"Custom_TablesRestrictions",
"TableName",
"AllowedAddsRoles"
),
", "
),
SPLIT(
LOOKUP(USEREMAIL(), "Custom_Users", "Email", "AllUserRoles"),
", "
)
)
)),
"ADDS_ONLY",
TRUE,
"READ_ONLY"
),
"Detail",
IFS(
IN(
"SuperAdmin",
SPLIT(LOOKUP(USEREMAIL(), "Custom_Users", "Email", "AllUserRoles"), ", ")
),
"ALL_CHANGES",
NOT(ISBLANK(
INTERSECT(
SPLIT(
LOOKUP(
"Persons",
"Custom_TablesRestrictions",
"TableName",
"AllowedUpdateRoles"
),
", "
),
SPLIT(
LOOKUP(USEREMAIL(), "Custom_Users", "Email", "AllUserRoles"),
", "
)
)
)),
"UPDATES_ONLY",
TRUE,
"READ_ONLY"
),
"Table",
IFS(
IN(
"SuperAdmin",
SPLIT(LOOKUP(USEREMAIL(), "Custom_Users", "Email", "AllUserRoles"), ", ")
),
"ALL_CHANGES",
NOT(ISBLANK(
INTERSECT(
SPLIT(
LOOKUP(
"Persons",
"Custom_TablesRestrictions",
"TableName",
"AllowedDeleteRoles"
),
", "
),
SPLIT(
LOOKUP(USEREMAIL(), "Custom_Users", "Email", "AllUserRoles"),
", "
)
)
)),
"DELETES_ONLY",
TRUE,
"READ_ONLY"
),
"READ_ONLY"
)



















