From 3221fa6c4cc7dad184c53ed7c1476102852df1c7 Mon Sep 17 00:00:00 2001 From: Oliver Stolpe Date: Wed, 8 Jan 2025 16:56:36 +0100 Subject: [PATCH] feat: option to allow registering all mail addresses --- adminsec/ldap.py | 3 +++ adminsec/views.py | 4 +++- config/settings/base.py | 3 +++ usersec/forms.py | 13 ++++++++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/adminsec/ldap.py b/adminsec/ldap.py index e2dd865..833d56d 100644 --- a/adminsec/ldap.py +++ b/adminsec/ldap.py @@ -112,6 +112,9 @@ def get_ldap_username_domain_by_mail(self, mail): search_base = settings.AUTH_LDAP2_USER_SEARCH_BASE domain = settings.AUTH_LDAP2_USERNAME_DOMAIN + elif settings.STAGING: + return mail.split("@")[0].lower(), "" + else: logger.error("Email %s not valid" % mail) raise ImproperlyConfigured("Email %s not valid" % mail) diff --git a/adminsec/views.py b/adminsec/views.py index f14e188..5aa6d1f 100644 --- a/adminsec/views.py +++ b/adminsec/views.py @@ -558,10 +558,12 @@ def post(self, request, *args, **kwargs): ) ) + django_username = ldap_to_django_username(username, domain) if domain else username + try: with transaction.atomic(): invitation = HpcGroupInvitation.objects.create_with_version( - hpcusercreaterequest=obj, username=ldap_to_django_username(username, domain) + hpcusercreaterequest=obj, username=django_username ) except Exception as e: diff --git a/config/settings/base.py b/config/settings/base.py index f332e1e..ecfd906 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -423,6 +423,9 @@ # View mode - disable all request options VIEW_MODE = env.bool("VIEW_MODE", False) +# Staging - primarily to allow for inviting external addresses for testing +STAGING = env.bool("STAGING", False) + # Cron settings CRON_QUOTA_EMAIL_YELLOW_DOW = env.str("CRON_QUOTA_EMAIL_YELLOW_DOW", "1") CRON_QUOTA_EMAIL_YELLOW_HOUR = env.str("CRON_QUOTA_EMAIL_YELLOW_HOUR", "0") diff --git a/usersec/forms.py b/usersec/forms.py index f9cb3f1..6689ab0 100644 --- a/usersec/forms.py +++ b/usersec/forms.py @@ -259,9 +259,16 @@ def clean(self): self.add_error("email", "This user is already registered.") return - if email_split[1].lower() not in valid_domains: - self.add_error("email", "No institute email address.") - return + if not settings.STAGING: + if email_split[1].lower() not in valid_domains: + self.add_error( + "email", + ( + "This is no institute email address. " + f"Valid domains are: {', '.join(valid_domains)}", + ), + ) + return return cleaned_data