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

Extend ObjectPermission constraints to OR multiple JSON objects

This commit is contained in:
Jeremy Stretch
2020-08-06 15:53:23 -04:00
parent b1ec332a56
commit 4a516103a6
5 changed files with 49 additions and 16 deletions

View File

@ -44,8 +44,15 @@ class RestrictedQuerySet(QuerySet):
else:
attrs = Q()
for perm_attrs in user._object_perm_cache[permission_required]:
if perm_attrs:
if type(perm_attrs) is list:
for p in perm_attrs:
attrs |= Q(**p)
elif perm_attrs:
attrs |= Q(**perm_attrs)
else:
# Any permission with null constraints grants access to _all_ instances
attrs = Q()
break
qs = self.filter(attrs)
return qs