mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Merge branch 'develop' into 7202-verify-static-assets
This commit is contained in:
commit
513ecd7e26
@ -2,14 +2,18 @@
|
||||
|
||||
## v3.0.2 (FUTURE)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [#7131](https://github.com/netbox-community/netbox/issues/7131) - Fix issue where Site fields were hidden when editing a VLAN group
|
||||
* [#7148](https://github.com/netbox-community/netbox/issues/7148) - Fix issue where static query parameters with multiple values were not queried properly
|
||||
* [#7153](https://github.com/netbox-community/netbox/issues/7153) - Allow clearing of assigned device type images
|
||||
* [#7164](https://github.com/netbox-community/netbox/issues/7164) - Fix styling of "decommissioned" label for circuits
|
||||
* [#7169](https://github.com/netbox-community/netbox/issues/7169) - Fix CSV import file upload
|
||||
* [#7176](https://github.com/netbox-community/netbox/issues/7176) - Fix issue where query parameters were duplicated across different forms of the same type
|
||||
* [#7188](https://github.com/netbox-community/netbox/issues/7188) - Fix issue where select fields with `null_option` did not render or send the null option
|
||||
* [#7189](https://github.com/netbox-community/netbox/issues/7189) - Set connection factory for django-redis when Sentinel is in use
|
||||
* [#7193](https://github.com/netbox-community/netbox/issues/7193) - Fix prefix (flat) template issue when viewing child prefixes with prefixes available
|
||||
* [#7202](https://github.com/netbox-community/netbox/issues/7202) - Verify integrity of static assets in CI
|
||||
* [#7209](https://github.com/netbox-community/netbox/issues/7209) - Allow unlimited API results when `MAX_PAGE_SIZE` is disabled
|
||||
|
||||
---
|
||||
|
||||
|
@ -34,13 +34,22 @@ class OptionalLimitOffsetPagination(LimitOffsetPagination):
|
||||
return list(queryset[self.offset:])
|
||||
|
||||
def get_limit(self, request):
|
||||
limit = super().get_limit(request)
|
||||
|
||||
# Enforce maximum page size
|
||||
if self.limit_query_param:
|
||||
try:
|
||||
limit = int(request.query_params[self.limit_query_param])
|
||||
if limit < 0:
|
||||
raise ValueError()
|
||||
# Enforce maximum page size, if defined
|
||||
if settings.MAX_PAGE_SIZE:
|
||||
limit = min(limit, settings.MAX_PAGE_SIZE)
|
||||
|
||||
if limit == 0:
|
||||
return settings.MAX_PAGE_SIZE
|
||||
else:
|
||||
return min(limit, settings.MAX_PAGE_SIZE)
|
||||
return limit
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
|
||||
return self.default_limit
|
||||
|
||||
def get_next_link(self):
|
||||
|
||||
|
BIN
netbox/project-static/dist/netbox.js
vendored
BIN
netbox/project-static/dist/netbox.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -58,6 +58,12 @@ export class APISelect {
|
||||
*/
|
||||
public readonly emptyOption: Option;
|
||||
|
||||
/**
|
||||
* Null option. When `data-null-option` attribute is a string, the value is used to created an
|
||||
* option of type `{text: '<value from data-null-option>': 'null'}`.
|
||||
*/
|
||||
public readonly nullOption: Nullable<Option> = null;
|
||||
|
||||
/**
|
||||
* Event that will initiate the API call to NetBox to load option data. By default, the trigger
|
||||
* is `'load'`, so data will be fetched when the element renders on the page.
|
||||
@ -197,6 +203,14 @@ export class APISelect {
|
||||
this.emptyOption = EMPTY_PLACEHOLDER;
|
||||
}
|
||||
|
||||
const nullOption = base.getAttribute('data-null-option');
|
||||
if (isTruthy(nullOption)) {
|
||||
this.nullOption = {
|
||||
text: nullOption,
|
||||
value: 'null',
|
||||
};
|
||||
}
|
||||
|
||||
this.slim = new SlimSelect({
|
||||
select: this.base,
|
||||
allowDeselect: true,
|
||||
@ -291,8 +305,15 @@ export class APISelect {
|
||||
*/
|
||||
private set options(optionsIn: Option[]) {
|
||||
let newOptions = optionsIn;
|
||||
// Ensure null option is present, if it exists.
|
||||
if (this.nullOption !== null) {
|
||||
newOptions = [this.nullOption, ...newOptions];
|
||||
}
|
||||
// Sort options unless this element is pre-sorted.
|
||||
if (!this.preSorted) {
|
||||
newOptions = optionsIn.sort((a, b) => (a.text.toLowerCase() > b.text.toLowerCase() ? 1 : -1));
|
||||
newOptions = newOptions.sort((a, b) =>
|
||||
a.text.toLowerCase() > b.text.toLowerCase() ? 1 : -1,
|
||||
);
|
||||
}
|
||||
// Deduplicate options each time they're set.
|
||||
const deduplicated = uniqueByProperty(newOptions, 'value');
|
||||
|
@ -39,13 +39,13 @@ class APITestCase(ModelTestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Create a superuser and token for API calls.
|
||||
Create a user and token for API calls.
|
||||
"""
|
||||
# Create the test user and assign permissions
|
||||
self.user = User.objects.create_user(username='testuser')
|
||||
self.add_permissions(*self.user_permissions)
|
||||
self.token = Token.objects.create(user=self.user)
|
||||
self.header = {'HTTP_AUTHORIZATION': 'Token {}'.format(self.token.key)}
|
||||
self.header = {'HTTP_AUTHORIZATION': f'Token {self.token.key}'}
|
||||
|
||||
def _get_view_namespace(self):
|
||||
return f'{self.view_namespace or self.model._meta.app_label}-api'
|
||||
|
@ -1,7 +1,8 @@
|
||||
import urllib.parse
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import Client, TestCase
|
||||
from django.test import Client, TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
|
||||
@ -122,6 +123,59 @@ class WritableNestedSerializerTest(APITestCase):
|
||||
self.assertEqual(VLAN.objects.count(), 0)
|
||||
|
||||
|
||||
class APIPaginationTestCase(APITestCase):
|
||||
user_permissions = ('dcim.view_site',)
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.url = reverse('dcim-api:site-list')
|
||||
|
||||
# Create a large number of Sites for testing
|
||||
Site.objects.bulk_create([
|
||||
Site(name=f'Site {i}', slug=f'site-{i}') for i in range(1, 101)
|
||||
])
|
||||
|
||||
def test_default_page_size(self):
|
||||
response = self.client.get(self.url, format='json', **self.header)
|
||||
page_size = settings.PAGINATE_COUNT
|
||||
self.assertLess(page_size, 100, "Default page size not sufficient for data set")
|
||||
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['count'], 100)
|
||||
self.assertTrue(response.data['next'].endswith(f'?limit={page_size}&offset={page_size}'))
|
||||
self.assertIsNone(response.data['previous'])
|
||||
self.assertEqual(len(response.data['results']), page_size)
|
||||
|
||||
def test_custom_page_size(self):
|
||||
response = self.client.get(f'{self.url}?limit=10', format='json', **self.header)
|
||||
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['count'], 100)
|
||||
self.assertTrue(response.data['next'].endswith(f'?limit=10&offset=10'))
|
||||
self.assertIsNone(response.data['previous'])
|
||||
self.assertEqual(len(response.data['results']), 10)
|
||||
|
||||
@override_settings(MAX_PAGE_SIZE=20)
|
||||
def test_max_page_size(self):
|
||||
response = self.client.get(f'{self.url}?limit=0', format='json', **self.header)
|
||||
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['count'], 100)
|
||||
self.assertTrue(response.data['next'].endswith(f'?limit=20&offset=20'))
|
||||
self.assertIsNone(response.data['previous'])
|
||||
self.assertEqual(len(response.data['results']), 20)
|
||||
|
||||
@override_settings(MAX_PAGE_SIZE=0)
|
||||
def test_max_page_size_disabled(self):
|
||||
response = self.client.get(f'{self.url}?limit=0', format='json', **self.header)
|
||||
|
||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['count'], 100)
|
||||
self.assertIsNone(response.data['next'])
|
||||
self.assertIsNone(response.data['previous'])
|
||||
self.assertEqual(len(response.data['results']), 100)
|
||||
|
||||
|
||||
class APIDocsTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user