1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-21 09:58:23 +02:00

Being superuser is not enough (must have the correct mask), add some initial fixtures

This commit is contained in:
Yohann D'ANELLO
2020-03-19 18:53:06 +01:00
parent 022997f923
commit 7794210cc8
9 changed files with 305 additions and 19 deletions

View File

@ -14,18 +14,20 @@ from django.utils.translation import gettext_lazy as _
class InstancedPermission:
def __init__(self, model, query, type, field):
def __init__(self, model, query, type, field, mask):
self.model = model
self.query = query
self.type = type
self.field = field
self.mask = mask
def applies(self, obj, permission_type, field_name=None):
"""
Returns True if the permission applies to
the field `field_name` object `obj`
"""
if ContentType.objects.get_for_model(obj) != self.model:
if not isinstance(obj, self.model.model_class()):
# The permission does not apply to the model
return False
@ -247,7 +249,7 @@ class Permission(models.Model):
"""
query = json.loads(self.query)
query = self._about(query, **kwargs)
return InstancedPermission(self.model, query, self.type, self.field)
return InstancedPermission(self.model, query, self.type, self.field, self.mask)
def __str__(self):
if self.field: