def update_email_branding(branding_id, logo=None): email_branding = email_branding_client.get_email_branding( branding_id)["email_branding"] form = ServiceUpdateEmailBranding( name=email_branding["name"], text=email_branding["text"], colour=email_branding["colour"], brand_type=email_branding["brand_type"], ) 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_email_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_email_temp_file(logo) return redirect( url_for( ".update_email_branding", branding_id=branding_id, logo=upload_filename, )) updated_logo_name = permanent_email_logo_name( logo, session["user_id"]) if logo else None email_branding_client.update_email_branding( branding_id=branding_id, logo=updated_logo_name, name=form.name.data, text=form.text.data, colour=form.colour.data, brand_type=form.brand_type.data, ) if logo: persist_logo(logo, updated_logo_name) delete_email_temp_files_created_by(session["user_id"]) return redirect(url_for(".email_branding", branding_id=branding_id)) return render_template( "views/email-branding/manage-branding.html", form=form, email_branding=email_branding, cdn_url=get_logo_cdn_domain(), logo=logo, )
def test_upload_email_logo_calls_correct_args(client, mocker, fake_uuid, upload_filename): mocker.patch('uuid.uuid4', return_value=upload_id) mocker.patch.dict('flask.current_app.config', {'LOGO_UPLOAD_BUCKET_NAME': bucket}) mocked_s3_upload = mocker.patch( 'app.s3_client.s3_logo_client.utils_s3upload') upload_email_logo(filename=filename, user_id=fake_uuid, filedata=data, region=region) mocked_s3_upload.assert_called_once_with(filedata=data, region=region, file_location=upload_filename, bucket_name=bucket, content_type='image/png')
def create_email_branding(logo=None): form = ServiceUpdateEmailBranding(brand_type='org') if form.validate_on_submit(): if form.file.data: upload_filename = upload_email_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_email_temp_file(logo) return redirect(url_for('.create_email_branding', logo=upload_filename)) updated_logo_name = permanent_email_logo_name(logo, session["user_id"]) if logo else None email_branding_client.create_email_branding( logo=updated_logo_name, name=form.name.data, text=form.text.data, colour=form.colour.data, brand_type=form.brand_type.data, ) if logo: persist_logo(logo, updated_logo_name) delete_email_temp_files_created_by(session["user_id"]) return redirect(url_for('.email_branding')) return render_template( 'views/email-branding/manage-branding.html', form=form, cdn_url=get_logo_cdn_domain(), logo=logo )
def branding_request(service_id, logo=None): file_upload_form = SVGFileUpload() file_upload_form_submitted = file_upload_form.file.data logo = logo if logo else "d512ab4f-3060-44e5-816f-59b5c54c67db-cds-logo-en-fr-5.png" upload_filename = None if file_upload_form_submitted: upload_filename = upload_email_logo( file_upload_form.file.data.filename, file_upload_form.file.data, current_app.config['AWS_REGION'], user_id=session["user_id"]) current_user.send_branding_request(current_service.id, current_service.name, upload_filename) return render_template( 'views/service-settings/branding/manage-email-branding.html', file_upload_form=file_upload_form, cdn_url=get_logo_cdn_domain(), upload_filename=upload_filename, logo=logo)
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, )