Automatically associate new service with an org

This is the same thing we do in the admin app at the moment with YAML:
2f4e933b65/app/utils.py (L556-L562)
This commit is contained in:
Chris Hill-Scott
2019-02-19 12:02:18 +00:00
parent d7e03e00d3
commit c0fb9267bd
6 changed files with 131 additions and 6 deletions

View File

@@ -24,6 +24,20 @@ def dao_get_organisation_by_id(organisation_id):
return Organisation.query.filter_by(id=organisation_id).one()
def dao_get_organisation_by_email_address(email_address):
email_address = email_address.lower()
for domain in Domain().query.all():
if (
email_address.endswith("@{}".format(domain.domain)) or
email_address.endswith(".{}".format(domain.domain))
):
return Organisation.query.filter_by(id=domain.organisation_id).one()
return None
def dao_get_organisation_by_service_id(service_id):
return Organisation.query.join(Organisation.services).filter_by(id=service_id).first()