mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 12:42:52 -06:00
Miscellaneous RestrictedQuerySet cleanup
This commit is contained in:
parent
26e81546eb
commit
4f00b5af4a
@ -1729,7 +1729,7 @@ class Device(ChangeLoggedModel, ConfigContextModel, CustomFieldModel):
|
|||||||
filter = Q(device=self)
|
filter = Q(device=self)
|
||||||
if self.virtual_chassis and self.virtual_chassis.master == self:
|
if self.virtual_chassis and self.virtual_chassis.master == self:
|
||||||
filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False)
|
filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False)
|
||||||
return Interface.objects.filter(filter)
|
return Interface.objects.unrestricted().filter(filter)
|
||||||
|
|
||||||
def get_cables(self, pk_list=False):
|
def get_cables(self, pk_list=False):
|
||||||
"""
|
"""
|
||||||
|
@ -495,13 +495,13 @@ class DeviceRoleTable(BaseTable):
|
|||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
device_count = tables.TemplateColumn(
|
device_count = tables.TemplateColumn(
|
||||||
template_code=DEVICEROLE_DEVICE_COUNT,
|
template_code=DEVICEROLE_DEVICE_COUNT,
|
||||||
accessor=Accessor('devices.count'),
|
accessor=Accessor('devices.unrestricted.count'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
verbose_name='Devices'
|
verbose_name='Devices'
|
||||||
)
|
)
|
||||||
vm_count = tables.TemplateColumn(
|
vm_count = tables.TemplateColumn(
|
||||||
template_code=DEVICEROLE_VM_COUNT,
|
template_code=DEVICEROLE_VM_COUNT,
|
||||||
accessor=Accessor('virtual_machines.count'),
|
accessor=Accessor('virtual_machines.unrestricted.count'),
|
||||||
orderable=False,
|
orderable=False,
|
||||||
verbose_name='VMs'
|
verbose_name='VMs'
|
||||||
)
|
)
|
||||||
|
@ -84,7 +84,7 @@ class PrefixViewSet(CustomFieldModelViewSet):
|
|||||||
The advisory lock decorator uses a PostgreSQL advisory lock to prevent this API from being
|
The advisory lock decorator uses a PostgreSQL advisory lock to prevent this API from being
|
||||||
invoked in parallel, which results in a race condition where multiple insertions can occur.
|
invoked in parallel, which results in a race condition where multiple insertions can occur.
|
||||||
"""
|
"""
|
||||||
prefix = get_object_or_404(Prefix, pk=pk)
|
prefix = get_object_or_404(self.queryset, pk=pk)
|
||||||
available_prefixes = prefix.get_available_prefixes()
|
available_prefixes = prefix.get_available_prefixes()
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||||
|
|
||||||
from dcim.models import Device, Interface, Rack, Region, Site
|
from dcim.models import Device, Interface, Rack, Region, Site
|
||||||
|
@ -868,9 +868,9 @@ class VLANGroup(ChangeLoggedModel):
|
|||||||
"""
|
"""
|
||||||
Return the first available VLAN ID (1-4094) in the group.
|
Return the first available VLAN ID (1-4094) in the group.
|
||||||
"""
|
"""
|
||||||
vids = [vlan['vid'] for vlan in self.vlans.order_by('vid').values('vid')]
|
vlan_ids = VLAN.objects.unrestricted().filter(group=self).values_list('vid', flat=True)
|
||||||
for i in range(1, 4095):
|
for i in range(1, 4095):
|
||||||
if i not in vids:
|
if i not in vlan_ids:
|
||||||
return i
|
return i
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ VLAN_LINK = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
VLAN_PREFIXES = """
|
VLAN_PREFIXES = """
|
||||||
{% for prefix in record.prefixes.all %}
|
{% for prefix in record.prefixes.unrestricted %}
|
||||||
<a href="{% url 'ipam:prefix' pk=prefix.pk %}">{{ prefix }}</a>{% if not forloop.last %}<br />{% endif %}
|
<a href="{% url 'ipam:prefix' pk=prefix.pk %}">{{ prefix }}</a>{% if not forloop.last %}<br />{% endif %}
|
||||||
{% empty %}
|
{% empty %}
|
||||||
—
|
—
|
||||||
@ -283,13 +283,13 @@ class AggregateDetailTable(AggregateTable):
|
|||||||
class RoleTable(BaseTable):
|
class RoleTable(BaseTable):
|
||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
prefix_count = tables.TemplateColumn(
|
prefix_count = tables.TemplateColumn(
|
||||||
accessor=Accessor('prefixes.count'),
|
accessor=Accessor('prefixes.unrestricted.count'),
|
||||||
template_code=ROLE_PREFIX_COUNT,
|
template_code=ROLE_PREFIX_COUNT,
|
||||||
orderable=False,
|
orderable=False,
|
||||||
verbose_name='Prefixes'
|
verbose_name='Prefixes'
|
||||||
)
|
)
|
||||||
vlan_count = tables.TemplateColumn(
|
vlan_count = tables.TemplateColumn(
|
||||||
accessor=Accessor('vlans.count'),
|
accessor=Accessor('vlans.unrestricted.count'),
|
||||||
template_code=ROLE_VLAN_COUNT,
|
template_code=ROLE_VLAN_COUNT,
|
||||||
orderable=False,
|
orderable=False,
|
||||||
verbose_name='VLANs'
|
verbose_name='VLANs'
|
||||||
|
@ -86,7 +86,7 @@ class PrefixOrderingTestCase(OrderingTestBase):
|
|||||||
Prefix.objects.bulk_create(prefixes)
|
Prefix.objects.bulk_create(prefixes)
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
self._compare(Prefix.objects.all(), prefixes)
|
self._compare(Prefix.objects.unrestricted(), prefixes)
|
||||||
|
|
||||||
def test_prefix_complex_ordering(self):
|
def test_prefix_complex_ordering(self):
|
||||||
"""
|
"""
|
||||||
@ -122,7 +122,7 @@ class PrefixOrderingTestCase(OrderingTestBase):
|
|||||||
Prefix.objects.bulk_create(prefixes)
|
Prefix.objects.bulk_create(prefixes)
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
self._compare(Prefix.objects.all(), prefixes)
|
self._compare(Prefix.objects.unrestricted(), prefixes)
|
||||||
|
|
||||||
|
|
||||||
class IPAddressOrderingTestCase(OrderingTestBase):
|
class IPAddressOrderingTestCase(OrderingTestBase):
|
||||||
@ -173,4 +173,4 @@ class IPAddressOrderingTestCase(OrderingTestBase):
|
|||||||
IPAddress.objects.bulk_create(addresses)
|
IPAddress.objects.bulk_create(addresses)
|
||||||
|
|
||||||
# Test
|
# Test
|
||||||
self._compare(IPAddress.objects.all(), addresses)
|
self._compare(IPAddress.objects.unrestricted(), addresses)
|
||||||
|
@ -827,9 +827,15 @@ class ServiceEditView(ObjectEditView):
|
|||||||
|
|
||||||
def alter_obj(self, obj, request, url_args, url_kwargs):
|
def alter_obj(self, obj, request, url_args, url_kwargs):
|
||||||
if 'device' in url_kwargs:
|
if 'device' in url_kwargs:
|
||||||
obj.device = get_object_or_404(Device, pk=url_kwargs['device'])
|
obj.device = get_object_or_404(
|
||||||
|
Device.objects.restrict(request.user),
|
||||||
|
pk=url_kwargs['device']
|
||||||
|
)
|
||||||
elif 'virtualmachine' in url_kwargs:
|
elif 'virtualmachine' in url_kwargs:
|
||||||
obj.virtual_machine = get_object_or_404(VirtualMachine, pk=url_kwargs['virtualmachine'])
|
obj.virtual_machine = get_object_or_404(
|
||||||
|
VirtualMachine.objects.restrict(request.user),
|
||||||
|
pk=url_kwargs['virtualmachine']
|
||||||
|
)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def get_return_url(self, request, service):
|
def get_return_url(self, request, service):
|
||||||
|
Loading…
Reference in New Issue
Block a user