예제 #1
0
def service_preview_email_branding(service_id):
    branding_style = request.args.get('branding_style', None)

    form = PreviewBranding(branding_style=branding_style)

    default_branding_is_french = None

    if form.branding_style.data == FieldWithLanguageOptions.ENGLISH_OPTION_VALUE:
        default_branding_is_french = False
    elif form.branding_style.data == FieldWithLanguageOptions.FRENCH_OPTION_VALUE:
        default_branding_is_french = True

    if form.validate_on_submit():
        if default_branding_is_french is not None:
            current_service.update(
                email_branding=None,
                default_branding_is_french=default_branding_is_french)
        else:
            current_service.update(email_branding=form.branding_style.data)
        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 estimate_usage(service_id):

    form = EstimateUsageForm(
        volume_email=current_service.volume_email,
        volume_sms=current_service.volume_sms,
        volume_letter=current_service.volume_letter,
        consent_to_research={
            True: 'yes',
            False: 'no',
        }.get(current_service.consent_to_research),
    )

    if form.validate_on_submit():
        current_service.update(
            volume_email=form.volume_email.data,
            volume_sms=form.volume_sms.data,
            volume_letter=form.volume_letter.data,
            consent_to_research=(form.consent_to_research.data == 'yes'),
        )
        return redirect(
            url_for(
                'main.request_to_go_live',
                service_id=service_id,
            ))

    return render_template(
        'views/service-settings/estimate-usage.html',
        form=form,
    )
def edit_service_billing_details(service_id):
    form = BillingDetailsForm(
        billing_contact_email_addresses=current_service.
        billing_contact_email_addresses,
        billing_contact_names=current_service.billing_contact_names,
        billing_reference=current_service.billing_reference,
        purchase_order_number=current_service.purchase_order_number,
        notes=current_service.notes,
    )

    if form.validate_on_submit():
        current_service.update(
            billing_contact_email_addresses=form.
            billing_contact_email_addresses.data,
            billing_contact_names=form.billing_contact_names.data,
            billing_reference=form.billing_reference.data,
            purchase_order_number=form.purchase_order_number.data,
            notes=form.notes.data,
        )
        return redirect(url_for('.service_settings', service_id=service_id))

    return render_template(
        'views/service-settings/edit-service-billing-details.html',
        form=form,
    )
def service_name_change_confirm(service_id):
    if 'service_name_change' not in session:
        flash("The change you made was not saved. Please try again.", 'error')
        return redirect(
            url_for('main.service_name_change', service_id=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:
            current_service.update(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 submit_request_to_go_live(service_id):
    current_service.update(go_live_user=current_user.id)

    flash(
        'Thanks for your request to go live. We’ll get back to you within one working day.',
        'default')
    return redirect(url_for('.service_settings', service_id=service_id))
def submit_request_to_go_live(service_id):

    zendesk_client.create_ticket(
        subject='Request to go live - {}'.format(current_service.name),
        message=(
            'Service: {service_name}\n'
            '{service_dashboard}\n'
            '\n---'
            '\nOrganisation type: {organisation_type}'
            '\nAgreement signed: {agreement}'
            '\n'
            '\nEmails in next year: {volume_email_formatted}'
            '\nText messages in next year: {volume_sms_formatted}'
            '\nLetters in next year: {volume_letter_formatted}'
            '\n'
            '\nConsent to research: {research_consent}'
            '\nOther live services: {existing_live}'
            '\n'
            '\nService reply-to address: {email_reply_to}'
            '\n'
            '\n---'
            '\nRequest sent by {email_address}'
            '\n').format(
                service_name=current_service.name,
                service_dashboard=url_for('main.service_dashboard',
                                          service_id=current_service.id,
                                          _external=True),
                organisation_type=str(
                    current_service.organisation_type).title(),
                agreement=current_service.organisation.
                as_agreement_statement_for_go_live_request(
                    current_user.email_domain),
                volume_email_formatted=format_thousands(
                    current_service.volume_email),
                volume_sms_formatted=format_thousands(
                    current_service.volume_sms),
                volume_letter_formatted=format_thousands(
                    current_service.volume_letter),
                research_consent='Yes'
                if current_service.consent_to_research else 'No',
                existing_live='Yes' if current_user.live_services else 'No',
                email_address=current_user.email_address,
                email_reply_to=current_service.default_email_reply_to_address
                or 'not set',
            ),
        ticket_type=zendesk_client.TYPE_QUESTION,
        user_email=current_user.email_address,
        user_name=current_user.name,
        tags=current_service.request_to_go_live_tags,
    )

    current_service.update(go_live_user=current_user.id)

    flash(
        'Thanks for your request to go live. We’ll get back to you within one working day.',
        'default')
    return redirect(url_for('.service_settings', service_id=service_id))
def service_set_sms_prefix(service_id):

    form = SMSPrefixForm(enabled=current_service.prefix_sms)

    form.enabled.label.text = 'Start all text messages with ‘{}:’'.format(
        current_service.name)

    if form.validate_on_submit():
        current_service.update(prefix_sms=form.enabled.data)
        return redirect(url_for('.service_settings', service_id=service_id))

    return render_template('views/service-settings/sms-prefix.html', form=form)
def set_rate_limit(service_id):

    form = RateLimit(rate_limit=current_service.rate_limit)

    if form.validate_on_submit():
        current_service.update(rate_limit=form.rate_limit.data)

        return redirect(url_for('.service_settings', service_id=service_id))

    return render_template(
        'views/service-settings/set-rate-limit.html',
        form=form,
    )
def service_preview_letter_branding(service_id):
    branding_style = request.args.get('branding_style')

    form = PreviewBranding(branding_style=branding_style)

    if form.validate_on_submit():
        current_service.update(letter_branding=form.branding_style.data)
        return redirect(url_for('.service_settings', service_id=service_id))

    return render_template(
        'views/service-settings/preview-letter-branding.html',
        form=form,
        service_id=service_id,
        action=url_for('main.service_preview_letter_branding',
                       service_id=service_id),
    )
def edit_service_notes(service_id):
    form = EditNotesForm(notes=current_service.notes)

    if form.validate_on_submit():

        if form.notes.data == current_service.notes:
            return redirect(url_for('.service_settings',
                                    service_id=service_id))

        current_service.update(notes=form.notes.data)
        return redirect(url_for('.service_settings', service_id=service_id))

    return render_template(
        'views/service-settings/edit-service-notes.html',
        form=form,
    )
예제 #11
0
def service_sending_domain(service_id):
    form = SendingDomainForm()

    if request.method == 'GET':
        form.sending_domain.data = current_service.sending_domain

    if form.validate_on_submit():
        current_service.update(sending_domain=form.sending_domain.data)
        flash(_('Sending domain updated'), 'default')
        return redirect(url_for('.service_settings', service_id=service_id))

    default_sending = current_app.config["SENDING_DOMAIN"]
    template = 'views/service-settings/sending_domain.html'
    return render_template(template,
                           service_id=service_id,
                           sending_domain=default_sending,
                           form=form)
def service_switch_count_as_live(service_id):

    form = ServiceOnOffSettingForm(
        name="Count in list of live services",
        enabled=current_service.count_as_live,
        truthy='Yes',
        falsey='No',
    )

    if form.validate_on_submit():
        current_service.update(count_as_live=form.enabled.data)
        return redirect(url_for('.service_settings', service_id=service_id))

    return render_template(
        'views/service-settings/set-service-setting.html',
        title="Count in list of live services",
        form=form,
    )
예제 #13
0
def service_set_letter_contact_block(service_id):

    if not current_service.has_permission('letter'):
        abort(403)

    form = ServiceLetterContactBlockForm(
        letter_contact_block=current_service.letter_contact_block)
    if form.validate_on_submit():
        current_service.update(
            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 estimate_usage(service_id):

    form = EstimateUsageForm(volume_sms=current_service.volume_sms, )

    if form.validate_on_submit():
        current_service.update(
            volume_sms=form.volume_sms.data,
            consent_to_research=False,
        )
        return redirect(
            url_for(
                'main.request_to_go_live',
                service_id=service_id,
            ))

    return render_template(
        'views/service-settings/estimate-usage.html',
        form=form,
    )
예제 #15
0
def service_set_contact_link(service_id):
    form = ServiceContactDetailsForm()

    if request.method == 'GET':
        contact_details = current_service.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

        current_service.update(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 set_organisation_type(service_id):

    form = OrganisationTypeForm(
        organisation_type=current_service.organisation_type)

    if form.validate_on_submit():
        free_sms_fragment_limit = current_app.config[
            'DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get(
                form.organisation_type.data)

        current_service.update(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,
    )
예제 #17
0
def service_switch_can_upload_document(service_id):
    if current_service.contact_link:
        return redirect(
            url_for('.service_set_permission',
                    service_id=service_id,
                    permission='upload_document'))

    form = ServiceContactDetailsForm()

    if form.validate_on_submit():
        contact_type = form.contact_details_type.data

        current_service.update(contact_link=form.data[contact_type])

        return redirect(
            url_for('.service_set_permission',
                    service_id=service_id,
                    permission='upload_document'))

    return render_template('views/service-settings/contact_link.html',
                           form=form)
예제 #18
0
def branding_request(service_id):
    current_branding = current_service.email_branding_id
    cdn_url = get_logo_cdn_domain()
    default_en_filename = "https://{}/gov-canada-en.svg".format(cdn_url)
    default_fr_filename = "https://{}/gov-canada-fr.svg".format(cdn_url)
    choices = [
        ('__FIP-EN__', _('English GC logo') + '||' + default_en_filename),
        ('__FIP-FR__', _('French GC logo') + '||' + default_fr_filename),
    ]
    if current_branding is None:
        current_branding = (FieldWithLanguageOptions.FRENCH_OPTION_VALUE if
                            current_service.default_branding_is_french is True
                            else FieldWithLanguageOptions.ENGLISH_OPTION_VALUE)
        branding_style = current_branding
    else:
        current_branding_filename = "https://{}/{}".format(
            cdn_url, current_service.email_branding['logo'])
        branding_style = 'custom'
        choices.append(
            ('custom', _('Custom {} logo').format(current_service.name) +
             '||' + current_branding_filename))

    form = SelectLogoForm(
        label=_('Type of logo'),
        choices=choices,
        branding_style=branding_style,
    )
    upload_filename = None
    if form.validate_on_submit():
        file_submitted = form.file.data
        if file_submitted:
            upload_filename = upload_email_logo(
                file_submitted.filename,
                file_submitted,
                current_app.config['AWS_REGION'],
                user_id=session["user_id"])
            current_user.send_branding_request(current_service.id,
                                               current_service.name,
                                               upload_filename)

        default_branding_is_french = None
        branding_choice = form.branding_style.data
        if branding_choice == 'custom' or file_submitted:
            default_branding_is_french = None
        else:
            default_branding_is_french = (
                branding_choice == FieldWithLanguageOptions.FRENCH_OPTION_VALUE
            )

        if default_branding_is_french is not None:
            current_service.update(
                email_branding=None,
                default_branding_is_french=default_branding_is_french)
            return redirect(url_for('.service_settings',
                                    service_id=service_id))

    return render_template(
        'views/service-settings/branding/manage-email-branding.html',
        form=form,
        using_custom_branding=current_service.email_branding_id is not None,
        cdn_url=cdn_url,
        upload_filename=upload_filename,
    )