diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 16182af64..1c330e8a8 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v3.1.6 + placeholder: v3.1.7 validations: required: true - type: dropdown diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index 0be999b16..eea258c09 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v3.1.6 + placeholder: v3.1.7 validations: required: true - type: dropdown diff --git a/base_requirements.txt b/base_requirements.txt index aaa9c7f44..0b8365e0e 100644 --- a/base_requirements.txt +++ b/base_requirements.txt @@ -100,7 +100,7 @@ PyYAML # Social authentication framework # https://github.com/python-social-auth/social-core -social-auth-core[all] +social-auth-core # Django app for social-auth-core # https://github.com/python-social-auth/social-app-django diff --git a/contrib/netbox-housekeeping.sh b/contrib/netbox-housekeeping.sh old mode 100644 new mode 100755 diff --git a/docs/additional-features/webhooks.md b/docs/additional-features/webhooks.md index 3f10cb9e6..5077f3a68 100644 --- a/docs/additional-features/webhooks.md +++ b/docs/additional-features/webhooks.md @@ -1,5 +1,22 @@ {!models/extras/webhook.md!} +## Conditional Webhooks + +A webhook may include a set of conditional logic expressed in JSON used to control whether a webhook triggers for a specific object. For example, you may wish to trigger a webhook for devices only when the `status` field of an object is "active": + +```json +{ + "and": [ + { + "attr": "status.value", + "value": "active" + } + ] +} +``` + +For more detail, see the reference documentation for NetBox's [conditional logic](../reference/conditions.md). + ## Webhook Processing When a change is detected, any resulting webhooks are placed into a Redis queue for processing. This allows the user's request to complete without needing to wait for the outgoing webhook(s) to be processed. The webhooks are then extracted from the queue by the `rqworker` process and HTTP requests are sent to their respective destinations. The current webhook queue and any failed webhooks can be inspected in the admin UI under System > Background Tasks. diff --git a/docs/administration/housekeeping.md b/docs/administration/housekeeping.md index 6f231798d..bbb03dc27 100644 --- a/docs/administration/housekeeping.md +++ b/docs/administration/housekeeping.md @@ -3,7 +3,7 @@ NetBox includes a `housekeeping` management command that should be run nightly. This command handles: * Clearing expired authentication sessions from the database -* Deleting changelog records older than the configured [retention time](../configuration/optional-settings.md#changelog_retention) +* Deleting changelog records older than the configured [retention time](../configuration/dynamic-settings.md#changelog_retention) This command can be invoked directly, or by using the shell script provided at `/opt/netbox/contrib/netbox-housekeeping.sh`. This script can be linked from your cron scheduler's daily jobs directory (e.g. `/etc/cron.daily`) or referenced directly within the cron configuration file. diff --git a/docs/customization/custom-scripts.md b/docs/customization/custom-scripts.md index df436fe99..02af19726 100644 --- a/docs/customization/custom-scripts.md +++ b/docs/customization/custom-scripts.md @@ -77,6 +77,10 @@ This is the human-friendly names of your script. If omitted, the class name will A human-friendly description of what your script does. +### `field_order` + +By default, script variables will be ordered in the form as they are defined in the script. `field_order` may be defined as an iterable of field names to determine the order in which variables are rendered. Any fields not included in this iterable be listed last. + ### `commit_default` The checkbox to commit database changes when executing a script is checked by default. Set `commit_default` to False under the script's Meta class to leave this option unchecked by default. diff --git a/docs/customization/custom-validation.md b/docs/customization/custom-validation.md index bfa1fc1b1..9e01f8bb6 100644 --- a/docs/customization/custom-validation.md +++ b/docs/customization/custom-validation.md @@ -50,7 +50,7 @@ The `fail()` method may optionally specify a field with which to associate the s ## Assigning Custom Validators -Custom validators are associated with specific NetBox models under the [CUSTOM_VALIDATORS](../configuration/optional-settings.md#custom_validators) configuration parameter. There are three manners by which custom validation rules can be defined: +Custom validators are associated with specific NetBox models under the [CUSTOM_VALIDATORS](../configuration/dynamic-settings.md#custom_validators) configuration parameter. There are three manners by which custom validation rules can be defined: 1. Plain JSON mapping (no custom logic) 2. Dotted path to a custom validator class diff --git a/docs/development/getting-started.md b/docs/development/getting-started.md index 742e93804..0e892bd4a 100644 --- a/docs/development/getting-started.md +++ b/docs/development/getting-started.md @@ -122,22 +122,22 @@ The demo data is provided in JSON format and loaded into an empty database using ## Running Tests -Prior to committing any substantial changes to the code base, be sure to run NetBox's test suite to catch any potential errors. Tests are run using the `test` management command. Remember to ensure the Python virtual environment is active before running this command. +Prior to committing any substantial changes to the code base, be sure to run NetBox's test suite to catch any potential errors. Tests are run using the `test` management command. Remember to ensure the Python virtual environment is active before running this command. Also keep in mind that these commands are executed in the `/netbox/` directory, not the root directory of the repository. ```no-highlight -$ python netbox/manage.py test +$ python manage.py test ``` In cases where you haven't made any changes to the database (which is most of the time), you can append the `--keepdb` argument to this command to reuse the test database between runs. This cuts down on the time it takes to run the test suite since the database doesn't have to be rebuilt each time. (Note that this argument will cause errors if you've modified any model fields since the previous test run.) ```no-highlight -$ python netbox/manage.py test --keepdb +$ python manage.py test --keepdb ``` You can also limit the command to running only a specific subset of tests. For example, to run only IPAM and DCIM view tests: ```no-highlight -$ python netbox/manage.py test dcim.tests.test_views ipam.tests.test_views +$ python manage.py test dcim.tests.test_views ipam.tests.test_views ``` ## Submitting Pull Requests diff --git a/docs/graphql-api/overview.md b/docs/graphql-api/overview.md index f4cdc5fba..57dfb22bd 100644 --- a/docs/graphql-api/overview.md +++ b/docs/graphql-api/overview.md @@ -67,4 +67,4 @@ Authorization: Token $TOKEN ## Disabling the GraphQL API -If not needed, the GraphQL API can be disabled by setting the [`GRAPHQL_ENABLED`](../configuration/optional-settings.md#graphql_enabled) configuration parameter to False and restarting NetBox. +If not needed, the GraphQL API can be disabled by setting the [`GRAPHQL_ENABLED`](../configuration/dynamic-settings.md#graphql_enabled) configuration parameter to False and restarting NetBox. diff --git a/docs/models/extras/webhook.md b/docs/models/extras/webhook.md index c71657336..eb47dd332 100644 --- a/docs/models/extras/webhook.md +++ b/docs/models/extras/webhook.md @@ -81,16 +81,3 @@ If no body template is specified, the request body will be populated with a JSON } } ``` - -## Conditional Webhooks - -A webhook may include a set of conditional logic expressed in JSON used to control whether a webhook triggers for a specific object. For example, you may wish to trigger a webhook for devices only when the `status` field of an object is "active": - -```json -{ - "attr": "status", - "value": "active" -} -``` - -For more detail, see the reference documentation for NetBox's [conditional logic](../reference/conditions.md). diff --git a/docs/reference/conditions.md b/docs/reference/conditions.md index 40b2ccb4b..fb8b66139 100644 --- a/docs/reference/conditions.md +++ b/docs/reference/conditions.md @@ -81,13 +81,16 @@ The following condition will evaluate as true: ```json { - "attr": "status", + "attr": "status.value", "value": ["planned", "staging"], "op": "in", "negate": true } ``` +!!! note "Evaluating static choice fields" + Pay close attention when evaluating static choice fields, such as the `status` field above. These fields typically render as a dictionary specifying both the field's raw value (`value`) and its human-friendly label (`label`). be sure to specify on which of these you want to match. + ## Condition Sets Multiple conditions can be combined into nested sets using AND or OR logic. This is done by declaring a JSON object with a single key (`and` or `or`) containing a list of condition objects and/or child condition sets. @@ -102,7 +105,7 @@ Multiple conditions can be combined into nested sets using AND or OR logic. This { "and": [ { - "attr": "status", + "attr": "status.value", "value": "active" }, { diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index 51ad02395..7d6341f44 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -367,7 +367,7 @@ More information about IP ranges is available [in the documentation](../models/i #### Custom Model Validation ([#5963](https://github.com/netbox-community/netbox/issues/5963)) -This release introduces the [`CUSTOM_VALIDATORS`](../configuration/optional-settings.md#custom_validators) configuration parameter, which allows administrators to map NetBox models to custom validator classes to enforce custom validation logic. For example, the following configuration requires every site to have a name of at least ten characters and a description: +This release introduces the [`CUSTOM_VALIDATORS`](../configuration/dynamic-settings.md#custom_validators) configuration parameter, which allows administrators to map NetBox models to custom validator classes to enforce custom validation logic. For example, the following configuration requires every site to have a name of at least ten characters and a description: ```python from extras.validators import CustomValidator diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index 88a6da77f..27aaa4b4c 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -1,5 +1,34 @@ # NetBox v3.1 +## v3.1.7 (2022-02-03) + +### Enhancements + +* [#7504](https://github.com/netbox-community/netbox/issues/7504) - Include IP range data under IPAM role views +* [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs +* [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function +* [#8368](https://github.com/netbox-community/netbox/issues/8368) - Enable controlling the order of custom script form fields with `field_order` +* [#8381](https://github.com/netbox-community/netbox/issues/8381) - Add contacts to global search function +* [#8462](https://github.com/netbox-community/netbox/issues/8462) - Linkify manufacturer column in device type table +* [#8476](https://github.com/netbox-community/netbox/issues/8476) - Bring the ASN Web UI up to the standard set by other objects +* [#8494](https://github.com/netbox-community/netbox/issues/8494) - Include locations count under tenant view +* [#8517](https://github.com/netbox-community/netbox/issues/8517) - Render boolean custom fields as icons in object tables +* [#8530](https://github.com/netbox-community/netbox/issues/8530) - Indicate CSV or YAML as format for "all data" export + +### Bug Fixes + +* [#8315](https://github.com/netbox-community/netbox/issues/8315) - Fix display of NAT link for primary IPv4 address under device view +* [#8377](https://github.com/netbox-community/netbox/issues/8377) - Fix calculation of absolute cable lengths when specified in fractional units +* [#8425](https://github.com/netbox-community/netbox/issues/8425) - Fix exception when viewing change list/records with removed plugins +* [#8456](https://github.com/netbox-community/netbox/issues/8456) - Fix redundant display of VRF RD in prefix view +* [#8465](https://github.com/netbox-community/netbox/issues/8465) - Accept empty string values for Interface `rf_channel` in REST API +* [#8498](https://github.com/netbox-community/netbox/issues/8498) - Fix display of selected content type filters in object list views +* [#8499](https://github.com/netbox-community/netbox/issues/8499) - Content types REST API endpoint should not require model permission +* [#8512](https://github.com/netbox-community/netbox/issues/8512) - Correct file permissions to allow execution of housekeeping script +* [#8527](https://github.com/netbox-community/netbox/issues/8527) - Fix display of changelog retention period + +--- + ## v3.1.6 (2022-01-17) ### Enhancements diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index 337fd35c6..6549e51a1 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -621,7 +621,7 @@ class InterfaceSerializer(PrimaryModelSerializer, LinkTerminationSerializer, Con lag = NestedInterfaceSerializer(required=False, allow_null=True) mode = ChoiceField(choices=InterfaceModeChoices, allow_blank=True, required=False) rf_role = ChoiceField(choices=WirelessRoleChoices, required=False, allow_null=True) - rf_channel = ChoiceField(choices=WirelessChannelChoices, required=False) + rf_channel = ChoiceField(choices=WirelessChannelChoices, required=False, allow_blank=True) untagged_vlan = NestedVLANSerializer(required=False, allow_null=True) tagged_vlans = SerializedPKRelatedField( queryset=VLAN.objects.all(), diff --git a/netbox/dcim/migrations/0144_fix_cable_abs_length.py b/netbox/dcim/migrations/0144_fix_cable_abs_length.py new file mode 100644 index 000000000..0da30ffb5 --- /dev/null +++ b/netbox/dcim/migrations/0144_fix_cable_abs_length.py @@ -0,0 +1,31 @@ +from django.db import migrations + +from utilities.utils import to_meters + + +def recalculate_abs_length(apps, schema_editor): + """ + Recalculate absolute lengths for all cables with a length and length unit defined. Fixes + incorrectly calculated values as reported under bug #8377. + """ + Cable = apps.get_model('dcim', 'Cable') + + cables = Cable.objects.filter(length__isnull=False).exclude(length_unit='') + for cable in cables: + cable._abs_length = to_meters(cable.length, cable.length_unit) + + Cable.objects.bulk_update(cables, ['_abs_length'], batch_size=100) + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0143_remove_primary_for_related_name'), + ] + + operations = [ + migrations.RunPython( + code=recalculate_abs_length, + reverse_code=migrations.RunPython.noop + ), + ] diff --git a/netbox/dcim/tables/cables.py b/netbox/dcim/tables/cables.py index bea2c0adf..9f2c08342 100644 --- a/netbox/dcim/tables/cables.py +++ b/netbox/dcim/tables/cables.py @@ -45,7 +45,7 @@ class CableTable(BaseTable): tenant = TenantColumn() length = TemplateColumn( template_code=CABLE_LENGTH, - order_by='_abs_length' + order_by=('_abs_length', 'length_unit') ) color = ColorColumn() tags = TagColumn( diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 5f15d5fbf..3c2b3dace 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -261,7 +261,7 @@ class CableTerminationTable(BaseTable): linkify=True ) cable_color = ColorColumn( - accessor='cable.color', + accessor='cable__color', orderable=False, verbose_name='Cable Color' ) @@ -276,7 +276,7 @@ class CableTerminationTable(BaseTable): class PathEndpointTable(CableTerminationTable): connection = TemplateColumn( - accessor='_path.last_node', + accessor='_path__last_node', template_code=LINKTERMINATION, verbose_name='Connection', orderable=False diff --git a/netbox/dcim/tables/devicetypes.py b/netbox/dcim/tables/devicetypes.py index dc437ee96..5643edc37 100644 --- a/netbox/dcim/tables/devicetypes.py +++ b/netbox/dcim/tables/devicetypes.py @@ -67,6 +67,9 @@ class DeviceTypeTable(BaseTable): linkify=True, verbose_name='Device Type' ) + manufacturer = tables.Column( + linkify=True + ) is_full_depth = BooleanColumn( verbose_name='Full Depth' ) diff --git a/netbox/dcim/tables/sites.py b/netbox/dcim/tables/sites.py index 83e5fa408..e658f1caa 100644 --- a/netbox/dcim/tables/sites.py +++ b/netbox/dcim/tables/sites.py @@ -82,7 +82,7 @@ class SiteTable(BaseTable): linkify=True ) asn_count = LinkedCountColumn( - accessor=tables.A('asns.count'), + accessor=tables.A('asns__count'), viewname='ipam:asn_list', url_params={'site_id': 'pk'}, verbose_name='ASNs' diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index ccca32be8..233694a7a 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -9,7 +9,8 @@ LINKTERMINATION = """ """ CABLE_LENGTH = """ -{% if record.length %}{{ record.length }} {{ record.get_length_unit_display }}{% endif %} +{% load helpers %} +{% if record.length %}{{ record.length|simplify_decimal }} {{ record.length_unit }}{% endif %} """ CABLE_TERMINATION_PARENT = """ diff --git a/netbox/dcim/tests/test_api.py b/netbox/dcim/tests/test_api.py index bc6b18ead..f403fa3eb 100644 --- a/netbox/dcim/tests/test_api.py +++ b/netbox/dcim/tests/test_api.py @@ -9,6 +9,7 @@ from dcim.models import * from ipam.models import ASN, RIR, VLAN from utilities.testing import APITestCase, APIViewTestCases from virtualization.models import Cluster, ClusterType +from wireless.choices import WirelessChannelChoices from wireless.models import WirelessLAN @@ -1239,10 +1240,8 @@ class InterfaceTest(Mixins.ComponentTraceMixin, APIViewTestCases.APIViewTestCase 'name': 'Interface 4', 'type': '1000base-t', 'mode': InterfaceModeChoices.MODE_TAGGED, - 'tx_power': 10, 'tagged_vlans': [vlans[0].pk, vlans[1].pk], 'untagged_vlan': vlans[2].pk, - 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], }, { 'device': device.pk, @@ -1250,10 +1249,8 @@ class InterfaceTest(Mixins.ComponentTraceMixin, APIViewTestCases.APIViewTestCase 'type': '1000base-t', 'mode': InterfaceModeChoices.MODE_TAGGED, 'bridge': interfaces[0].pk, - 'tx_power': 10, 'tagged_vlans': [vlans[0].pk, vlans[1].pk], 'untagged_vlan': vlans[2].pk, - 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], }, { 'device': device.pk, @@ -1261,10 +1258,24 @@ class InterfaceTest(Mixins.ComponentTraceMixin, APIViewTestCases.APIViewTestCase 'type': 'virtual', 'mode': InterfaceModeChoices.MODE_TAGGED, 'parent': interfaces[1].pk, - 'tx_power': 10, 'tagged_vlans': [vlans[0].pk, vlans[1].pk], 'untagged_vlan': vlans[2].pk, + }, + { + 'device': device.pk, + 'name': 'Interface 7', + 'type': InterfaceTypeChoices.TYPE_80211A, + 'tx_power': 10, 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], + 'rf_channel': WirelessChannelChoices.CHANNEL_5G_32, + }, + { + 'device': device.pk, + 'name': 'Interface 8', + 'type': InterfaceTypeChoices.TYPE_80211A, + 'tx_power': 10, + 'wireless_lans': [wireless_lans[0].pk, wireless_lans[1].pk], + 'rf_channel': "", }, ] diff --git a/netbox/extras/api/views.py b/netbox/extras/api/views.py index fbeba8328..074a33823 100644 --- a/netbox/extras/api/views.py +++ b/netbox/extras/api/views.py @@ -4,6 +4,7 @@ from django_rq.queues import get_connection from rest_framework import status from rest_framework.decorators import action from rest_framework.exceptions import PermissionDenied +from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.routers import APIRootView from rest_framework.viewsets import ReadOnlyModelViewSet, ViewSet @@ -382,6 +383,7 @@ class ContentTypeViewSet(ReadOnlyModelViewSet): """ Read-only list of ContentTypes. Limit results to ContentTypes pertinent to NetBox objects. """ + permission_classes = (IsAuthenticated,) queryset = ContentType.objects.order_by('app_label', 'model') serializer_class = serializers.ContentTypeSerializer filterset_class = filtersets.ContentTypeFilterSet diff --git a/netbox/extras/forms/bulk_edit.py b/netbox/extras/forms/bulk_edit.py index 1b87256a5..45b48e9a2 100644 --- a/netbox/extras/forms/bulk_edit.py +++ b/netbox/extras/forms/bulk_edit.py @@ -44,7 +44,7 @@ class CustomLinkBulkEditForm(BulkEditForm): ) content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('custom_links'), required=False ) new_window = forms.NullBooleanField( @@ -71,7 +71,7 @@ class ExportTemplateBulkEditForm(BulkEditForm): ) content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('export_templates'), required=False ) description = forms.CharField( diff --git a/netbox/extras/forms/filtersets.py b/netbox/extras/forms/filtersets.py index 03cd170b8..3848dcb0d 100644 --- a/netbox/extras/forms/filtersets.py +++ b/netbox/extras/forms/filtersets.py @@ -62,7 +62,7 @@ class CustomLinkFilterForm(FilterForm): ] content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('custom_links'), required=False ) weight = forms.IntegerField( @@ -83,7 +83,7 @@ class ExportTemplateFilterForm(FilterForm): ] content_type = ContentTypeChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('export_templates'), required=False ) mime_type = forms.CharField( @@ -109,7 +109,7 @@ class WebhookFilterForm(FilterForm): ] content_types = ContentTypeMultipleChoiceField( queryset=ContentType.objects.all(), - limit_choices_to=FeatureQuery('custom_fields'), + limit_choices_to=FeatureQuery('webhooks'), required=False ) http_method = forms.MultipleChoiceField( diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 3c7ad3c15..fb3c6558a 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -296,12 +296,21 @@ class BaseScript: @classmethod def _get_vars(cls): - vars = OrderedDict() + vars = {} for name, attr in cls.__dict__.items(): if name not in vars and issubclass(attr.__class__, ScriptVariable): vars[name] = attr - return vars + # Order variables according to field_order + field_order = getattr(cls.Meta, 'field_order', None) + if not field_order: + return vars + ordered_vars = { + field: vars.pop(field) for field in field_order if field in vars + } + ordered_vars.update(vars) + + return ordered_vars def run(self, data, commit): raise NotImplementedError("The script must define a run() method.") diff --git a/netbox/extras/tables.py b/netbox/extras/tables.py index bee21f697..7cc29005f 100644 --- a/netbox/extras/tables.py +++ b/netbox/extras/tables.py @@ -30,7 +30,7 @@ CONFIGCONTEXT_ACTIONS = """ """ OBJECTCHANGE_OBJECT = """ -{% if record.changed_object.get_absolute_url %} +{% if record.changed_object and record.changed_object.get_absolute_url %} {{ record.object_repr }} {% else %} {{ record.object_repr }} diff --git a/netbox/extras/tests/test_api.py b/netbox/extras/tests/test_api.py index d15b57e43..8769a9015 100644 --- a/netbox/extras/tests/test_api.py +++ b/netbox/extras/tests/test_api.py @@ -608,7 +608,6 @@ class CreatedUpdatedFilterTest(APITestCase): class ContentTypeTest(APITestCase): - @override_settings(EXEMPT_VIEW_PERMISSIONS=['contenttypes.contenttype']) def test_list_objects(self): contenttype_count = ContentType.objects.count() @@ -616,7 +615,6 @@ class ContentTypeTest(APITestCase): self.assertHttpStatus(response, status.HTTP_200_OK) self.assertEqual(response.data['count'], contenttype_count) - @override_settings(EXEMPT_VIEW_PERMISSIONS=['contenttypes.contenttype']) def test_get_object(self): contenttype = ContentType.objects.first() diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py index df6ee1055..d7e1ee47e 100644 --- a/netbox/ipam/filtersets.py +++ b/netbox/ipam/filtersets.py @@ -209,6 +209,10 @@ class ASNFilterSet(OrganizationalModelFilterSet, TenancyFilterSet): if not value.strip(): return queryset qs_filter = Q(description__icontains=value) + try: + qs_filter |= Q(asn=int(value)) + except ValueError: + pass return queryset.filter(qs_filter) diff --git a/netbox/ipam/tables/fhrp.py b/netbox/ipam/tables/fhrp.py index a8a25f319..d615b6374 100644 --- a/netbox/ipam/tables/fhrp.py +++ b/netbox/ipam/tables/fhrp.py @@ -46,7 +46,7 @@ class FHRPGroupTable(BaseTable): class FHRPGroupAssignmentTable(BaseTable): pk = ToggleColumn() interface_parent = tables.Column( - accessor=tables.A('interface.parent_object'), + accessor=tables.A('interface__parent_object'), linkify=True, orderable=False, verbose_name='Parent' diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index f188a21c0..2cd2ab6ac 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -107,21 +107,32 @@ class RIRTable(BaseTable): class ASNTable(BaseTable): pk = ToggleColumn() asn = tables.Column( - accessor=tables.A('asn_asdot'), linkify=True ) - + asn_asdot = tables.Column( + accessor=tables.A('asn_asdot'), + linkify=True, + verbose_name='ASDOT' + ) site_count = LinkedCountColumn( viewname='dcim:site_list', url_params={'asn_id': 'pk'}, verbose_name='Sites' ) + tenant = TenantColumn() + tags = TagColumn( + url_name='ipam:asn_list' + ) + actions = ButtonsColumn(ASN) class Meta(BaseTable.Meta): model = ASN - fields = ('pk', 'asn', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', 'last_updated',) - default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'tenant', 'actions') + fields = ( + 'pk', 'asn', 'asn_asdot', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', + 'last_updated', 'tags', + ) + default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'description', 'tenant', 'actions') # @@ -173,6 +184,11 @@ class RoleTable(BaseTable): url_params={'role_id': 'pk'}, verbose_name='Prefixes' ) + iprange_count = LinkedCountColumn( + viewname='ipam:iprange_list', + url_params={'role_id': 'pk'}, + verbose_name='IP Ranges' + ) vlan_count = LinkedCountColumn( viewname='ipam:vlan_list', url_params={'role_id': 'pk'}, @@ -186,10 +202,10 @@ class RoleTable(BaseTable): class Meta(BaseTable.Meta): model = Role fields = ( - 'pk', 'id', 'name', 'slug', 'prefix_count', 'vlan_count', 'description', 'weight', 'tags', 'actions', - 'created', 'last_updated', + 'pk', 'id', 'name', 'slug', 'prefix_count', 'iprange_count', 'vlan_count', 'description', 'weight', 'tags', + 'actions', 'created', 'last_updated', ) - default_columns = ('pk', 'name', 'prefix_count', 'vlan_count', 'description', 'actions') + default_columns = ('pk', 'name', 'prefix_count', 'iprange_count', 'vlan_count', 'description', 'actions') # @@ -352,7 +368,7 @@ class IPAddressTable(BaseTable): verbose_name='Interface' ) assigned_object_parent = tables.Column( - accessor='assigned_object.parent_object', + accessor='assigned_object__parent_object', linkify=True, orderable=False, verbose_name='Device/VM' diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 38b30e9cc..c9ac44f46 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -340,6 +340,7 @@ class AggregateBulkDeleteView(generic.BulkDeleteView): class RoleListView(generic.ObjectListView): queryset = Role.objects.annotate( prefix_count=count_related(Prefix, 'role'), + iprange_count=count_related(IPRange, 'role'), vlan_count=count_related(VLAN, 'role') ) filterset = filtersets.RoleFilterSet diff --git a/netbox/netbox/constants.py b/netbox/netbox/constants.py index 3e935e722..be5f12980 100644 --- a/netbox/netbox/constants.py +++ b/netbox/netbox/constants.py @@ -12,12 +12,14 @@ from dcim.tables import ( CableTable, DeviceTable, DeviceTypeTable, PowerFeedTable, RackTable, RackReservationTable, LocationTable, SiteTable, VirtualChassisTable, ) -from ipam.filtersets import AggregateFilterSet, IPAddressFilterSet, PrefixFilterSet, VLANFilterSet, VRFFilterSet -from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF -from ipam.tables import AggregateTable, IPAddressTable, PrefixTable, VLANTable, VRFTable -from tenancy.filtersets import TenantFilterSet -from tenancy.models import Tenant -from tenancy.tables import TenantTable +from ipam.filtersets import ( + AggregateFilterSet, ASNFilterSet, IPAddressFilterSet, PrefixFilterSet, VLANFilterSet, VRFFilterSet, +) +from ipam.models import Aggregate, ASN, IPAddress, Prefix, VLAN, VRF +from ipam.tables import AggregateTable, ASNTable, IPAddressTable, PrefixTable, VLANTable, VRFTable +from tenancy.filtersets import ContactFilterSet, TenantFilterSet +from tenancy.models import Contact, Tenant +from tenancy.tables import ContactTable, TenantTable from utilities.utils import count_related from virtualization.filtersets import ClusterFilterSet, VirtualMachineFilterSet from virtualization.models import Cluster, VirtualMachine @@ -170,6 +172,12 @@ SEARCH_TYPES = OrderedDict(( 'table': VLANTable, 'url': 'ipam:vlan_list', }), + ('asn', { + 'queryset': ASN.objects.prefetch_related('rir', 'tenant'), + 'filterset': ASNFilterSet, + 'table': ASNTable, + 'url': 'ipam:asn_list', + }), # Tenancy ('tenant', { 'queryset': Tenant.objects.prefetch_related('group'), @@ -177,4 +185,10 @@ SEARCH_TYPES = OrderedDict(( 'table': TenantTable, 'url': 'tenancy:tenant_list', }), + ('contact', { + 'queryset': Contact.objects.prefetch_related('group', 'assignments'), + 'filterset': ContactFilterSet, + 'table': ContactTable, + 'url': 'tenancy:contact_list', + }), )) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index ff767b4d8..d69c45fc9 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -19,7 +19,7 @@ from netbox.config import PARAMS # Environment setup # -VERSION = '3.1.6' +VERSION = '3.1.7' # Hostname HOSTNAME = platform.node() diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 31f2a18bd..35224a1fc 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -188,7 +188,7 @@ {% if object.primary_ip4 %} {{ object.primary_ip4.address.ip }} {% if object.primary_ip4.nat_inside %} - (NAT for {{ object.primary_ip4.nat_inside.address.ip }}) + (NAT for {{ object.primary_ip4.nat_inside.address.ip }}) {% elif object.primary_ip4.nat_outside %} (NAT: {{ object.primary_ip4.nat_outside.address.ip }}) {% endif %} diff --git a/netbox/templates/extras/object_changelog.html b/netbox/templates/extras/object_changelog.html index d84ba0b7a..d064ab435 100644 --- a/netbox/templates/extras/object_changelog.html +++ b/netbox/templates/extras/object_changelog.html @@ -11,7 +11,7 @@
Rack reservations
+Locations
+ASNs
+Prefixes
diff --git a/netbox/tenancy/views.py b/netbox/tenancy/views.py index b0f550304..4c9fffa1a 100644 --- a/netbox/tenancy/views.py +++ b/netbox/tenancy/views.py @@ -1,10 +1,9 @@ from django.contrib.contenttypes.models import ContentType -from django.http import Http404 from django.shortcuts import get_object_or_404 from circuits.models import Circuit -from dcim.models import Site, Rack, Device, RackReservation, Cable -from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF +from dcim.models import Cable, Device, Location, Rack, RackReservation, Site +from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF, ASN from netbox.views import generic from utilities.tables import paginate_table from utilities.utils import count_related @@ -103,6 +102,7 @@ class TenantView(generic.ObjectView): 'site_count': Site.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'rack_count': Rack.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'rackreservation_count': RackReservation.objects.restrict(request.user, 'view').filter(tenant=instance).count(), + 'location_count': Location.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'device_count': Device.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'vrf_count': VRF.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'prefix_count': Prefix.objects.restrict(request.user, 'view').filter(tenant=instance).count(), @@ -113,6 +113,7 @@ class TenantView(generic.ObjectView): 'virtualmachine_count': VirtualMachine.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'cluster_count': Cluster.objects.restrict(request.user, 'view').filter(tenant=instance).count(), 'cable_count': Cable.objects.restrict(request.user, 'view').filter(tenant=instance).count(), + 'asn_count': ASN.objects.restrict(request.user, 'view').filter(tenant=instance).count(), } return { diff --git a/netbox/utilities/forms/utils.py b/netbox/utilities/forms/utils.py index 343fdb8a3..6d45d524d 100644 --- a/netbox/utilities/forms/utils.py +++ b/netbox/utilities/forms/utils.py @@ -127,12 +127,13 @@ def get_selected_values(form, field_name): if not hasattr(field, 'choices'): return [str(filter_data)] - # Get choice labels + # Model choice field if type(field.choices) is forms.models.ModelChoiceIterator: - # Field uses dynamic choices: show all that have been populated on the widget - values = [ - subwidget.choice_label for subwidget in form[field_name].subwidgets - ] + # If this is a single-choice field, wrap its value in a list + if not hasattr(filter_data, '__iter__'): + values = [filter_data] + else: + values = filter_data else: # Static selection field diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index c640e0e85..0b67434b1 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -414,13 +414,23 @@ class CustomFieldColumn(tables.Column): def render(self, value): if isinstance(value, list): return ', '.join(v for v in value) + elif self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is True: + return mark_safe('') + elif self.customfield.type == CustomFieldTypeChoices.TYPE_BOOLEAN and value is False: + return mark_safe('') elif self.customfield.type == CustomFieldTypeChoices.TYPE_URL: - # Linkify custom URLs return mark_safe(f'{value}') if value is not None: return value return self.default + def value(self, value): + if isinstance(value, list): + return ','.join(v for v in value) + if value is not None: + return value + return self.default + class CustomLinkColumn(tables.Column): """ diff --git a/netbox/utilities/templates/buttons/export.html b/netbox/utilities/templates/buttons/export.html index 20ecc2dff..bb6e4379c 100644 --- a/netbox/utilities/templates/buttons/export.html +++ b/netbox/utilities/templates/buttons/export.html @@ -1,31 +1,31 @@