mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
Fix evaluation of RestrictedQuerySets
This commit is contained in:
parent
220352f44b
commit
1f3ff5f7d5
@ -1,5 +1,5 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import Count
|
from django.db.models import Count, Prefetch
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django_pglocks import advisory_lock
|
from django_pglocks import advisory_lock
|
||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
@ -270,6 +270,9 @@ class VLANViewSet(CustomFieldModelViewSet):
|
|||||||
#
|
#
|
||||||
|
|
||||||
class ServiceViewSet(ModelViewSet):
|
class ServiceViewSet(ModelViewSet):
|
||||||
queryset = Service.objects.prefetch_related('device').prefetch_related('tags')
|
queryset = Service.objects.prefetch_related(
|
||||||
|
Prefetch('ipaddresses', queryset=IPAddress.objects.unrestricted()),
|
||||||
|
'device', 'virtual_machine', 'tags'
|
||||||
|
)
|
||||||
serializer_class = serializers.ServiceSerializer
|
serializer_class = serializers.ServiceSerializer
|
||||||
filterset_class = filters.ServiceFilterSet
|
filterset_class = filters.ServiceFilterSet
|
||||||
|
@ -216,7 +216,9 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Ensure that the aggregate being added is not covered by an existing aggregate
|
# Ensure that the aggregate being added is not covered by an existing aggregate
|
||||||
covering_aggregates = Aggregate.objects.filter(prefix__net_contains_or_equals=str(self.prefix))
|
covering_aggregates = Aggregate.objects.unrestricted().filter(
|
||||||
|
prefix__net_contains_or_equals=str(self.prefix)
|
||||||
|
)
|
||||||
if self.pk:
|
if self.pk:
|
||||||
covering_aggregates = covering_aggregates.exclude(pk=self.pk)
|
covering_aggregates = covering_aggregates.exclude(pk=self.pk)
|
||||||
if covering_aggregates:
|
if covering_aggregates:
|
||||||
@ -227,7 +229,7 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# Ensure that the aggregate being added does not cover an existing aggregate
|
# Ensure that the aggregate being added does not cover an existing aggregate
|
||||||
covered_aggregates = Aggregate.objects.filter(prefix__net_contained=str(self.prefix))
|
covered_aggregates = Aggregate.objects.unrestricted().filter(prefix__net_contained=str(self.prefix))
|
||||||
if self.pk:
|
if self.pk:
|
||||||
covered_aggregates = covered_aggregates.exclude(pk=self.pk)
|
covered_aggregates = covered_aggregates.exclude(pk=self.pk)
|
||||||
if covered_aggregates:
|
if covered_aggregates:
|
||||||
@ -722,7 +724,7 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|||||||
|
|
||||||
# Check for primary IP assignment that doesn't match the assigned device/VM
|
# Check for primary IP assignment that doesn't match the assigned device/VM
|
||||||
if self.pk and type(self.assigned_object) is Interface:
|
if self.pk and type(self.assigned_object) is Interface:
|
||||||
device = Device.objects.filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first()
|
device = Device.objects.unrestricted().filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first()
|
||||||
if device:
|
if device:
|
||||||
if self.assigned_object is None:
|
if self.assigned_object is None:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
@ -734,7 +736,7 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|||||||
f"{self.assigned_object.device} ({self.assigned_object})"
|
f"{self.assigned_object.device} ({self.assigned_object})"
|
||||||
})
|
})
|
||||||
elif self.pk and type(self.assigned_object) is VMInterface:
|
elif self.pk and type(self.assigned_object) is VMInterface:
|
||||||
vm = VirtualMachine.objects.filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first()
|
vm = VirtualMachine.unrestricted().objects.filter(Q(primary_ip4=self) | Q(primary_ip6=self)).first()
|
||||||
if vm:
|
if vm:
|
||||||
if self.assigned_object is None:
|
if self.assigned_object is None:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
|
Loading…
Reference in New Issue
Block a user