Sfoglia il codice sorgente

Fixes #12238: Improve error message for API token IP prefix validation failures

jeremystretch 2 anni fa
parent
commit
053be952ba
2 ha cambiato i file con 3 aggiunte e 1 eliminazioni
  1. 1 0
      docs/release-notes/version-3.4.md
  2. 2 1
      netbox/users/forms.py

+ 1 - 0
docs/release-notes/version-3.4.md

@@ -10,6 +10,7 @@
 ### Bug Fixes
 
 * [#11383](https://github.com/netbox-community/netbox/issues/11383) - Fix ordering of global search results by object type
+* [#12238](https://github.com/netbox-community/netbox/issues/12238) - Improve error message for API token IP prefix validation failures
 * [#12255](https://github.com/netbox-community/netbox/issues/12255) - Restore the ability to move inventory items among devices
 * [#12270](https://github.com/netbox-community/netbox/issues/12270) - Fix pre-population of list values when creating a saved filter
 * [#12296](https://github.com/netbox-community/netbox/issues/12296) - Fix "mark connected" form field for bulk editing front & rear ports

+ 2 - 1
netbox/users/forms.py

@@ -6,6 +6,7 @@ from django.utils.html import mark_safe
 from django.utils.translation import gettext as _
 
 from ipam.formfields import IPNetworkFormField
+from ipam.validators import prefix_validator
 from netbox.preferences import PREFERENCES
 from utilities.forms import BootstrapMixin, DateTimePicker, StaticSelect
 from utilities.utils import flatten_dict
@@ -104,7 +105,7 @@ class TokenForm(BootstrapMixin, forms.ModelForm):
         help_text=_("If no key is provided, one will be generated automatically.")
     )
     allowed_ips = SimpleArrayField(
-        base_field=IPNetworkFormField(),
+        base_field=IPNetworkFormField(validators=[prefix_validator]),
         required=False,
         label=_('Allowed IPs'),
         help_text=_('Allowed IPv4/IPv6 networks from where the token can be used. Leave blank for no restrictions. '