From 82928b8033be4de0eae08c200836416e62f4f636 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Mon, 20 Jul 2020 20:00:05 +0000 Subject: [PATCH] Add rudimentary validation to the admin group form acronym field. Partially addresses #3026. Commit ready for merge. - Legacy-Id: 18205 --- ietf/group/admin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ietf/group/admin.py b/ietf/group/admin.py index a37741d4f..1a7d59631 100644 --- a/ietf/group/admin.py +++ b/ietf/group/admin.py @@ -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 == '':