def service_name_change_confirm(service_id): # Validate password for form def _check_password(pwd): return user_api_client.verify_password(current_user.id, pwd) form = ConfirmPasswordForm(_check_password) if form.validate_on_submit(): try: service_api_client.update_service( current_service['id'], name=session['service_name_change'], email_from=email_safe(session['service_name_change'])) except HTTPError as e: error_msg = "Duplicate service name '{}'".format( session['service_name_change']) if e.status_code == 400 and error_msg in e.message['name']: # Redirect the user back to the change service name screen flash('This service name is already in use', 'error') return redirect( url_for('main.service_name_change', service_id=service_id)) else: raise e else: session.pop('service_name_change') return redirect(url_for('.service_settings', service_id=service_id)) return render_template('views/service-settings/confirm.html', heading='Change your service name', form=form)
def service_name_change_confirm(service_id): # Validate password for form def _check_password(pwd): return user_api_client.verify_password(current_user.id, pwd) form = ConfirmPasswordForm(_check_password) if form.validate_on_submit(): current_service['name'] = session['service_name_change'] current_service['email_from'] = email_safe(session['service_name_change']) try: service_api_client.update_service( current_service['id'], current_service['name'], current_service['active'], current_service['message_limit'], current_service['restricted'], current_service['users'], current_service['email_from']) except HTTPError as e: error_msg = "Duplicate service name '{}'".format(session['service_name_change']) if e.status_code == 400 and error_msg in e.message['name']: # Redirect the user back to the change service name screen flash('This service name is already in use', 'error') return redirect(url_for('main.service_name_change', service_id=service_id)) else: raise e else: session.pop('service_name_change') return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/confirm.html', heading='Change your service name', form=form)
def service_switch_live(service_id): service_api_client.update_service( current_service['id'], # TODO This limit should be set depending on the agreement signed by # with Notify. message_limit=250000 if current_service['restricted'] else 50, restricted=(not current_service['restricted'])) return redirect(url_for('.service_settings', service_id=service_id))
def service_switch_live(service_id): service_api_client.update_service( current_service['id'], # TODO This limit should be set depending on the agreement signed by # with Notify. message_limit=250000 if current_service['restricted'] else 50, restricted=(not current_service['restricted']) ) return redirect(url_for('.service_settings', service_id=service_id))
def service_set_sms_sender(service_id): form = ServiceSmsSender() if request.method == 'GET': form.sms_sender.data = current_service.get('sms_sender') if form.validate_on_submit(): service_api_client.update_service(current_service['id'], sms_sender=form.sms_sender.data or None) return redirect(url_for('.service_settings', service_id=service_id)) return render_template('views/service-settings/set-sms-sender.html', form=form)
def service_set_reply_to_email(service_id): form = ServiceReplyToEmailFrom() if request.method == 'GET': form.email_address.data = current_service.get('reply_to_email_address') if form.validate_on_submit(): service_api_client.update_service( current_service['id'], reply_to_email_address=form.email_address.data) return redirect(url_for('.service_settings', service_id=service_id)) return render_template('views/service-settings/set-reply-to-email.html', form=form)
def service_switch_live(service_id): service_api_client.update_service( current_service['id'], current_service['name'], current_service['active'], # TODO This limit should be set depending on the agreement signed by # with Notify. 250000 if current_service['restricted'] else 50, False if current_service['restricted'] else True, current_service['users'], current_service['email_from']) return redirect(url_for('.service_settings', service_id=service_id))
def service_set_sms_sender(service_id): form = ServiceSmsSender() if request.method == 'GET': form.sms_sender.data = current_service.get('sms_sender') if form.validate_on_submit(): service_api_client.update_service( current_service['id'], sms_sender=form.sms_sender.data or None ) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-sms-sender.html', form=form)
def service_set_reply_to_email(service_id): form = ServiceReplyToEmailFrom() if request.method == 'GET': form.email_address.data = current_service.get('reply_to_email_address') if form.validate_on_submit(): service_api_client.update_service( current_service['id'], reply_to_email_address=form.email_address.data ) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-reply-to-email.html', form=form)
def service_set_contact_link(service_id): form = ServiceContactLinkForm() if request.method == 'GET': form.url.data = current_service.get('contact_link') if form.validate_on_submit(): service_api_client.update_service(current_service['id'], contact_link=form.url.data) return redirect( url_for('.service_settings', service_id=current_service['id'])) return render_template('views/service-settings/contact_link.html', form=form)
def service_set_sms_prefix(service_id): form = SMSPrefixForm( enabled=('on' if current_service['prefix_sms'] else 'off')) form.enabled.label.text = 'Start all text messages with ‘{}’:'.format( current_service['name']) if form.validate_on_submit(): service_api_client.update_service( current_service['id'], prefix_sms=(form.enabled.data == 'on')) return redirect(url_for('.service_settings', service_id=service_id)) return render_template('views/service-settings/sms-prefix.html', form=form)
def set_organisation_type(service_id): form = OrganisationTypeForm(organisation_type=current_service.get('organisation_type')) if form.validate_on_submit(): service_api_client.update_service( service_id, organisation_type=form.organisation_type.data, ) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-organisation-type.html', form=form, )
def set_letter_branding(service_id): form = LetterBranding( choices=email_branding_client.get_letter_email_branding().items()) if form.validate_on_submit(): service_api_client.update_service( service_id, dvla_organisation=form.dvla_org_id.data) return redirect(url_for('.service_settings', service_id=service_id)) form.dvla_org_id.data = current_service.get('dvla_organisation', '001') return render_template( 'views/service-settings/set-letter-branding.html', form=form, )
def service_switch_can_upload_document(service_id): form = ServiceContactLinkForm() # If turning the permission off, or turning it on and the service already has a contact_link, # don't show the form to add the link if 'upload_document' in current_service[ 'permissions'] or current_service.get('contact_link'): switch_service_permissions(service_id, 'upload_document') return redirect(url_for('.service_settings', service_id=service_id)) if form.validate_on_submit(): service_api_client.update_service(current_service['id'], contact_link=form.url.data) switch_service_permissions(service_id, 'upload_document') return redirect(url_for('.service_settings', service_id=service_id)) return render_template('views/service-settings/contact_link.html', form=form)
def service_set_letter_contact_block(service_id): if 'letter' not in current_service['permissions']: abort(403) form = ServiceLetterContactBlockForm( letter_contact_block=current_service['letter_contact_block']) if form.validate_on_submit(): service_api_client.update_service( current_service['id'], letter_contact_block=form.letter_contact_block.data.replace( '\r', '') or None) if request.args.get('from_template'): return redirect( url_for('.view_template', service_id=service_id, template_id=request.args.get('from_template'))) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-letter-contact-block.html', form=form)
def service_set_reply_to_email(service_id): form = ServiceReplyToEmailFrom() if request.method == 'GET': form.email_address.data = current_service.get('reply_to_email_address') if form.validate_on_submit(): message = 'Reply to email set to {}'.format(form.email_address.data) service_api_client.update_service( current_service['id'], current_service['name'], current_service['active'], current_service['message_limit'], current_service['restricted'], current_service['users'], current_service['email_from'], reply_to_email_address=form.email_address.data) flash(message, 'default_with_tick') return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-reply-to-email.html', form=form)
def set_organisation_type(service_id): form = OrganisationTypeForm(organisation_type=current_service.get('organisation_type')) if form.validate_on_submit(): free_sms_fragment_limit = current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get( form.organisation_type.data) service_api_client.update_service( service_id, organisation_type=form.organisation_type.data, ) billing_api_client.create_or_update_free_sms_fragment_limit(service_id, free_sms_fragment_limit) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-organisation-type.html', form=form, )
def service_switch_can_upload_document(service_id): form = ServiceContactDetailsForm() # If turning the permission off, or turning it on and the service already has a contact_link, # don't show the form to add the link if current_service.has_permission('upload_document') or current_service.get('contact_link'): switch_service_permissions(service_id, 'upload_document') return redirect(url_for('.service_settings', service_id=service_id)) if form.validate_on_submit(): contact_type = form.contact_details_type.data service_api_client.update_service( current_service.id, contact_link=form.data[contact_type] ) switch_service_permissions(service_id, 'upload_document') return redirect(url_for('.service_settings', service_id=service_id)) return render_template('views/service-settings/contact_link.html', form=form)
def service_set_branding_and_org(service_id): organisations = organisations_client.get_organisations() form = ServiceBrandingOrg(branding_type=current_service.get('branding')) # dynamically create org choices, including the null option form.organisation.choices = [ ('None', 'None') ] + get_branding_as_value_and_label(organisations) if form.validate_on_submit(): organisation = None if form.organisation.data == 'None' else form.organisation.data service_api_client.update_service(service_id, branding=form.branding_type.data, organisation=organisation) return redirect(url_for('.service_settings', service_id=service_id)) form.organisation.data = current_service['organisation'] or 'None' return render_template('views/service-settings/set-branding-and-org.html', form=form, branding_dict=get_branding_as_dict(organisations))
def service_preview_email_branding(service_id): branding_type = request.args.get('branding_type', None) branding_style = request.args.get('branding_style', None) form = ServicePreviewBranding(branding_type=branding_type, branding_style=branding_style) if form.validate_on_submit(): branding_style = None if form.branding_style.data == 'None' else form.branding_style.data service_api_client.update_service( service_id, branding=form.branding_type.data, email_branding=branding_style ) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/preview-email-branding.html', form=form, service_id=service_id, action=url_for('main.service_preview_email_branding', service_id=service_id), )
def service_set_contact_link(service_id): form = ServiceContactDetailsForm() if request.method == 'GET': contact_details = current_service.get('contact_link') contact_type = check_contact_details_type(contact_details) field_to_update = getattr(form, contact_type) form.contact_details_type.data = contact_type field_to_update.data = contact_details if form.validate_on_submit(): contact_type = form.contact_details_type.data service_api_client.update_service( current_service.id, contact_link=form.data[contact_type] ) return redirect(url_for('.service_settings', service_id=current_service.id)) return render_template('views/service-settings/contact_link.html', form=form)
def service_set_email_branding(service_id): email_branding = email_branding_client.get_all_email_branding() form = ServiceSetBranding(branding_type=current_service.get('branding')) # dynamically create org choices, including the null option form.branding_style.choices = [ ('None', 'None') ] + get_branding_as_value_and_label(email_branding) if form.validate_on_submit(): branding_style = None if form.branding_style.data == 'None' else form.branding_style.data service_api_client.update_service(service_id, branding=form.branding_type.data, email_branding=branding_style) return redirect(url_for('.service_settings', service_id=service_id)) form.branding_style.data = current_service['email_branding'] or 'None' return render_template('views/service-settings/set-email-branding.html', form=form, branding_dict=get_branding_as_dict(email_branding))
def service_set_branding_and_org(service_id): organisations = organisations_client.get_organisations() form = ServiceBrandingOrg(branding_type=current_service.get('branding')) # dynamically create org choices, including the null option form.organisation.choices = [('None', 'None')] + get_branding_as_value_and_label(organisations) if form.validate_on_submit(): organisation = None if form.organisation.data == 'None' else form.organisation.data service_api_client.update_service( service_id, branding=form.branding_type.data, organisation=organisation ) return redirect(url_for('.service_settings', service_id=service_id)) form.organisation.data = current_service['organisation'] or 'None' return render_template( 'views/service-settings/set-branding-and-org.html', form=form, branding_dict=get_branding_as_dict(organisations) )
def service_status_change_confirm(service_id): # Validate password for form def _check_password(pwd): return user_api_client.verify_password(current_user.id, pwd) form = ConfirmPasswordForm(_check_password) if form.validate_on_submit(): current_service['active'] = True service_api_client.update_service( current_service['id'], current_service['name'], current_service['active'], current_service['message_limit'], current_service['restricted'], current_service['users'], current_service['email_from']) return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/confirm.html', heading='Turn off all outgoing notifications', destructive=True, form=form)
def service_set_sms_sender(service_id): form = ServiceSmsSender() if request.method == 'GET': form.sms_sender.data = current_service.get('sms_sender') if form.validate_on_submit(): if form.sms_sender.data: message = 'Text message sender set to {}'.format(form.sms_sender.data) else: message = 'Text message sender removed' service_api_client.update_service( current_service['id'], current_service['name'], current_service['active'], current_service['message_limit'], current_service['restricted'], current_service['users'], current_service['email_from'], current_service['reply_to_email_address'], sms_sender=form.sms_sender.data if form.sms_sender.data else None) flash(message, 'default_with_tick') return redirect(url_for('.service_settings', service_id=service_id)) return render_template( 'views/service-settings/set-sms-sender.html', form=form)