Skip to content

Commit 775fefd

Browse files
feat: add allowed email domains for SBP registration to settings
1 parent 6f762bb commit 775fefd

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ class Settings(BaseSettings):
2121
cors_allowed_origins: str
2222
# AAI Portal URL for admin links in emails
2323
aai_portal_url: str = "https://aaiportal.test.biocommons.org.au"
24+
# Allowed email domains for SBP registration
25+
sbp_allowed_email_domains: list[str] = [
26+
# UNSW
27+
"@unsw.edu.au", "@ad.unsw.edu.au", "@student.unsw.edu.au",
28+
# BioCommons
29+
"@biocommons.org.au",
30+
# USyd
31+
"@sydney.edu.au", "@uni.sydney.edu.au",
32+
# WEHI
33+
"@wehi.edu.au",
34+
# Monash
35+
"@monash.edu", "@student.monash.edu",
36+
# Griffith
37+
"@griffith.edu.au", "@griffithuni.edu.au",
38+
# UoM
39+
"@unimelb.edu.au", "@student.unimelb.edu.au"
40+
]
2441

2542
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
2643

routers/sbp_register.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,15 @@
2424
route_class=RegistrationRoute
2525
)
2626

27-
# Allowed email domains for SBP registration
28-
SBP_ALLOWED_EMAIL_DOMAINS = {
29-
# UNSW
30-
"@unsw.edu.au", "@ad.unsw.edu.au", "@student.unsw.edu.au",
31-
# BioCommons
32-
"@biocommons.org.au",
33-
# USyd
34-
"@sydney.edu.au", "@uni.sydney.edu.au",
35-
# WEHI
36-
"@wehi.edu.au",
37-
# Monash
38-
"@monash.edu", "@student.monash.edu",
39-
# Griffith
40-
"@griffith.edu.au", "@griffithuni.edu.au",
41-
# UoM
42-
"@unimelb.edu.au", "@student.unimelb.edu.au"
43-
}
27+
def _validate_email_domain_with_list(email: str, allowed_domains: list[str]) -> bool:
28+
email_lower = email.lower()
29+
return any(email_lower.endswith(domain) for domain in allowed_domains)
4430

4531

4632
def validate_sbp_email_domain(email: str) -> bool:
47-
email_lower = email.lower()
48-
return any(email_lower.endswith(domain) for domain in SBP_ALLOWED_EMAIL_DOMAINS)
33+
from config import get_settings
34+
settings = get_settings()
35+
return _validate_email_domain_with_list(email, settings.sbp_allowed_email_domains)
4936

5037

5138
def send_approval_email(registration: SBPRegistrationRequest, settings: Settings):

0 commit comments

Comments
 (0)