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)
def test_delete_temp_files_created_by_user(client, mocker, fake_uuid): obj = namedtuple("obj", ["key"]) objs = [obj(key='test1'), obj(key='test2')] mocker.patch('app.main.s3_client.get_s3_objects_filter_by_prefix', return_value=objs) mocked_delete_s3_object = mocker.patch('app.main.s3_client.delete_s3_object') delete_temp_files_created_by(fake_uuid) assert mocked_delete_s3_object.called_with_args(objs[0].key) for index, arg in enumerate(mocked_delete_s3_object.call_args_list): assert arg == call(objs[index].key)
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 )
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 )