Exemplo n.º 1
0
def get_apis():
    callback_api = None
    inbound_api = None
    if current_service['service_callback_api']:
        callback_api = service_api_client.get_service_callback_api(
            current_service['id'],
            current_service.get('service_callback_api')[0])
    if current_service['inbound_api']:
        inbound_api = service_api_client.get_service_inbound_api(
            current_service['id'],
            current_service.get('inbound_api')[0])

    return (callback_api, inbound_api)
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)
Exemplo n.º 3
0
def service_settings(service_id):
    letter_branding_organisations = email_branding_client.get_letter_email_branding(
    )
    organisation = organisations_client.get_service_organisation(
        service_id).get('name', None)

    if current_service['email_branding']:
        email_branding = email_branding_client.get_email_branding(
            current_service['email_branding'])['email_branding']
    else:
        email_branding = None

    inbound_number = inbound_number_client.get_inbound_sms_number_for_service(
        service_id)
    disp_inbound_number = inbound_number['data'].get('number', '')
    reply_to_email_addresses = service_api_client.get_reply_to_email_addresses(
        service_id)
    reply_to_email_address_count = len(reply_to_email_addresses)
    default_reply_to_email_address = next(
        (x['email_address']
         for x in reply_to_email_addresses if x['is_default']), "Not set")
    letter_contact_details = service_api_client.get_letter_contacts(service_id)
    letter_contact_details_count = len(letter_contact_details)
    default_letter_contact_block = next(
        (Field(x['contact_block'], html='escape')
         for x in letter_contact_details if x['is_default']), "Not set")
    sms_senders = service_api_client.get_sms_senders(service_id)
    sms_sender_count = len(sms_senders)
    default_sms_sender = next((Field(x['sms_sender'], html='escape')
                               for x in sms_senders if x['is_default']),
                              "None")

    free_sms_fragment_limit = billing_api_client.get_free_sms_fragment_limit_for_year(
        service_id)
    data_retention = service_api_client.get_service_data_retention(service_id)

    return render_template(
        'views/service-settings.html',
        email_branding=email_branding,
        letter_branding=letter_branding_organisations.get(
            current_service.get('dvla_organisation', '001')),
        can_receive_inbound=('inbound_sms' in current_service['permissions']),
        inbound_number=disp_inbound_number,
        default_reply_to_email_address=default_reply_to_email_address,
        reply_to_email_address_count=reply_to_email_address_count,
        default_letter_contact_block=default_letter_contact_block,
        letter_contact_details_count=letter_contact_details_count,
        default_sms_sender=default_sms_sender,
        sms_sender_count=sms_sender_count,
        free_sms_fragment_limit=free_sms_fragment_limit,
        prefix_sms=current_service['prefix_sms'],
        organisation=organisation,
        data_retention=data_retention,
    )
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_name_change(service_id):
    form = ServiceNameForm(service_api_client.find_all_service_email_from)

    if request.method == 'GET':
        form.name.data = current_service.get('name')

    if form.validate_on_submit():
        session['service_name_change'] = form.name.data
        return redirect(
            url_for('.service_name_change_confirm', service_id=service_id))

    return render_template('views/service-settings/name.html', 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():
        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_name_change(service_id):
    form = ServiceNameForm(service_api_client.find_all_service_email_from)

    if request.method == 'GET':
        form.name.data = current_service.get('name')

    if form.validate_on_submit():
        session['service_name_change'] = form.name.data
        return redirect(url_for('.service_name_change_confirm', service_id=service_id))

    return render_template(
        'views/service-settings/name.html',
        form=form)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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,
    )
Exemplo n.º 11
0
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,
    )
Exemplo n.º 12
0
def service_name_change(service_id):
    form = RenameServiceForm()

    if request.method == 'GET':
        form.name.data = current_service.get('name')

    if form.validate_on_submit():
        unique_name = service_api_client.is_service_name_unique(service_id, form.name.data, email_safe(form.name.data))
        if not unique_name:
            form.name.errors.append("This service name is already in use")
            return render_template('views/service-settings/name.html', form=form)
        session['service_name_change'] = form.name.data
        return redirect(url_for('.service_name_change_confirm', service_id=service_id))

    return render_template(
        'views/service-settings/name.html',
        form=form)
Exemplo n.º 13
0
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_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)
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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_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_set_email_branding(service_id):
    email_branding = email_branding_client.get_all_email_branding()
    branding_type = current_service.get('branding')

    form = ServiceSetBranding(branding_type=branding_type)

    # 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
        return redirect(url_for('.service_preview_email_branding', service_id=service_id,
                        branding_type=form.branding_type.data, branding_style=branding_style))

    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_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_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)
    )
Exemplo n.º 21
0
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)
Exemplo n.º 22
0
def get_received_text_messages_callback():
    if current_service['inbound_api']:
        return service_api_client.get_service_inbound_api(
            current_service['id'],
            current_service.get('inbound_api')[0])
Exemplo n.º 23
0
def get_delivery_status_callback_details():
    if current_service['service_callback_api']:
        return service_api_client.get_service_callback_api(
            current_service['id'],
            current_service.get('service_callback_api')[0])