mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 13:39:41 -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:
@@ -31,7 +31,9 @@ def delete_s3_object(filename):
|
||||
get_s3_object(bucket_name, filename).delete()
|
||||
|
||||
|
||||
def rename_s3_object(old_name, new_name):
|
||||
def persist_logo(old_name, new_name):
|
||||
if old_name == new_name:
|
||||
return
|
||||
bucket_name = current_app.config['LOGO_UPLOAD_BUCKET_NAME']
|
||||
get_s3_object(bucket_name, new_name).copy_from(
|
||||
CopySource='{}/{}'.format(bucket_name, old_name))
|
||||
@@ -110,17 +112,12 @@ def upload_logo(filename, filedata, region, user_id):
|
||||
return upload_file_name
|
||||
|
||||
|
||||
def persist_logo(filename, user_id):
|
||||
def permanent_logo_name(filename, user_id):
|
||||
if filename.startswith(TEMP_TAG.format(user_id=user_id)):
|
||||
persisted_filename = get_temp_truncated_filename(
|
||||
filename=filename, user_id=user_id)
|
||||
return get_temp_truncated_filename(filename=filename, user_id=user_id)
|
||||
else:
|
||||
return filename
|
||||
|
||||
rename_s3_object(filename, persisted_filename)
|
||||
|
||||
return persisted_filename
|
||||
|
||||
|
||||
def delete_temp_files_created_by(user_id):
|
||||
for obj in get_s3_objects_filter_by_prefix(TEMP_TAG.format(user_id=user_id)):
|
||||
|
||||
Reference in New Issue
Block a user