I'm working on a Django project which will take on firms as clients and each client will be allowed to create multiple users. These users can then be assigned different permissions or roles.
The catch being that the type of permissions vary with clients i.e. they're not as simple as read, write, delete. Hence one client can have only 5-10 types of permissions while the other can have 100's.
The inbuilt Django permissions framework does not directly support my usecase, so this is what I came up with:
- Create a main django app which houses the user model
- For every new client, create a new django app with only models.py
- The models.py has only one model (for the time being) that in itself houses the permissions specific to that client as explained here.
- Now I can assign each user permissions depending on which client the user is a part of.
While I haven't tested it, this should work. The solution looks scalable but there are a lot of inconsistencies and it doesn't seem like the right way to do it. Is there a work around?
Update: django-guardian looks like it could help, not sure how.
Update: I think I'll explain the entire architecture because the current solution does not work directly for it.
- There are time series data streams with data coming in at regular intervals. Each client can have anywhere between 100 to more than 1000 such streams. These streams are not however saved in the webservers DB but are saved in each clients different DB.
- Now, a user can have privileges to view either all, one, or some of the above streams. The client lets us know about the type of user they want to create and we create one accordingly.
- For authentication purposes, its better to have all users in one table. But for authorization it makes sense to have each clients users on a separate table. It's best, in my opinion, to segregate the clients.
- Slightly off topic, but we were looking at providing each client with a separate co-domain like client1.mysite.com, client2.mysite.com etc and hence we have the freedom to deploy different web servers for each client and hence customize it for each client. Also, this helps in storing the data of each clients users differently.