diff --git a/adminsec/tests/test_views.py b/adminsec/tests/test_views.py index 998adb3..fbc29e0 100644 --- a/adminsec/tests/test_views.py +++ b/adminsec/tests/test_views.py @@ -2365,7 +2365,8 @@ def test_ldap_to_hpc_username_institute2(self): def test_ldap_to_hpc_username_invalid_string(self): username = "user" domain = "UNKNOWN" - self.assertEqual(ldap_to_hpc_username(username, domain), "") + with self.assertRaisesMessage(ValueError, "Unknown domain:"): + ldap_to_hpc_username(username, domain) def test_django_to_hpc_username_institute1(self): username = "user@" + settings.AUTH_LDAP_USERNAME_DOMAIN @@ -2381,11 +2382,13 @@ def test_django_to_hpc_username_institute2(self): def test_django_to_hpc_username_invalid_string(self): username = "user@A@B" - self.assertEqual(django_to_hpc_username(username), "") + with self.assertRaisesMessage(ValueError, "Invalid username format:"): + django_to_hpc_username(username) def test_django_to_hpc_username_invalid_domain(self): username = "user@UNKNOWN" - self.assertEqual(django_to_hpc_username(username), "") + with self.assertRaisesMessage(ValueError, "Unknown domain:"): + django_to_hpc_username(username) def test_convert_to_posix(self): name = "LeéèÄAöo" diff --git a/adminsec/views.py b/adminsec/views.py index 66eefe8..f14e188 100644 --- a/adminsec/views.py +++ b/adminsec/views.py @@ -140,25 +140,24 @@ def get_admin_emails(): def ldap_to_hpc_username(username, domain): - fail_string = "" ending = DOMAIN_MAPPING.get(domain.upper()) if not ending: - return fail_string + raise ValueError(f"Unknown domain: {domain}") return f"{username}{HPC_USERNAME_SEPARATOR}{ending}" def django_to_hpc_username(username): - fail_string = "" data = username.split(LDAP_USERNAME_SEPARATOR) - if not len(data) == 2: - return fail_string + if len(data) == 1: + return data[0] - username, domain = data + if len(data) == 2: + return ldap_to_hpc_username(data[0], data[1]) - return ldap_to_hpc_username(username, domain) + raise ValueError(f"Invalid username format: {username}") def ldap_to_django_username(username, domain): diff --git a/usersec/models.py b/usersec/models.py index ad14e24..a1f6192 100644 --- a/usersec/models.py +++ b/usersec/models.py @@ -710,10 +710,16 @@ def role(self): @property def is_pi(self): + if self.primary_group is None: + return False + return self.primary_group.owner == self @property def is_delegate(self): + if self.primary_group is None: + return False + return self.primary_group.delegate == self @property diff --git a/usersec/templates/usersec/hpcgroupcreaterequest_detail.html b/usersec/templates/usersec/hpcgroupcreaterequest_detail.html index dddd18a..e54a859 100644 --- a/usersec/templates/usersec/hpcgroupcreaterequest_detail.html +++ b/usersec/templates/usersec/hpcgroupcreaterequest_detail.html @@ -28,6 +28,11 @@