Add rudimentary validation to the admin group form acronym field. Partially addresses #3026. Commit ready for merge.

- Legacy-Id: 18205
This commit is contained in:
Robert Sparks 2020-07-20 20:00:05 +00:00
parent 62434faf54
commit 82928b8033

View file

@ -1,6 +1,7 @@
# Copyright The IETF Trust 2010-2020, All Rights Reserved
# -*- coding: utf-8 -*-
import re
from functools import update_wrapper
@ -32,6 +33,15 @@ class GroupForm(forms.ModelForm):
model = Group
fields = '__all__'
def clean_acronym(self):
''' Constrain the acronym form. Note that this doesn't look for collisions.
See ietf.group.forms.GroupForm.clean_acronym()
'''
acronym = self.cleaned_data['acronym'].strip().lower()
if not re.match(r'^[a-z][a-z0-9]+$', acronym):
raise forms.ValidationError("Acronym is invalid, must be at least two characters and only contain lowercase letters and numbers starting with a letter.")
return acronym
def clean_used_roles(self):
data = self.cleaned_data['used_roles']
if data is None or data == '':