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)