Roles of users for the data in the database

Right now I have 3 type of users, one admin that needs to be able to change any item of the Repeating rows; one that can only change the ones that he saves himself, they fill the form and saves it, so they can only change those ones; and one that can only visualize them. all three of them should be able to visualize all the entries.

I saw the video in the youtube Anvil channel Multi-User Applications with Anvil, but in the example they can only visualice the entries made by themselves.

how should I approach this problem? can I visualize who saved or change the entry?

https://anvil.works/build#clone:EYYVCSAV7EIDK6BC=FBKUNUHK3P44N6AIE5AHJ4OS

The big ideas here are not specific to any one App. So I haven’t looked at yours, specifically.

Consider how you might arrange the information for a clerk to use. (The clerk takes the role of the data server.)

One approach would be to have a formal table, listing each user, and for each user, the rights/permissions/responsibilities they have.

Another way to organize the information splits it into two tables: one defines the list of roles, each role with its own rights/permissions/responsibilities; and the other lists the users, with a role (or roles) for each one. To connect the two, see Links Between Tables, and see whether that suits your uses.

The clerk (i.e., your server-side code) could then consult this set of data before serving any data, or allowing any (controlled) kind of action (e.g., updates). Their job is to enforce the rules you specify.

To make some of these distinctions, you’ll need to keep track of who entered what. Again, Links Between Tables can be good for this sort of thing.

Edit: I encourage you to search this forum, to see how others have already tackled such matters.

3 Likes

It’s also possible to open different forms for users, when they log in, according to which level of access they have. Each user interface can provide different views and access to different interactions with the data. You’ll still need to track who can do what with each row in tables, but this can help separate workflows a bit more easily.

2 Likes

I use something like this example a music studio to sign up students for recitals (it helps build a recital program from the entries). Every teacher can input entries, but they can only edit their own:

Something I do is create a separate app for admin, using the data table shared from some app like the one above. It’s important to know that when you share data tables between apps, the form permissions are per app (you can keep your data tables locked down in the app above, but make them fully editable from front end code in the admin app). That makes it really easy to create a simple CRUD admin panel that allows users of that second app to change anything in the database, using something like these examples:

2 Likes

the recital app clonning failed, it says The link to copy this app was invalid. It may have been revoked, can you please share it again

https://anvil.works/build#clone:KKP7UJHIW2OSSFMD=BHBZCQVOISPTOA3QCWOWWDM4

1 Like

the delet button is really usefull, is there any way that using a similar functionality like the

def button_1_click(self, **event_args):
usrname=anvil.users.get_user()
if usrname==self.item[‘usrname’]:
if confirm(‘Delete?’):
self.item.delete()
self.remove_from_parent()
open_form(‘Form1’)

applied to the textboxs so only the usser can modify the content?

Yep, take a look at the final 3 examples on that CRUD post. They demonstrate updating rows of tables using functions to the server. The same technique can be used anywhere you want to update any values in a data table - you can just check that the logged in user is only updating rows created by the same user. Here’s the clone to check out:

https://anvil.works/build#clone:LVHEEA6QEAROVZKE=SASNRPS7S6YH53QFPNZYBS4Z

1 Like