I developed a prototype of my application in an other Python web framework and struggle to get my head around using Django’s authorization system.
In my prototype I have the tables auth_user, auth_group and auth_membership. auth_user is similar to auth_user in Django. auth_group has fields role and description and auth_membership is an intermediary join table containing user_id and group_id.
I can restrict access to a function using a decorator like this:
@auth.requires(lambda: auth.has_membership(group_id=28, cached=True)
In Django I created an app named accounts and I use a custom user model. This gives me the following tables in my database:
accounts_customuser
accounts_customuser_groups
accounts_customuser_user_permissions
auth_group
auth_group_permissions
auth_permission
All tables are empty.
What I think I understand is that when I have a class Event I can create an auth_group named ‘event’ and add the permissions: Can add event, Can change event, Can delete event and Can view event to that auth_group.
First question: when are the permissions added to the auth_permission table?
Second question: accounts_customuser_groups stores customuser_id and group_id, am I right that this table is the equivalent of the auth_membership table in my prototype?
In my prototype I added three fields to the auth_membership table: backend, expiration_date and frontend.
I added backend and expiration_date to be able to grant and withdraw memberships without the need to delete the membership record from the auth_membership table.
I added frontend to make it possible for the user to disable menu item in case they don’t want to use a function.
Third question: what is the best way to handle temporary memberships in Django?
Fourth question: considering Django’s architecture should I create a separate app to handle the menu.
I look forward to your sharing your thoughts about these issues with me.
Kind regards,
Johanna