def create_email_branding(logo=None):
    form = ServiceCreateEmailBranding()

    if form.validate_on_submit():
        if form.file.data:
            upload_filename = upload_logo(form.file.data.filename,
                                          form.file.data,
                                          current_app.config['AWS_REGION'],
                                          user_id=session["user_id"])

            if logo and logo.startswith(
                    TEMP_TAG.format(user_id=session['user_id'])):
                delete_temp_file(logo)

            return redirect(
                url_for('.create_email_branding', logo=upload_filename))

        if logo:
            logo = persist_logo(logo, session["user_id"])

        delete_temp_files_created_by(session["user_id"])

        email_branding_client.create_email_branding(logo=logo,
                                                    name=form.name.data,
                                                    colour=form.colour.data)

        return redirect(url_for('.email_branding'))

    return render_template('views/email-branding/manage-branding.html',
                           form=form,
                           cdn_url=get_cdn_domain(),
                           logo=logo)
Beispiel #2
0
def test_persist_logo_returns_if_not_temp(client, mocker, fake_uuid):
    filename = 'logo.png'
    mocker.patch.dict('flask.current_app.config', {'LOGO_UPLOAD_BUCKET_NAME': bucket})
    mocked_rename_s3_object = mocker.patch('app.main.s3_client.rename_s3_object')

    persisted_filename = persist_logo(filename=filename, user_id=fake_uuid)

    assert not mocked_rename_s3_object.called
    assert persisted_filename == filename
Beispiel #3
0
def test_persist_logo(client, mocker, fake_uuid, upload_filename):
    mocker.patch.dict('flask.current_app.config', {'LOGO_UPLOAD_BUCKET_NAME': bucket})
    mocked_rename_s3_object = mocker.patch('app.main.s3_client.rename_s3_object')

    persisted_filename = persist_logo(filename=upload_filename, user_id=fake_uuid)

    assert mocked_rename_s3_object.called_once_with(
        upload_filename, get_temp_truncated_filename(upload_filename, fake_uuid))
    assert persisted_filename == get_temp_truncated_filename(upload_filename, fake_uuid)
Beispiel #4
0
def manage_org(logo=None):
    form = ServiceManageOrg()

    org = session.get("organisation")

    logo = logo if logo else org.get('logo') if org else None

    if form.validate_on_submit():
        if form.file.data:
            upload_filename = upload_logo(
                form.file.data.filename,
                form.file.data,
                current_app.config['AWS_REGION'],
                user_id=session["user_id"]
            )

            if logo and logo.startswith(TEMP_TAG.format(user_id=session['user_id'])):
                delete_temp_file(logo)

            return redirect(
                url_for('.manage_org', logo=upload_filename))

        if logo:
            logo = persist_logo(logo, session["user_id"])

        delete_temp_files_created_by(session["user_id"])

        if org:
            organisations_client.update_organisation(
                org_id=org['id'], logo=logo, name=form.name.data, colour=form.colour.data)
            org_id = org['id']
        else:
            resp = organisations_client.create_organisation(
                logo=logo, name=form.name.data, colour=form.colour.data)
            org_id = resp['data']['id']

        return redirect(url_for('.organisations', organisation_id=org_id))
    if org:
        form.name.data = org['name']
        form.colour.data = org['colour']

    return render_template(
        'views/organisations/manage-org.html',
        form=form,
        organisation=org,
        cdn_url=get_cdn_domain(),
        logo=logo
    )
Beispiel #5
0
def update_email_branding(branding_id, logo=None):
    email_branding = email_branding_client.get_email_branding(branding_id)['email_branding']

    form = ServiceUpdateEmailBranding()

    logo = logo if logo else email_branding.get('logo') if email_branding else None

    if form.validate_on_submit():
        if form.file.data:
            upload_filename = upload_logo(
                form.file.data.filename,
                form.file.data,
                current_app.config['AWS_REGION'],
                user_id=session["user_id"]
            )

            if logo and logo.startswith(TEMP_TAG.format(user_id=session['user_id'])):
                delete_temp_file(logo)

            return redirect(url_for('.update_email_branding', branding_id=branding_id, logo=upload_filename))

        if logo:
            logo = persist_logo(logo, session["user_id"])

        delete_temp_files_created_by(session["user_id"])

        email_branding_client.update_email_branding(
            branding_id=branding_id,
            logo=logo,
            name=form.name.data,
            text=form.text.data,
            colour=form.colour.data
        )

        return redirect(url_for('.email_branding', branding_id=branding_id))

    form.name.data = email_branding['name']
    form.text.data = email_branding['text']
    form.colour.data = email_branding['colour']

    return render_template(
        'views/email-branding/manage-branding.html',
        form=form,
        email_branding=email_branding,
        cdn_url=get_cdn_domain(),
        logo=logo
    )