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 2019/05/31 20:20:34 UTC

[airavata-django-portal] 02/02: AIRAVATA-3016 Fixing user storage dir for shared data products

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.git

commit 05b7241d1c60bbb1b10add9b4ac4be70ab928f64
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri May 31 16:19:59 2019 -0400

    AIRAVATA-3016 Fixing user storage dir for shared data products
---
 django_airavata/apps/api/data_products_helper.py | 20 ++++++++++++--------
 django_airavata/apps/api/datastore.py            |  6 +++---
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/django_airavata/apps/api/data_products_helper.py b/django_airavata/apps/api/data_products_helper.py
index 943ea4b..fe0f0b3 100644
--- a/django_airavata/apps/api/data_products_helper.py
+++ b/django_airavata/apps/api/data_products_helper.py
@@ -59,8 +59,12 @@ def move_input_file_upload(request, data_product, path):
     source_path = _get_replica_filepath(data_product)
     file_name = data_product.productName
     target_path = os.path.join(path, file_name)
-    full_path = datastore.move(request.user.username, source_path, target_path)
-    _delete_data_product(request, source_path)
+    full_path = datastore.move(
+        data_product.ownerName,
+        source_path,
+        request.user.username,
+        target_path)
+    _delete_data_product(data_product.ownerName, source_path)
     data_product = _save_data_product(request, full_path, name=file_name)
     return data_product
 
@@ -68,13 +72,13 @@ def move_input_file_upload(request, data_product, path):
 def open(request, data_product):
     "Return file object for replica if it exists in user storage."
     path = _get_replica_filepath(data_product)
-    return datastore.open(request.user.username, path)
+    return datastore.open(data_product.ownerName, path)
 
 
 def exists(request, data_product):
     "Return True if replica for data_product exists in user storage."
     path = _get_replica_filepath(data_product)
-    return datastore.exists(request.user.username, path)
+    return datastore.exists(data_product.ownerName, path)
 
 
 def dir_exists(request, path):
@@ -99,8 +103,8 @@ def delete(request, data_product):
     "Delete replica for data product in this data store."
     path = _get_replica_filepath(data_product)
     try:
-        datastore.delete(request.user.username, path)
-        _delete_data_product(request, path)
+        datastore.delete(data_product.ownerName, path)
+        _delete_data_product(data_product.ownerName, path)
     except Exception as e:
         logger.exception("Unable to delete file {} for data product uri {}"
                          .format(path, data_product.productUri))
@@ -185,11 +189,11 @@ def _save_data_product(request, full_path, name=None):
     return data_product
 
 
-def _delete_data_product(request, full_path):
+def _delete_data_product(username, full_path):
     # TODO: call API to delete data product from replica catalog when it is
     # available (not currently implemented)
     user_file = models.User_Files.objects.filter(
-        username=request.user.username, file_path=full_path)
+        username=username, file_path=full_path)
     if user_file.exists():
         user_file.delete()
 
diff --git a/django_airavata/apps/api/datastore.py b/django_airavata/apps/api/datastore.py
index 2707db0..2438939 100644
--- a/django_airavata/apps/api/datastore.py
+++ b/django_airavata/apps/api/datastore.py
@@ -41,9 +41,9 @@ def save(username, path, file, name=None):
     return input_file_fullpath
 
 
-def move(username, source_path, target_path):
-    source_full_path = path_(username, source_path)
-    target_full_path = path_(username, target_path)
+def move(source_username, source_path, target_username, target_path):
+    source_full_path = path_(source_username, source_path)
+    target_full_path = path_(target_username, target_path)
     file_move_safe(source_full_path, target_full_path)
     return target_full_path