def test_get_organisation_by_email_address_ignores_gsi_gov_uk( notify_db_session): org = create_organisation() create_domain('example.gov.uk', org.id) found_org = dao_get_organisation_by_email_address( '*****@*****.**') assert org == found_org
def dao_create_service( service, user, service_id=None, service_permissions=None, ): # the default property does not appear to work when there is a difference between the sqlalchemy schema and the # db schema (ie: during a migration), so we have to set sms_sender manually here. After the GOVUK sms_sender # migration is completed, this code should be able to be removed. if not user: raise ValueError("Can't create a service without a user") if service_permissions is None: service_permissions = DEFAULT_SERVICE_PERMISSIONS organisation = dao_get_organisation_by_email_address(user.email_address) from app.dao.permissions_dao import permission_dao service.users.append(user) permission_dao.add_default_service_permissions_for_user(user, service) service.id = service_id or uuid.uuid4( ) # must be set now so version history model can use same id service.active = True service.research_mode = False for permission in service_permissions: service_permission = ServicePermission(service_id=service.id, permission=permission) service.permissions.append(service_permission) # do we just add the default - or will we get a value from FE? insert_service_sms_sender(service, current_app.config["FROM_NUMBER"]) if organisation: service.organisation_id = organisation.id service.organisation_type = organisation.organisation_type if organisation.email_branding: service.email_branding = organisation.email_branding if organisation.letter_branding and not service.letter_branding: service.letter_branding = organisation.letter_branding elif service.organisation_type in NHS_ORGANISATION_TYPES or email_address_is_nhs( user.email_address): service.email_branding = dao_get_email_branding_by_name("NHS") service.letter_branding = dao_get_letter_branding_by_name("NHS") if organisation: service.crown = organisation.crown elif service.organisation_type in CROWN_ORGANISATION_TYPES: service.crown = True elif service.organisation_type in NON_CROWN_ORGANISATION_TYPES: service.crown = False service.count_as_live = not user.platform_admin db.session.add(service)
def dao_create_service( service, user, service_id=None, service_permissions=None, ): if not user: raise ValueError("Can't create a service without a user") if service_permissions is None: service_permissions = DEFAULT_SERVICE_PERMISSIONS organisation = dao_get_organisation_by_email_address(user.email_address) from app.dao.permissions_dao import permission_dao service.users.append(user) permission_dao.add_default_service_permissions_for_user(user, service) service.id = service_id or uuid.uuid4( ) # must be set now so version history model can use same id service.active = True service.research_mode = False for permission in service_permissions: service_permission = ServicePermission(service_id=service.id, permission=permission) service.permissions.append(service_permission) # do we just add the default - or will we get a value from FE? insert_service_sms_sender(service, current_app.config['FROM_NUMBER']) if organisation: service.organisation_id = organisation.id service.organisation_type = organisation.organisation_type if organisation.email_branding: service.email_branding = organisation.email_branding if organisation.letter_branding and not service.letter_branding: service.letter_branding = organisation.letter_branding elif service.organisation_type in NHS_ORGANISATION_TYPES or email_address_is_nhs( user.email_address): service.email_branding = dao_get_email_branding_by_name('NHS') service.letter_branding = dao_get_letter_branding_by_name('NHS') if organisation: service.crown = organisation.crown elif service.organisation_type in CROWN_ORGANISATION_TYPES: service.crown = True elif service.organisation_type in NON_CROWN_ORGANISATION_TYPES: service.crown = False service.count_as_live = not user.platform_admin db.session.add(service)
def associate_services_to_organisations(): services = Service.get_history_model().query.filter_by(version=1).all() for s in services: created_by_user = User.query.filter_by(id=s.created_by_id).first() organisation = dao_get_organisation_by_email_address( created_by_user.email_address) service = dao_fetch_service_by_id(service_id=s.id) if organisation: dao_add_service_to_organisation(service=service, organisation_id=organisation.id) print("finished associating services to organisations")
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())
def test_get_organisation_by_email_address(domain, expected_org, notify_db_session): org = create_organisation() create_domain('example.gov.uk', org.id) create_domain('test.gov.uk', org.id) another_org = create_organisation(name='Another') create_domain('cabinet-office.gov.uk', another_org.id) create_domain('cabinetoffice.gov.uk', another_org.id) found_org = dao_get_organisation_by_email_address('test@{}'.format(domain)) if expected_org: assert found_org is org else: assert found_org is None