mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #10718: Optimize object-based permissions enforcement
This commit is contained in:
@ -108,6 +108,5 @@ class ObjectValidationMixin:
|
||||
conforming_count = self.queryset.filter(pk__in=[obj.pk for obj in instance]).count()
|
||||
if conforming_count != len(instance):
|
||||
raise ObjectDoesNotExist
|
||||
else:
|
||||
# Check that the instance is matched by the view's queryset
|
||||
self.queryset.get(pk=instance.pk)
|
||||
elif not self.queryset.filter(pk=instance.pk).exists():
|
||||
raise ObjectDoesNotExist
|
||||
|
@ -173,7 +173,7 @@ class ObjectImportView(GetReturnURLMixin, BaseObjectView):
|
||||
obj = model_form.save()
|
||||
|
||||
# Enforce object-level permissions
|
||||
if not self.queryset.filter(pk=obj.pk).first():
|
||||
if not self.queryset.filter(pk=obj.pk).exists():
|
||||
raise PermissionsViolation()
|
||||
|
||||
# Iterate through the related object forms (if any), validating and saving each instance.
|
||||
@ -390,7 +390,7 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
||||
obj = form.save()
|
||||
|
||||
# Check that the new object conforms with any assigned object-level permissions
|
||||
if not self.queryset.filter(pk=obj.pk).first():
|
||||
if not self.queryset.filter(pk=obj.pk).exists():
|
||||
raise PermissionsViolation()
|
||||
|
||||
msg = '{} {}'.format(
|
||||
|
Reference in New Issue
Block a user