mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Choose most specific domains first
If we had organisations for GDS and Cabinet Office, then we’d always want someone whose email address ends in `@cabinet-office.gov.uk` to match to `cabinet-office.gov.uk` before matching to `digital.cabinet-office.gov.uk`. Sorting the list by shortest first addresses this.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from sqlalchemy.sql.expression import func
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import transactional
|
||||
from app.models import (
|
||||
@@ -28,7 +30,8 @@ def dao_get_organisation_by_email_address(email_address):
|
||||
|
||||
email_address = email_address.lower()
|
||||
|
||||
for domain in Domain().query.all():
|
||||
for domain in Domain.query.order_by(func.char_length(Domain.domain).desc()).all():
|
||||
|
||||
if (
|
||||
email_address.endswith("@{}".format(domain.domain)) or
|
||||
email_address.endswith(".{}".format(domain.domain))
|
||||
|
||||
Reference in New Issue
Block a user