Skip to content

Commit

Permalink
feat: Group admin form accepts acronyms starting with numbers for SDO…
Browse files Browse the repository at this point in the history
… groups (#7051)

* feat: Group admin form accepts acronyms starting with numbers for SDO groups (#6825)

* fix: Acronym can't start with hyphen

* fix: Restore some tests
  • Loading branch information
pselkirk authored Feb 20, 2024
1 parent 74ceac7 commit 65cf001
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ietf/group/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright The IETF Trust 2010-2020, All Rights Reserved
# Copyright The IETF Trust 2010-2024, All Rights Reserved
# -*- coding: utf-8 -*-

import re
Expand Down Expand Up @@ -72,6 +72,12 @@ def clean(self):
'Acronym is invalid. For groups that create documents, the acronym must be at least '
'two characters and only contain lowercase letters and numbers starting with a letter.'
)
elif self.cleaned_data['type'].pk == 'sdo':
valid_re = r'^[a-z0-9][a-z0-9-]*[a-z0-9]$'
error_msg = (
'Acronym is invalid. It must be at least two characters and only contain lowercase '
'letters and numbers. It may contain hyphens, but that is discouraged.'
)
else:
valid_re = r'^[a-z][a-z0-9-]*[a-z0-9]$'
error_msg = (
Expand Down
11 changes: 10 additions & 1 deletion ietf/group/tests_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright The IETF Trust 2009-2023, All Rights Reserved
# Copyright The IETF Trust 2009-2024, All Rights Reserved
# -*- coding: utf-8 -*-


Expand Down Expand Up @@ -2044,8 +2044,17 @@ def test_admin_acronym_validation(self):
self.assertTrue(form.is_valid())
form = AdminGroupForm({'acronym':'shouldfail-','name':'should fail','type':'wg','state':'active','used_roles':'[]','time':now})
self.assertIn('acronym',form.errors)
form = AdminGroupForm({'acronym':'shouldfail-','name':'should fail','type':'sdo','state':'active','used_roles':'[]','time':now})
self.assertIn('acronym',form.errors)
form = AdminGroupForm({'acronym':'-shouldfail','name':'should fail','type':'wg','state':'active','used_roles':'[]','time':now})
self.assertIn('acronym',form.errors)
form = AdminGroupForm({'acronym':'-shouldfail','name':'should fail','type':'sdo','state':'active','used_roles':'[]','time':now})
self.assertIn('acronym',form.errors)
# SDO groups (and only SDO groups) can have a leading number
form = AdminGroupForm({'acronym':'3gpp-should-pass','name':'should pass','type':'sdo','state':'active','used_roles':'[]','time':now})
self.assertTrue(form.is_valid())
form = AdminGroupForm({'acronym':'123shouldfail','name':'should fail','type':'wg','state':'active','used_roles':'[]','time':now})
self.assertIn('acronym',form.errors)

wg = GroupFactory(acronym='bad-idea', type_id='wg') # There are some existing wg and programs with hyphens in their acronyms.
form = AdminGroupForm({'acronym':wg.acronym,'name':wg.name,'type':wg.type_id,'state':wg.state_id,'used_roles':str(wg.used_roles),'time':now},instance=wg)
Expand Down

0 comments on commit 65cf001

Please sign in to comment.