mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Stop persisting email branding logos if saving to db fails
We were previously persisting the logo for the email branding and deleting the temp files that get created before trying to update the database with the new email branding. This meant that if there was an error when saving (e.g. the domain used was a duplicate) the final logo was already in S3 and trying to go 'back' in the browser would give an error since the temp files needed to display the create branding page had already been deleted. This changes the order we do things in, so that we try persisting the email branding to the database first.
This commit is contained in:
@@ -8,6 +8,7 @@ from app.main.s3_client import (
|
||||
TEMP_TAG,
|
||||
delete_temp_file,
|
||||
delete_temp_files_created_by,
|
||||
permanent_logo_name,
|
||||
persist_logo,
|
||||
upload_logo,
|
||||
)
|
||||
@@ -60,14 +61,11 @@ def update_email_branding(branding_id, logo=None):
|
||||
|
||||
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"])
|
||||
updated_logo_name = permanent_logo_name(logo, session["user_id"]) if logo else None
|
||||
|
||||
email_branding_client.update_email_branding(
|
||||
branding_id=branding_id,
|
||||
logo=logo,
|
||||
logo=updated_logo_name,
|
||||
name=form.name.data,
|
||||
text=form.text.data,
|
||||
colour=form.colour.data,
|
||||
@@ -75,6 +73,11 @@ def update_email_branding(branding_id, logo=None):
|
||||
brand_type=form.brand_type.data,
|
||||
)
|
||||
|
||||
if logo:
|
||||
persist_logo(logo, updated_logo_name)
|
||||
|
||||
delete_temp_files_created_by(session["user_id"])
|
||||
|
||||
return redirect(url_for('.email_branding', branding_id=branding_id))
|
||||
|
||||
return render_template(
|
||||
@@ -107,13 +110,10 @@ def create_email_branding(logo=None):
|
||||
|
||||
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"])
|
||||
updated_logo_name = permanent_logo_name(logo, session["user_id"]) if logo else None
|
||||
|
||||
email_branding_client.create_email_branding(
|
||||
logo=logo,
|
||||
logo=updated_logo_name,
|
||||
name=form.name.data,
|
||||
text=form.text.data,
|
||||
colour=form.colour.data,
|
||||
@@ -121,6 +121,11 @@ def create_email_branding(logo=None):
|
||||
brand_type=form.brand_type.data,
|
||||
)
|
||||
|
||||
if logo:
|
||||
persist_logo(logo, updated_logo_name)
|
||||
|
||||
delete_temp_files_created_by(session["user_id"])
|
||||
|
||||
return redirect(url_for('.email_branding'))
|
||||
|
||||
return render_template(
|
||||
|
||||
Reference in New Issue
Block a user