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

This commit is contained in:
jeremystretch 2023-04-21 16:06:33 -04:00
parent 390619ca99
commit 053be952ba
2 changed files with 3 additions and 1 deletions

View File

@ -10,6 +10,7 @@
### Bug Fixes ### Bug Fixes
* [#11383](https://github.com/netbox-community/netbox/issues/11383) - Fix ordering of global search results by object type * [#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 * [#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 * [#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 * [#12296](https://github.com/netbox-community/netbox/issues/12296) - Fix "mark connected" form field for bulk editing front & rear ports

View File

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