mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-23 01:08:45 +02:00
This commit is contained in:
@@ -159,7 +159,7 @@ class BaseTable(tables.Table):
|
|||||||
columns = None
|
columns = None
|
||||||
ordering = None
|
ordering = None
|
||||||
|
|
||||||
if self.prefixed_order_by_field in request.GET:
|
if request.user.is_authenticated and self.prefixed_order_by_field in request.GET:
|
||||||
if request.GET[self.prefixed_order_by_field]:
|
if request.GET[self.prefixed_order_by_field]:
|
||||||
# If an ordering has been specified as a query parameter, save it as the
|
# If an ordering has been specified as a query parameter, save it as the
|
||||||
# user's preferred ordering for this table.
|
# user's preferred ordering for this table.
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.template import Context, Template
|
from django.template import Context, Template
|
||||||
from django.test import RequestFactory, TestCase
|
from django.test import RequestFactory, TestCase
|
||||||
|
|
||||||
@@ -46,6 +47,16 @@ class BaseTableTest(TestCase):
|
|||||||
prefetch_lookups = table.data.data._prefetch_related_lookups
|
prefetch_lookups = table.data.data._prefetch_related_lookups
|
||||||
self.assertEqual(prefetch_lookups, tuple())
|
self.assertEqual(prefetch_lookups, tuple())
|
||||||
|
|
||||||
|
def test_configure_anonymous_user_with_ordering(self):
|
||||||
|
"""
|
||||||
|
Verify that table.configure() does not raise an error when an anonymous
|
||||||
|
user sorts a table column.
|
||||||
|
"""
|
||||||
|
request = RequestFactory().get('/?sort=name')
|
||||||
|
request.user = AnonymousUser()
|
||||||
|
table = DeviceTable(Device.objects.all())
|
||||||
|
table.configure(request)
|
||||||
|
|
||||||
|
|
||||||
class TagColumnTable(NetBoxTable):
|
class TagColumnTable(NetBoxTable):
|
||||||
tags = columns.TagColumn(url_name='dcim:site_list')
|
tags = columns.TagColumn(url_name='dcim:site_list')
|
||||||
|
|||||||
Reference in New Issue
Block a user