def _create_service(service_name, organisation_type, email_from, form): free_sms_fragment_limit = current_app.config[ 'DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get(organisation_type) try: service_id = service_api_client.create_service( service_name=service_name, organisation_type=organisation_type, message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], restricted=True, user_id=session['user_id'], email_from=email_from, ) session['service_id'] = service_id billing_api_client.create_or_update_free_sms_fragment_limit( service_id, free_sms_fragment_limit) return service_id, None except HTTPError as e: if e.status_code == 400 and e.message['name']: form.name.errors.append("This service name is already in use") return None, e else: raise e
def _create_service( service_name: str, organisation_type: str, email_from: str, default_branding_is_french: bool, ) -> ServiceResult: free_sms_fragment_limit = current_app.config["DEFAULT_FREE_SMS_FRAGMENT_LIMITS"].get(organisation_type) try: service_id = service_api_client.create_service( service_name=service_name, organisation_type=organisation_type, message_limit=current_app.config["DEFAULT_SERVICE_LIMIT"], restricted=True, user_id=session["user_id"], email_from=email_from, default_branding_is_french=default_branding_is_french, ) session["service_id"] = service_id billing_api_client.create_or_update_free_sms_fragment_limit(service_id, free_sms_fragment_limit) return SuccessResult(service_id) except HTTPError as e: if e.status_code == 400 and e.message["name"]: errors = [_("This service name is already in use")] return DuplicateNameResult(errors) if e.status_code == 400 and e.message["email_from"]: errors = [_("This email address is already in use")] return DuplicateNameResult(errors) else: raise e
def _create_service(service_name, email_from): service_id = service_api_client.create_service(service_name=service_name, message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], restricted=True, user_id=session['user_id'], email_from=email_from) session['service_id'] = service_id return service_id
def add_service(): invited_user = session.get('invited_user') if invited_user: invitation = InvitedUser(**invited_user) # if invited user add to service and redirect to dashboard user = user_api_client.get_user(session['user_id']) service_id = invited_user['service'] user_api_client.add_user_to_service(service_id, user.id, invitation.permissions) invite_api_client.accept_invite(service_id, invitation.id) return redirect( url_for('main.service_dashboard', service_id=service_id)) form = AddServiceForm(service_api_client.find_all_service_email_from) heading = 'Which service do you want to set up notifications for?' if form.validate_on_submit(): email_from = email_safe(form.name.data) service_id = service_api_client.create_service( service_name=form.name.data, active=False, message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], restricted=True, user_id=session['user_id'], email_from=email_from) session['service_id'] = service_id if (len( service_api_client.get_services({ 'user_id': session['user_id'] }).get('data', [])) > 1): return redirect( url_for('main.service_dashboard', service_id=service_id)) example_sms_template = service_api_client.create_service_template( 'Example text message template', 'sms', 'Hey ((name)), I’m trying out Notify. Today is ((day of week)) and my favourite colour is ((colour)).', service_id) return redirect( url_for('main.send_test', service_id=service_id, template_id=example_sms_template['data']['id'], help=1)) else: return render_template('views/add-service.html', form=form, heading=heading)
def add_service(): invited_user = session.get('invited_user') if invited_user: invitation = InvitedUser(**invited_user) # if invited user add to service and redirect to dashboard user = user_api_client.get_user(session['user_id']) service_id = invited_user['service'] user_api_client.add_user_to_service(service_id, user.id, invitation.permissions) invite_api_client.accept_invite(service_id, invitation.id) return redirect(url_for('main.service_dashboard', service_id=service_id)) form = AddServiceForm(service_api_client.find_all_service_email_from) heading = 'Which service do you want to set up notifications for?' if form.validate_on_submit(): email_from = email_safe(form.name.data) service_id = service_api_client.create_service(service_name=form.name.data, active=False, message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], restricted=True, user_id=session['user_id'], email_from=email_from) session['service_id'] = service_id if (len(service_api_client.get_services({'user_id': session['user_id']}).get('data', [])) > 1): return redirect(url_for('main.service_dashboard', service_id=service_id)) example_sms_template = service_api_client.create_service_template( 'Example text message template', 'sms', 'Hey ((name)), I’m trying out Notify. Today is ((day of week)) and my favourite colour is ((colour)).', service_id ) return redirect(url_for( 'main.send_test', service_id=service_id, template_id=example_sms_template['data']['id'], help=1 )) else: return render_template( 'views/add-service.html', form=form, heading=heading )