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()
|
conforming_count = self.queryset.filter(pk__in=[obj.pk for obj in instance]).count()
|
||||||
if conforming_count != len(instance):
|
if conforming_count != len(instance):
|
||||||
raise ObjectDoesNotExist
|
raise ObjectDoesNotExist
|
||||||
else:
|
elif not self.queryset.filter(pk=instance.pk).exists():
|
||||||
# Check that the instance is matched by the view's queryset
|
raise ObjectDoesNotExist
|
||||||
self.queryset.get(pk=instance.pk)
|
|
||||||
|
@ -173,7 +173,7 @@ class ObjectImportView(GetReturnURLMixin, BaseObjectView):
|
|||||||
obj = model_form.save()
|
obj = model_form.save()
|
||||||
|
|
||||||
# Enforce object-level permissions
|
# Enforce object-level permissions
|
||||||
if not self.queryset.filter(pk=obj.pk).first():
|
if not self.queryset.filter(pk=obj.pk).exists():
|
||||||
raise PermissionsViolation()
|
raise PermissionsViolation()
|
||||||
|
|
||||||
# Iterate through the related object forms (if any), validating and saving each instance.
|
# Iterate through the related object forms (if any), validating and saving each instance.
|
||||||
@ -390,7 +390,7 @@ class ObjectEditView(GetReturnURLMixin, BaseObjectView):
|
|||||||
obj = form.save()
|
obj = form.save()
|
||||||
|
|
||||||
# Check that the new object conforms with any assigned object-level permissions
|
# 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()
|
raise PermissionsViolation()
|
||||||
|
|
||||||
msg = '{} {}'.format(
|
msg = '{} {}'.format(
|
||||||
|
Reference in New Issue
Block a user