Add a method to guess organisation from a domain

We need this in the admin app while we still have pages that:
- talk about the data sharing and financial agreement
- but aren’t within a service (so can’t look at the service’s
  organisation)

This is a get, but it deliberately won’t work if you pass it an email
address, in order not to put personally identifying information in our
logs.
This commit is contained in:
Chris Hill-Scott
2019-04-04 10:13:19 +01:00
parent c654bc1e5e
commit f62ed714f8
2 changed files with 55 additions and 1 deletions

View File

@@ -1,10 +1,11 @@
from flask import Blueprint, jsonify, request, current_app
from flask import abort, Blueprint, jsonify, request, current_app
from sqlalchemy.exc import IntegrityError
from app.dao.organisation_dao import (
dao_create_organisation,
dao_get_organisations,
dao_get_organisation_by_id,
dao_get_organisation_by_email_address,
dao_get_organisation_services,
dao_update_organisation,
dao_add_service_to_organisation,
@@ -53,6 +54,24 @@ def get_organisation_by_id(organisation_id):
return jsonify(organisation.serialize())
@organisation_blueprint.route('/by-domain', methods=['GET'])
def get_organisation_by_domain():
domain = request.args.get('domain')
if not domain or '@' in domain:
abort(400)
organisation = dao_get_organisation_by_email_address(
'example@{}'.format(request.args.get('domain'))
)
if not organisation:
abort(404)
return jsonify(organisation.serialize())
@organisation_blueprint.route('', methods=['POST'])
def create_organisation():
data = request.get_json()