You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/07/01 18:50:18 UTC

[airavata-django-portal-sdk] branch master updated: AIRAVATA-3469 Preserve force download param when redirecting

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal-sdk.git


The following commit(s) were added to refs/heads/master by this push:
     new 80c7fb2  AIRAVATA-3469 Preserve force download param when redirecting
80c7fb2 is described below

commit 80c7fb2f1d6d6c4942f3ba067997259d39b146e6
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Jul 1 14:50:04 2021 -0400

    AIRAVATA-3469 Preserve force download param when redirecting
---
 airavata_django_portal_sdk/user_storage/api.py | 8 +++++---
 airavata_django_portal_sdk/views.py            | 5 ++++-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/airavata_django_portal_sdk/user_storage/api.py b/airavata_django_portal_sdk/user_storage/api.py
index d68dbe7..fbdd0a7 100644
--- a/airavata_django_portal_sdk/user_storage/api.py
+++ b/airavata_django_portal_sdk/user_storage/api.py
@@ -186,7 +186,7 @@ def move_input_file(request, data_product=None, path=None, data_product_uri=None
     return move(request, data_product=data_product, path=path, data_product_uri=data_product_uri, storage_resource_id=storage_resource_id)
 
 
-def get_download_url(request, data_product=None, data_product_uri=None):
+def get_download_url(request, data_product=None, data_product_uri=None, force_download=False):
     "Return URL for downloading data product. One of `data_product` or `data_product_uri` is required."
     if data_product is None:
         data_product = _get_data_product(request, data_product_uri)
@@ -199,8 +199,10 @@ def get_download_url(request, data_product=None, data_product_uri=None):
     else:
         # if backend doesn't provide a download url, then use default one
         # that uses backend to read the file
-        return (reverse("airavata_django_portal_sdk:download_file") + "?" +
-                urlencode({"data-product-uri": data_product.productUri}))
+        params = {"data-product-uri": data_product.productUri}
+        if force_download:
+            params['download'] = ''
+        return f"{reverse('airavata_django_portal_sdk:download_file')}?{urlencode(params)}"
 
 
 def get_lazy_download_url(request, data_product=None, data_product_uri=None):
diff --git a/airavata_django_portal_sdk/views.py b/airavata_django_portal_sdk/views.py
index 816af58..8cae056 100644
--- a/airavata_django_portal_sdk/views.py
+++ b/airavata_django_portal_sdk/views.py
@@ -20,7 +20,10 @@ MAX_DOWNLOAD_ZIPFILE_SIZE = 1 * 1024**3  # 1 GB
 @api_view()
 def download(request):
     data_product_uri = request.GET.get('data-product-uri', '')
-    download_url = user_storage.get_download_url(request, data_product_uri=data_product_uri)
+    force_download = 'download' in request.GET
+    download_url = user_storage.get_download_url(request,
+                                                 data_product_uri=data_product_uri,
+                                                 force_download=force_download)
     return redirect(download_url)