From f694889424301e022a6a0bedce2543739969edd4 Mon Sep 17 00:00:00 2001
From: msb <mike@msb.me.uk>
Date: Thu, 9 May 2019 15:25:26 +0100
Subject: [PATCH] Fixed a problem where validate_groupid_list() failed to
 validate a group id if it had leading zeroes. Removed the conversion of the
 id to an int when passing to get_or_create_group_by_groupid(). Unnecessary as
 the id was already validated with a regex.

---
 CHANGELOG           | 6 ++++++
 setup.py            | 2 +-
 ucamlookup/tests.py | 8 ++++++++
 ucamlookup/utils.py | 2 +-
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 0bd5d1a..cc90f9e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,12 @@
 django-ucamlookup changelog
 =============================
 
+3.0.3 - 09/05/2019
+------------------
+
+- Fixed a problem where validate_groupid_list() failed to validate a group id if it had leading
+zeroes.
+
 3.0.2 - 30/04/2019
 ------------------
 
diff --git a/setup.py b/setup.py
index d63c0e7..d0b0850 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ setup(
     long_description=open('README.md').read(),
     long_description_content_type='text/markdown',
     url='https://gitlab.developers.cam.ac.uk/uis/devops/django/ucamlookup',
-    version='3.0.2',
+    version='3.0.3',
     license='MIT',
     author='DevOps Division, University Information Services, University of Cambridge',
     author_email='devops@uis.cam.ac.uk',
diff --git a/ucamlookup/tests.py b/ucamlookup/tests.py
index 8c1ec6e..71cab5e 100644
--- a/ucamlookup/tests.py
+++ b/ucamlookup/tests.py
@@ -71,6 +71,8 @@ class UcamLookupTests(TestCase):
                 mock_result.group.title = 'CS Information Systems team'
             elif path == 'api/v1/group/101923':
                 mock_result.group.title = 'UIS Finance team'
+            elif path == 'api/v1/group/001161':
+                mock_result.group.title = 'Members of "Magdalene College".'
             elif path == 'api/v1/group/203840928304982':
                 mock_result.group = None
             elif path == 'api/v1/person/search':
@@ -267,6 +269,12 @@ class UcamLookupTests(TestCase):
         with self.assertRaises(ValidationError):
             validate_groupid_list(["kaskvdkam20e9mciasmdimadf"])
 
+    def test_validate_groupid_list_leading_zeroes(self):
+        """Check that group ids with leading zeroes are correctly validated"""
+        user_list = validate_groupid_list(['001161'])
+        self.assertEqual(user_list[0].lookup_id, '001161')
+        self.assertEqual(user_list[0].name, 'Members of "Magdalene College".')
+
     def test_get_user_lookupgroups(self):
         amc203 = User.objects.create_user(username="amc203")
         groups = get_user_lookupgroups(amc203)
diff --git a/ucamlookup/utils.py b/ucamlookup/utils.py
index 2f20b28..751d6fa 100644
--- a/ucamlookup/utils.py
+++ b/ucamlookup/utils.py
@@ -241,7 +241,7 @@ def validate_groupid_list(groupids):
 
     for groupid in groupids:
         if groupid_re.match(groupid):
-            groups += (get_or_create_group_by_groupid(int(groupid)),)
+            groups += (get_or_create_group_by_groupid(groupid),)
         else:
             raise ValidationError("The list of groups contains an invalid group")
 
-- 
GitLab