Question
There is a table for registering users' personal data. After initially entering a user (login/password) into the system table "users", the created user should be given access only to their own row in the registration data table for independently entering the remaining personal data. How can this be done?
Answer
Restricting user access to specific rows in a table is achieved using Prefilters. If a prefilter field is linked to a row part field and is not editable (visibility does not matter in this case) for the user, then this prefilter field acts as an access limiter on the server side.
In the row part of the table, there should be a field where, for example, user IDs are stored, and this field is linked to the prefilter field. In the prefilter field, the code calculates the ID of the current user who opened the table:
Prefilter field defining the current user's ID:
=: $#nu
This code can be refined to provide more convenience for users who need to see the entire table:
=: if(condition: $#nr = json`[1,5]`; then: ""; else: $#nu)
In this code, we check the current user's roles, and if role 1 or 5 is among them, we set an empty value in the prefilter field, which is equivalent to disabling it if this field is of type String or Number. If the user does not have these roles, the code returns the current user's ID.
If the prefilter limiter field is of type Select or Select-tree, instead of "", you need to pass "*ALL*"
:
=: if(condition: $#nr = json`[1,5]`; then: "*ALL*"; else: $#nu)
For the Cycles table, this approach does not work, as in Cycles, it is necessary to restrict access not only to rows in the Cycles table but also to tables within the cycle. This is done using the table settings parameter: Access type to cycles. In conjunction with the technical field creator_id in the cycles table and settings in the users table: boss_id, add_users, and all_connected_users.