mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Merge branch 'develop' into 7205-applied-filters
This commit is contained in:
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -58,6 +58,9 @@ jobs:
|
|||||||
|
|
||||||
- name: Check UI ESLint, TypeScript, and Prettier Compliance
|
- name: Check UI ESLint, TypeScript, and Prettier Compliance
|
||||||
run: yarn --cwd netbox/project-static validate
|
run: yarn --cwd netbox/project-static validate
|
||||||
|
|
||||||
|
- name: Validate Static Asset Integrity
|
||||||
|
run: scripts/verify-bundles.sh
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: coverage run --source="netbox/" netbox/manage.py test netbox/
|
run: coverage run --source="netbox/" netbox/manage.py test netbox/
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## v3.0.2 (FUTURE)
|
## 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
|
* [#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
|
* [#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
|
* [#7153](https://github.com/netbox-community/netbox/issues/7153) - Allow clearing of assigned device type images
|
||||||
@ -9,8 +11,10 @@
|
|||||||
* [#7169](https://github.com/netbox-community/netbox/issues/7169) - Fix CSV import file upload
|
* [#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
|
* [#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
|
* [#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
|
* [#7193](https://github.com/netbox-community/netbox/issues/7193) - Fix prefix (flat) template issue when viewing child prefixes with prefixes available
|
||||||
* [#7205](https://github.com/netbox-community/netbox/issues/7205) - Fix issue where selected fields with `null_option` set were not added to applied filters
|
* [#7205](https://github.com/netbox-community/netbox/issues/7205) - Fix issue where selected fields with `null_option` set were not added to applied filters
|
||||||
|
* [#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:])
|
return list(queryset[self.offset:])
|
||||||
|
|
||||||
def get_limit(self, request):
|
def get_limit(self, request):
|
||||||
limit = super().get_limit(request)
|
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:
|
||||||
|
if limit == 0:
|
||||||
|
return settings.MAX_PAGE_SIZE
|
||||||
|
else:
|
||||||
|
return min(limit, settings.MAX_PAGE_SIZE)
|
||||||
|
return limit
|
||||||
|
except (KeyError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
# Enforce maximum page size
|
return self.default_limit
|
||||||
if settings.MAX_PAGE_SIZE:
|
|
||||||
limit = min(limit, settings.MAX_PAGE_SIZE)
|
|
||||||
|
|
||||||
return limit
|
|
||||||
|
|
||||||
def get_next_link(self):
|
def get_next_link(self):
|
||||||
|
|
||||||
|
@ -39,13 +39,13 @@ class APITestCase(ModelTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
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
|
# Create the test user and assign permissions
|
||||||
self.user = User.objects.create_user(username='testuser')
|
self.user = User.objects.create_user(username='testuser')
|
||||||
self.add_permissions(*self.user_permissions)
|
self.add_permissions(*self.user_permissions)
|
||||||
self.token = Token.objects.create(user=self.user)
|
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):
|
def _get_view_namespace(self):
|
||||||
return f'{self.view_namespace or self.model._meta.app_label}-api'
|
return f'{self.view_namespace or self.model._meta.app_label}-api'
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.contenttypes.models import ContentType
|
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 django.urls import reverse
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
@ -122,6 +123,59 @@ class WritableNestedSerializerTest(APITestCase):
|
|||||||
self.assertEqual(VLAN.objects.count(), 0)
|
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):
|
class APIDocsTestCase(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
41
scripts/verify-bundles.sh
Executable file
41
scripts/verify-bundles.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script verifies the integrity of *bundled* static assets by re-running the bundling process
|
||||||
|
# and checking for changed files. Because bundle output should not change given the same source
|
||||||
|
# input, the bundle process shouldn't produce any changes. If they do, it's an indication that
|
||||||
|
# the dist files have been altered, or that dist files were not committed. In either case, tests
|
||||||
|
# should fail.
|
||||||
|
|
||||||
|
PROJECT_STATIC="$PWD/netbox/project-static"
|
||||||
|
DIST="$PROJECT_STATIC/dist/"
|
||||||
|
|
||||||
|
# Bundle static assets.
|
||||||
|
bundle() {
|
||||||
|
echo "Bundling static assets..."
|
||||||
|
yarn --cwd $PROJECT_STATIC bundle >/dev/null 2>&1
|
||||||
|
if [[ $? != 0 ]]; then
|
||||||
|
echo "Error bundling static assets"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# See if any files have changed.
|
||||||
|
check_dist() {
|
||||||
|
local diff=$(git --no-pager diff $DIST)
|
||||||
|
if [[ $diff != "" ]]; then
|
||||||
|
local SHA=$(git rev-parse HEAD)
|
||||||
|
echo "Commit '$SHA' produced different static assets than were committed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
bundle
|
||||||
|
check_dist
|
||||||
|
|
||||||
|
if [[ $? = 0 ]]; then
|
||||||
|
echo "Static asset check passed"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "Error checking static asset integrity"
|
||||||
|
exit 1
|
||||||
|
fi
|
Reference in New Issue
Block a user