mirror of
https://github.com/netbox-community/netbox.git
synced 2025-09-06 06:13:36 -06:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c9f823167c | ||
|
5ca2cea016 | ||
|
026737b62b | ||
|
94faf58c27 | ||
|
de499ca686 | ||
|
f04a2b965f | ||
|
fcb380b5c5 | ||
|
8311f457b5 | ||
|
47e4947ca0 | ||
|
545773e221 | ||
|
2ddec1ef48 | ||
|
309e434064 | ||
|
8a1db81111 | ||
|
399d51b466 | ||
|
6135fb8cd7 | ||
|
ea50786b5c |
@ -21,6 +21,14 @@ repos:
|
||||
language: system
|
||||
pass_filenames: false
|
||||
types: [python]
|
||||
- id: openapi-check
|
||||
name: "Validate OpenAPI schema"
|
||||
description: "Check for any unexpected changes to the OpenAPI schema"
|
||||
files: api/.*\.py$
|
||||
entry: scripts/verify-openapi.sh
|
||||
language: system
|
||||
pass_filenames: false
|
||||
types: [python]
|
||||
- id: mkdocs-build
|
||||
name: "Build documentation"
|
||||
description: "Build the documentation with mkdocs"
|
||||
|
256546
contrib/openapi.json
Normal file
256546
contrib/openapi.json
Normal file
File diff suppressed because one or more lines are too long
@ -123,16 +123,6 @@ $ node bundle.js
|
||||
Done in 1.00s.
|
||||
```
|
||||
|
||||
### Rebuild the Device Type Definition Schema
|
||||
|
||||
Run the following command to update the device type definition validation schema:
|
||||
|
||||
```nohighlight
|
||||
./manage.py buildschema --write
|
||||
```
|
||||
|
||||
This will automatically update the schema file at `contrib/generated_schema.json`.
|
||||
|
||||
### Update & Compile Translations
|
||||
|
||||
Updated language translations should be pulled from [Transifex](https://app.transifex.com/netbox-community/netbox/dashboard/) and re-compiled for each new release. First, retrieve any updated translation files using the Transifex CLI client:
|
||||
@ -160,6 +150,24 @@ Then, compile these portable (`.po`) files for use in the application:
|
||||
!!! tip
|
||||
Put yourself in the shoes of the user when recording change notes. Focus on the effect that each change has for the end user, rather than the specific bits of code that were modified in a PR. Ensure that each message conveys meaning absent context of the initial feature request or bug report. Remember to include keywords or phrases (such as exception names) that can be easily searched.
|
||||
|
||||
### Rebuild the Device Type Definition Schema
|
||||
|
||||
Run the following command to update the device type definition validation schema:
|
||||
|
||||
```nohighlight
|
||||
./manage.py buildschema --write
|
||||
```
|
||||
|
||||
This will automatically update the schema file at `contrib/generated_schema.json`.
|
||||
|
||||
### Update the OpenAPI Schema
|
||||
|
||||
Update the static OpenAPI schema definition at `contrib/openapi.json` with the management command below. If the schema file is up-to-date, only the NetBox version will be changed.
|
||||
|
||||
```nohighlight
|
||||
./manage.py spectacular --format openapi-json > ../contrib/openapi.json
|
||||
```
|
||||
|
||||
### Submit a Pull Request
|
||||
|
||||
Commit the above changes and submit a pull request titled **"Release vX.Y.Z"** to merge the current release branch (e.g. `release-vX.Y.Z`) into `main`. Copy the documented release notes into the pull request's body.
|
||||
|
@ -6,7 +6,6 @@ from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from circuits.choices import *
|
||||
from circuits.constants import *
|
||||
from dcim.models import CabledObjectModel
|
||||
from netbox.models import ChangeLoggedModel, OrganizationalModel, PrimaryModel
|
||||
from netbox.models.mixins import DistanceMixin
|
||||
@ -231,6 +230,7 @@ class CircuitGroupAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin,
|
||||
class CircuitTermination(
|
||||
CustomFieldsMixin,
|
||||
CustomLinksMixin,
|
||||
ExportTemplatesMixin,
|
||||
TagsMixin,
|
||||
ChangeLoggedModel,
|
||||
CabledObjectModel
|
||||
|
@ -8,7 +8,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from circuits.choices import *
|
||||
from netbox.models import ChangeLoggedModel, PrimaryModel
|
||||
from netbox.models.features import CustomFieldsMixin, CustomLinksMixin, TagsMixin
|
||||
from netbox.models.features import CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, TagsMixin
|
||||
from .base import BaseCircuitType
|
||||
|
||||
__all__ = (
|
||||
@ -121,6 +121,7 @@ class VirtualCircuit(PrimaryModel):
|
||||
class VirtualCircuitTermination(
|
||||
CustomFieldsMixin,
|
||||
CustomLinksMixin,
|
||||
ExportTemplatesMixin,
|
||||
TagsMixin,
|
||||
ChangeLoggedModel
|
||||
):
|
||||
|
@ -1181,7 +1181,7 @@ class InventoryItemImportForm(NetBoxModelImportForm):
|
||||
help_text=_('Component Type')
|
||||
)
|
||||
component_name = forms.CharField(
|
||||
label=_('Compnent name'),
|
||||
label=_('Component name'),
|
||||
required=False,
|
||||
help_text=_('Component Name')
|
||||
)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from django import forms
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from dcim.constants import LOCATION_SCOPE_TYPES
|
||||
@ -48,8 +48,17 @@ class ScopedForm(forms.Form):
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
scope = self.cleaned_data.get('scope')
|
||||
scope_type = self.cleaned_data.get('scope_type')
|
||||
if scope_type and not scope:
|
||||
raise ValidationError({
|
||||
'scope': _(
|
||||
"Please select a {scope_type}."
|
||||
).format(scope_type=scope_type.model_class()._meta.model_name)
|
||||
})
|
||||
|
||||
# Assign the selected scope (if any)
|
||||
self.instance.scope = self.cleaned_data.get('scope')
|
||||
self.instance.scope = scope
|
||||
|
||||
def _set_scoped_values(self):
|
||||
if scope_type_id := get_field_value(self, 'scope_type'):
|
||||
@ -107,3 +116,15 @@ class ScopedImportForm(forms.Form):
|
||||
required=False,
|
||||
label=_('Scope type (app & model)')
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
scope_id = self.cleaned_data.get('scope_id')
|
||||
scope_type = self.cleaned_data.get('scope_type')
|
||||
if scope_type and not scope_id:
|
||||
raise ValidationError({
|
||||
'scope_id': _(
|
||||
"Please select a {scope_type}."
|
||||
).format(scope_type=scope_type.model_class()._meta.model_name)
|
||||
})
|
||||
|
@ -87,11 +87,9 @@ class CachedScopeMixin(models.Model):
|
||||
def clean(self):
|
||||
if self.scope_type and not (self.scope or self.scope_id):
|
||||
scope_type = self.scope_type.model_class()
|
||||
raise ValidationError({
|
||||
'scope': _(
|
||||
"Please select a {scope_type}."
|
||||
).format(scope_type=scope_type._meta.model_name)
|
||||
})
|
||||
raise ValidationError(
|
||||
_("Please select a {scope_type}.").format(scope_type=scope_type._meta.model_name)
|
||||
)
|
||||
super().clean()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
@ -76,11 +76,11 @@ class CustomFieldBulkEditForm(ChangelogMessageMixin, BulkEditForm):
|
||||
required=False,
|
||||
widget=BulkEditNullBooleanSelect()
|
||||
)
|
||||
validation_minimum = forms.IntegerField(
|
||||
validation_minimum = forms.DecimalField(
|
||||
label=_('Minimum value'),
|
||||
required=False,
|
||||
)
|
||||
validation_maximum = forms.IntegerField(
|
||||
validation_maximum = forms.DecimalField(
|
||||
label=_('Maximum value'),
|
||||
required=False,
|
||||
)
|
||||
|
@ -103,11 +103,11 @@ class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
|
||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||
)
|
||||
)
|
||||
validation_minimum = forms.IntegerField(
|
||||
validation_minimum = forms.DecimalField(
|
||||
label=_('Minimum value'),
|
||||
required=False
|
||||
)
|
||||
validation_maximum = forms.IntegerField(
|
||||
validation_maximum = forms.DecimalField(
|
||||
label=_('Maximum value'),
|
||||
required=False
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ if TYPE_CHECKING:
|
||||
)
|
||||
from tenancy.graphql.filters import TenantFilter, TenantGroupFilter
|
||||
from netbox.graphql.enums import ColorEnum
|
||||
from netbox.graphql.filter_lookups import IntegerLookup, JSONFilter, StringArrayLookup, TreeNodeFilter
|
||||
from netbox.graphql.filter_lookups import FloatLookup, IntegerLookup, JSONFilter, StringArrayLookup, TreeNodeFilter
|
||||
from users.graphql.filters import GroupFilter, UserFilter
|
||||
from virtualization.graphql.filters import ClusterFilter, ClusterGroupFilter, ClusterTypeFilter
|
||||
from .enums import *
|
||||
@ -151,10 +151,10 @@ class CustomFieldFilter(BaseObjectTypeFilterMixin, ChangeLogFilterMixin):
|
||||
weight: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||
strawberry_django.filter_field()
|
||||
)
|
||||
validation_minimum: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||
validation_minimum: Annotated['FloatLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||
strawberry_django.filter_field()
|
||||
)
|
||||
validation_maximum: Annotated['IntegerLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||
validation_maximum: Annotated['FloatLookup', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||
strawberry_django.filter_field()
|
||||
)
|
||||
validation_regex: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||
|
21
netbox/extras/migrations/0133_make_cf_minmax_decimal.py
Normal file
21
netbox/extras/migrations/0133_make_cf_minmax_decimal.py
Normal file
@ -0,0 +1,21 @@
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0132_configcontextprofile'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customfield',
|
||||
name='validation_maximum',
|
||||
field=models.DecimalField(blank=True, decimal_places=4, max_digits=16, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='customfield',
|
||||
name='validation_minimum',
|
||||
field=models.DecimalField(blank=True, decimal_places=4, max_digits=16, null=True),
|
||||
),
|
||||
]
|
@ -174,13 +174,17 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
verbose_name=_('display weight'),
|
||||
help_text=_('Fields with higher weights appear lower in a form.')
|
||||
)
|
||||
validation_minimum = models.BigIntegerField(
|
||||
validation_minimum = models.DecimalField(
|
||||
max_digits=16,
|
||||
decimal_places=4,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_('minimum value'),
|
||||
help_text=_('Minimum allowed value (for numeric fields)')
|
||||
)
|
||||
validation_maximum = models.BigIntegerField(
|
||||
validation_maximum = models.DecimalField(
|
||||
max_digits=16,
|
||||
decimal_places=4,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_('maximum value'),
|
||||
@ -471,7 +475,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
field = forms.DecimalField(
|
||||
required=required,
|
||||
initial=initial,
|
||||
max_digits=12,
|
||||
max_digits=16,
|
||||
decimal_places=4,
|
||||
min_value=self.validation_minimum,
|
||||
max_value=self.validation_maximum
|
||||
@ -534,7 +538,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
||||
|
||||
# JSON
|
||||
elif self.type == CustomFieldTypeChoices.TYPE_JSON:
|
||||
field = JSONField(required=required, initial=json.dumps(initial) if initial else None)
|
||||
field = JSONField(required=required, initial=json.dumps(initial) if initial is not None else None)
|
||||
|
||||
# Object
|
||||
elif self.type == CustomFieldTypeChoices.TYPE_OBJECT:
|
||||
|
@ -1,7 +1,9 @@
|
||||
import datetime
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.test import tag
|
||||
from django.urls import reverse
|
||||
from rest_framework import status
|
||||
|
||||
@ -269,6 +271,60 @@ class CustomFieldTest(TestCase):
|
||||
instance.refresh_from_db()
|
||||
self.assertIsNone(instance.custom_field_data.get(cf.name))
|
||||
|
||||
@tag('regression')
|
||||
def test_json_field_falsy_defaults(self):
|
||||
"""Test that falsy JSON default values are properly handled"""
|
||||
falsy_test_cases = [
|
||||
({}, 'empty_dict'),
|
||||
([], 'empty_array'),
|
||||
(0, 'zero'),
|
||||
(False, 'false_bool'),
|
||||
("", 'empty_string'),
|
||||
]
|
||||
|
||||
for default, suffix in falsy_test_cases:
|
||||
with self.subTest(default=default, suffix=suffix):
|
||||
cf = CustomField.objects.create(
|
||||
name=f'json_falsy_{suffix}',
|
||||
type=CustomFieldTypeChoices.TYPE_JSON,
|
||||
default=default,
|
||||
required=False
|
||||
)
|
||||
cf.object_types.set([self.object_type])
|
||||
|
||||
instance = Site.objects.create(name=f'Test Site {suffix}', slug=f'test-site-{suffix}')
|
||||
|
||||
self.assertIsNotNone(instance.custom_field_data)
|
||||
self.assertIn(cf.name, instance.custom_field_data)
|
||||
|
||||
instance.refresh_from_db()
|
||||
stored = instance.custom_field_data[cf.name]
|
||||
self.assertEqual(stored, default)
|
||||
|
||||
@tag('regression')
|
||||
def test_json_field_falsy_to_form_field(self):
|
||||
"""Test form field generation preserves falsy defaults"""
|
||||
falsy_test_cases = (
|
||||
({}, json.dumps({}), 'empty_dict'),
|
||||
([], json.dumps([]), 'empty_array'),
|
||||
(0, json.dumps(0), 'zero'),
|
||||
(False, json.dumps(False), 'false_bool'),
|
||||
("", '""', 'empty_string'),
|
||||
)
|
||||
|
||||
for default, expected, suffix in falsy_test_cases:
|
||||
with self.subTest(default=default, expected=expected, suffix=suffix):
|
||||
cf = CustomField.objects.create(
|
||||
name=f'json_falsy_{suffix}',
|
||||
type=CustomFieldTypeChoices.TYPE_JSON,
|
||||
default=default,
|
||||
required=False
|
||||
)
|
||||
cf.object_types.set([self.object_type])
|
||||
|
||||
form_field = cf.to_form_field(set_initial=True)
|
||||
self.assertEqual(form_field.initial, expected)
|
||||
|
||||
def test_select_field(self):
|
||||
CHOICES = (
|
||||
('a', 'Option A'),
|
||||
|
@ -84,6 +84,7 @@ CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIS
|
||||
CORS_ORIGIN_WHITELIST = getattr(configuration, 'CORS_ORIGIN_WHITELIST', [])
|
||||
CSRF_COOKIE_NAME = getattr(configuration, 'CSRF_COOKIE_NAME', 'csrftoken')
|
||||
CSRF_COOKIE_PATH = f'/{BASE_PATH.rstrip("/")}'
|
||||
CSRF_COOKIE_HTTPONLY = True
|
||||
CSRF_COOKIE_SECURE = getattr(configuration, 'CSRF_COOKIE_SECURE', False)
|
||||
CSRF_TRUSTED_ORIGINS = getattr(configuration, 'CSRF_TRUSTED_ORIGINS', [])
|
||||
DATA_UPLOAD_MAX_MEMORY_SIZE = getattr(configuration, 'DATA_UPLOAD_MAX_MEMORY_SIZE', 2621440)
|
||||
|
@ -15,7 +15,7 @@ from django.utils.translation import gettext as _
|
||||
|
||||
from core.signals import clear_events
|
||||
from netbox.object_actions import (
|
||||
AddObject, BulkDelete, BulkEdit, BulkExport, BulkImport, CloneObject, DeleteObject, EditObject,
|
||||
BulkDelete, BulkEdit, BulkExport, BulkImport, CloneObject, DeleteObject, EditObject,
|
||||
)
|
||||
from utilities.error_handlers import handle_protectederror
|
||||
from utilities.exceptions import AbortRequest, PermissionsViolation
|
||||
@ -103,7 +103,7 @@ class ObjectChildrenView(ObjectView, ActionsMixin, TableMixin):
|
||||
table = None
|
||||
filterset = None
|
||||
filterset_form = None
|
||||
actions = (AddObject, BulkImport, BulkEdit, BulkExport, BulkDelete)
|
||||
actions = (BulkImport, BulkEdit, BulkExport, BulkDelete)
|
||||
template_name = 'generic/object_children.html'
|
||||
|
||||
def get_children(self, request, parent):
|
||||
|
BIN
netbox/project-static/dist/netbox.css
vendored
BIN
netbox/project-static/dist/netbox.css
vendored
Binary file not shown.
@ -30,7 +30,7 @@
|
||||
|
||||
// Remove the bottom margin of the last <p> elements in markdown
|
||||
.rendered-markdown {
|
||||
p:last-of-type {
|
||||
p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@
|
||||
<td>{{ worker.pid|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">{% trans "Curent Job" %}</th>
|
||||
<th scope="row">{% trans "Current Job" %}</th>
|
||||
<td>{{ job.func_name|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -1,16 +1,14 @@
|
||||
{% load buttons %}
|
||||
{% load i18n %}
|
||||
|
||||
<div class="alert alert-warning" role="alert">
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<i class="mdi mdi-alert p-2"></i>
|
||||
{% blocktrans trimmed with model=model|meta:"verbose_name" prerequisite_model=prerequisite_model|meta:"verbose_name" %}
|
||||
Before you can add a {{ model }} you must first create a <strong>{{ prerequisite_model }}</strong>.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
<div>
|
||||
{% add_button prerequisite_model request.path %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-warning d-flex align-items-center" role="alert">
|
||||
<span class="text-warning fs-1">
|
||||
<i class="mdi mdi-alert"></i>
|
||||
</span>
|
||||
<span class="flex-fill">
|
||||
{% blocktrans trimmed with model=model|meta:"verbose_name" prerequisite_model=prerequisite_model|meta:"verbose_name" %}
|
||||
Before you can add a {{ model }} you must first create a <strong>{{ prerequisite_model }}</strong>.
|
||||
{% endblocktrans %}
|
||||
</span>
|
||||
{% add_button prerequisite_model return_url=request.path %}
|
||||
</div>
|
||||
|
@ -69,7 +69,7 @@ class ContactGroupBulkEditForm(NetBoxModelBulkEditForm):
|
||||
required=False
|
||||
)
|
||||
description = forms.CharField(
|
||||
label=_('Desciption'),
|
||||
label=_('Description'),
|
||||
max_length=200,
|
||||
required=False
|
||||
)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@
|
||||
{{ value|isodatetime }}
|
||||
{% elif customfield.type == 'url' and value %}
|
||||
<a href="{{ value }}">{{ value|truncatechars:70 }}</a>
|
||||
{% elif customfield.type == 'json' and value %}
|
||||
{% elif customfield.type == 'json' and value is not None %}
|
||||
<pre>{{ value|json }}</pre>
|
||||
{% elif customfield.type == 'multiselect' and value %}
|
||||
{{ value|join:", " }}
|
||||
|
@ -107,7 +107,7 @@ class TunnelTerminationImportForm(NetBoxModelImportForm):
|
||||
label=_('Outside IP'),
|
||||
queryset=IPAddress.objects.all(),
|
||||
required=False,
|
||||
to_field_name='name'
|
||||
to_field_name='address'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
@ -14,6 +14,17 @@ class TunnelIndex(SearchIndex):
|
||||
display_attrs = ('group', 'status', 'encapsulation', 'tenant', 'tunnel_id', 'description')
|
||||
|
||||
|
||||
@register_search
|
||||
class TunnelGroupIndex(SearchIndex):
|
||||
model = models.TunnelGroup
|
||||
fields = (
|
||||
('name', 100),
|
||||
('slug', 110),
|
||||
('description', 500),
|
||||
)
|
||||
display_attrs = ('description',)
|
||||
|
||||
|
||||
@register_search
|
||||
class IKEProposalIndex(SearchIndex):
|
||||
model = models.IKEProposal
|
||||
|
22
scripts/verify-openapi.sh
Executable file
22
scripts/verify-openapi.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script checks for differences between the generated OpenAPI schema and the static definition
|
||||
# saved at contrib/openapi.json. If the two are not identical, the script returns an error.
|
||||
|
||||
PROJECT_ROOT="$PWD"
|
||||
CMD="python $PROJECT_ROOT/netbox/manage.py spectacular --format openapi-json"
|
||||
SCHEMA_FILE="$PROJECT_ROOT/contrib/openapi.json"
|
||||
|
||||
# Generate the OpenAPI schema & save it to a temporary file
|
||||
TEMP_FILE=$(mktemp)
|
||||
trap 'rm -f "$TEMP_FILE"' EXIT
|
||||
eval "$CMD > $TEMP_FILE"
|
||||
|
||||
# Run a diff between the original & generated schemas
|
||||
if diff -u "$SCHEMA_FILE" "$TEMP_FILE"; then
|
||||
echo "✅ No changes found."
|
||||
exit 0
|
||||
else
|
||||
echo "❌ Change(s) to OpenAPI schema detected."
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in New Issue
Block a user