Skip to content

Commit

Permalink
feat: option to allow registering all mail addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
stolpeo committed Jan 8, 2025
1 parent cf79065 commit 3221fa6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions adminsec/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion adminsec/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 10 additions & 3 deletions usersec/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3221fa6

Please sign in to comment.