mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 04:42:22 -06:00
Fixes #8030: Validate custom field names
This commit is contained in:
18
netbox/extras/migrations/0066_customfield_name_validation.py
Normal file
18
netbox/extras/migrations/0066_customfield_name_validation.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
import re
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('extras', '0065_imageattachment_change_logging'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customfield',
|
||||
name='name',
|
||||
field=models.CharField(max_length=50, unique=True, validators=[django.core.validators.RegexValidator(flags=re.RegexFlag['IGNORECASE'], message='Only alphanumeric characters and underscores are allowed.', regex='^[a-z0-9_]+$')]),
|
||||
),
|
||||
]
|
||||
@@ -22,6 +22,12 @@ from utilities.querysets import RestrictedQuerySet
|
||||
from utilities.validators import validate_regex
|
||||
|
||||
|
||||
__all__ = (
|
||||
'CustomField',
|
||||
'CustomFieldManager',
|
||||
)
|
||||
|
||||
|
||||
class CustomFieldManager(models.Manager.from_queryset(RestrictedQuerySet)):
|
||||
use_in_migrations = True
|
||||
|
||||
@@ -49,7 +55,14 @@ class CustomField(ChangeLoggedModel):
|
||||
name = models.CharField(
|
||||
max_length=50,
|
||||
unique=True,
|
||||
help_text='Internal field name'
|
||||
help_text='Internal field name',
|
||||
validators=(
|
||||
RegexValidator(
|
||||
regex=r'^[a-z0-9_]+$',
|
||||
message="Only alphanumeric characters and underscores are allowed.",
|
||||
flags=re.IGNORECASE
|
||||
),
|
||||
)
|
||||
)
|
||||
label = models.CharField(
|
||||
max_length=50,
|
||||
|
||||
Reference in New Issue
Block a user