Open realnot opened 1 year ago
I would probably change it so you have all 4 CRUD methods on the same row with a BooleanField
for each:
class BookPermission(RulesModel):
user = models.ForeignKey(User, on_delete=models.CASCADE)
book = models.ForeignKey(Book, on_delete=models.CASCADE)
can_add = models.BooleanField(default=False)
can_view = models.BooleanField(default=False)
can_change = models.BooleanField(default=False)
can_delete = models.BooleanField(default=False)
It's unrelated to django-rules
but I would also recommend avoiding object_id
+ content_type
. You can do this in django with GenericForeignKey
s but you should leave them as a last resort. This article talks about the alternatives,
I'm trying to build this permission mapping
But from the documentation I don't see how "Bob and Tim can edit Lord of the rings". Bob is not in any group and is not the owner of the book. Basically what is missing is a table to map Users, Permissions, Objects.
All examples show a predicate with user and object as arguments, but not a "permission". How do you test against above matrix? One way would be create a table like:
And from the view you have:
1) required permissions 2) user from request 3) current object_id (from get_object) which take you to step 4 4) get content_type with object_id
Now you have to test that all permissions you retrieve from the table are in required permission defined by view. Is the right approach or there's another way?