1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Remove ObjectPermissionManager

This commit is contained in:
Jeremy Stretch
2020-05-28 13:47:52 -04:00
parent a8ed04c4d2
commit f8e29ea66a

View File

@ -197,29 +197,6 @@ class Token(models.Model):
return True return True
class ObjectPermissionManager(models.Manager):
def get_attr_constraints(self, user, perm):
"""
Compile all ObjectPermission attributes applicable to a specific combination of user, model, and action. Returns
a dictionary that can be passed directly to .filter() on a QuerySet.
"""
content_type, action = resolve_permission(perm)
assert action in ['view', 'add', 'change', 'delete'], f"Invalid action: {action}"
qs = self.get_queryset().filter(
Q(users=user) | Q(groups__user=user),
model=content_type,
**{f'can_{action}': True}
)
attrs = Q()
for perm in qs:
attrs |= Q(**perm.attrs)
return attrs
class ObjectPermission(models.Model): class ObjectPermission(models.Model):
""" """
A mapping of view, add, change, and/or delete permission for users and/or groups to an arbitrary set of objects A mapping of view, add, change, and/or delete permission for users and/or groups to an arbitrary set of objects
@ -257,8 +234,6 @@ class ObjectPermission(models.Model):
default=False default=False
) )
objects = ObjectPermissionManager()
class Meta: class Meta:
unique_together = ('model', 'attrs') unique_together = ('model', 'attrs')