Browse Source

HUE-8280 [fb] Move action button does not prevent move to itself

Roohi 7 years ago
parent
commit
73fdc9dba0

+ 12 - 0
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -2256,6 +2256,18 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
           resetPrimaryButtonsStatus(); //globally available
           return false;
         }
+        var isMoveOnSelf = false;
+        $(viewModel.selectedFiles()).each(function (index, file) {
+          if (file.path == $('#moveDestination').val()) {
+            isMoveOnSelf = true;
+            return false;
+          }
+        });
+        if(isMoveOnSelf){
+          $.jHueNotify.warn("${ _('You cannot copy a folder into itself.') }");
+          $('#moveDestination').val('');
+          return false;
+        }
         return true;
       });
 

+ 2 - 0
apps/filebrowser/src/filebrowser/views.py

@@ -1164,6 +1164,8 @@ def move(request):
     params = ['src_path']
     def bulk_move(*args, **kwargs):
         for arg in args:
+            if arg['src_path'] == arg['dest_path']:
+                raise PopupException(_('Source path and destination path cannot be same'))
             request.fs.rename(urllib.unquote(arg['src_path']), urllib.unquote(arg['dest_path']))
     return generic_op(RenameFormSet, request, bulk_move, ["src_path", "dest_path"], None,
                       data_extractor=formset_data_extractor(recurring, params),

+ 2 - 0
apps/filebrowser/src/filebrowser/views_test.py

@@ -149,6 +149,8 @@ class TestFileBrowserWithHadoop(object):
     assert_true(self.cluster.fs.exists(SUB_PATH2_2))
     assert_true(self.cluster.fs.exists(SUB_PATH2_3))
 
+    response = self.c.post('/filebrowser/move', dict(src_path=[SUB_PATH1_2, SUB_PATH1_3], dest_path=SUB_PATH1_2))
+    assert_equal(500, response.status_code)
 
   def test_copy(self):
     prefix = self.cluster.fs_prefix + '/test-copy'