Assignee (linked to a users table containing ID, email, etc.)
Status
I aim to establish a default filter for all users titled “Show My Tasks Only.”
Could I introduce a “My Tasks” column (toggle type) with a formula such as “user.Email == $assignee_email” to facilitate filtering?
The way you’re suggesting sounds exactly right to me. You should have a toggle column that only goes True when the current user is the assignee. If you then filter the table by that column, showing only the “True” value, then everyone should get to see only their own tasks.
Suppose you have a ‘Tasks’ table that lists all the tasks and has a column ‘assignee’, with that being a reference to the table ‘Assignee’. Then you could also have a toggle column on the ‘Tasks’ table and put a formula like this:
# This supposes that the 'Assignee' table has an 'email' column.
return Assignee.lookupOne(id=$assignee).email == user.Email
Oops, actually, the “user” variable isn’t available in formula columns, so that won’t work at all. Instead you could use ACL to simply deny users access to records that they’re not assigned to. Visually, that should come down to the same thing as filtering. Here’s how:
Create a table ‘Permissions’ (or any other name you choose). In it, you’ll have to create one record per each user. Unfortunately, this has to be done manually. A good idea is to have a column ‘user_id’ and give it an “on new record” trigger that reads return user.UserID.
Go to the ‘Tasks’ table and set the ‘assignee’ column to be a reference to the ‘Permissions’ table.
On the ‘Permissions’ table, make a reference list column ‘assigned_tasks’, point it to the ‘Tasks’ table. Make it a formula column and put this: return Tasks.lookupRecords(assignee=$id)
Open Access Rules. Click ‘Add User Attributes’. Fill out the blank row that’s just appeared at the top as follows: Name: this_users_permissions, Attribute to look up: user.UserID, Lookup table: Permissions, Lookup column: user_id.
Click ‘Add Table Rules’, then ‘Tasks’. This appends a new rules box for the ‘Tasks’ table to the ACL page.
In it, first make sure that you maintain admin access as to everything. Make sure there is a rule user.Access in [OWNER] that has all of the “R”, “U”, “C”, “D” buttons set to green.
Deny the entire ‘Tasks’ table for everyone else. Create a new line, leave its rule blank (it should faintly read Everyone else as a result), and set all buttons to red.
Create another new line and put: rec in user.this_users_permissions.assigned_tasks, and set all the buttons to green.
The last step is where the magic happens. Due to steps 6 and 7, the ‘Tasks’ table is now generally inaccessible to anyone who isn’t an OWNER, aka admin. But step 8 says that if a record from the ‘Tasks’ table (rec) happens to be in this user’s assigned tasks list, then they get access. This should be what you want, hopefully. Let me know if it works.
This is what I tried to do.
But I get the error:
NameError : name ‘user’ is not defined
A NameError exception indicates that a variable or
function name is not known to Python.
Most often, this is because there is a spelling mistake.
However, sometimes it is because the name is used
before being defined or given a value.
In your program, no object with the name user exists.
I have no additional information for you.
This is a good trick which I always use to implement row-level access.
But my task is just to create a column which is used to filter tasks in the common tasks list.
The behaviur: when user opens the tasks list, he should see only his tasks (filtered list), but he is allowed to see the whole list as well.
Yes, I answered it already. Unfortunatly it’s not what I am looking what. It’s really strange that I can’t get any user information whithin column formulas.
I’m not sure I understand you correctly. Are you saying your users should basically be able to choose whether to view the whole ‘Tasks’ table or just those records that they’re assigned to? In that case, my ACL approach above requires a small addition: For the table ‘Permissions’, also add a toggle column ‘view_all_tasks_not_just_assigned_ones’. Then extend the above ACL solution with this additional rule:
user.view_all_tasks_not_just_assigned_ones
… with all buttons set to green. That way, if you turn on the ‘view all tasks’ switch in ‘Permissions’, that user gets to see the entire ‘Tasks’ table.
No, it’s not about permissions, it’s about tasks view only.
When the user opens the list of tasks, he should see the list filtered by the column “my tasks yes/no”. But it should be the simple table filter to allow this user to uncheck this filter and see the tasks assigned to other people.
Ah, thanks for clearing that up. Unless I’m overlooking something, that’s not possible. The closest you could get is having a separate “view all” switch on a separate table that users could flip, see my previous post.