From c78ebb7f815bc128c95a7263b595efe423096554 Mon Sep 17 00:00:00 2001 From: Abram Booth Date: Wed, 26 Oct 2022 17:33:28 -0400 Subject: [PATCH] prevent creating a phantom BaseFileNode with Guid wait to create a guid and redirect to the file detail page until after verifying the file exists. --- addons/base/views.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/addons/base/views.py b/addons/base/views.py index d3afdea8de0..6790c194515 100644 --- a/addons/base/views.py +++ b/addons/base/views.py @@ -762,15 +762,6 @@ def addon_view_or_download_file(auth, path, provider, **kwargs): ) ) - # There's no download action redirect to the Ember front-end file view and create guid. - if action != 'download': - if isinstance(target, Node) and waffle.flag_is_active(request, features.EMBER_FILE_PROJECT_DETAIL): - guid = file_node.get_guid(create=True) - return redirect(f'{settings.DOMAIN}{guid._id}/') - if isinstance(target, Registration) and waffle.flag_is_active(request, features.EMBER_FILE_REGISTRATION_DETAIL): - guid = file_node.get_guid(create=True) - return redirect(f'{settings.DOMAIN}{guid._id}/') - if version is None: # File is either deleted or unable to be found in the provider location # Rollback the insertion of the file_node @@ -799,6 +790,15 @@ def addon_view_or_download_file(auth, path, provider, **kwargs): else: transaction.savepoint_commit(savepoint_id) + # There's no download action redirect to the Ember front-end file view and create guid. + if action != 'download': + if isinstance(target, Node) and waffle.flag_is_active(request, features.EMBER_FILE_PROJECT_DETAIL): + guid = file_node.get_guid(create=True) + return redirect(f'{settings.DOMAIN}{guid._id}/') + if isinstance(target, Registration) and waffle.flag_is_active(request, features.EMBER_FILE_REGISTRATION_DETAIL): + guid = file_node.get_guid(create=True) + return redirect(f'{settings.DOMAIN}{guid._id}/') + # TODO clean up these urls and unify what is used as a version identifier if request.method == 'HEAD': return make_response(('', http_status.HTTP_302_FOUND, {