mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Merge pull request #2434 from alphagov/get-org-by-domain
Add a method to guess organisation from a domain
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user