浏览代码

HUE-5014 [core] Prevent copying a Document folder into itself which then creates a recursive depth issue

Jenny Kim 9 年之前
父节点
当前提交
1531376f8d
共有 2 个文件被更改,包括 14 次插入0 次删除
  1. 4 0
      desktop/core/src/desktop/models.py
  2. 10 0
      desktop/core/src/desktop/tests_doc2.py

+ 4 - 0
desktop/core/src/desktop/models.py

@@ -1328,6 +1328,10 @@ class Document2(models.Model):
     Uses Floyd's cycle-detection algorithm to detect a cycle (aka Tortoise and Hare)
     https://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare
     """
+    # Test base case where self.uuid == self.parent_directory.uuid first
+    if self.parent_directory is not None and self.parent_directory.uuid == self.uuid:
+      return True
+
     slow = self
     fast = self
     while True:

+ 10 - 0
desktop/core/src/desktop/tests_doc2.py

@@ -366,6 +366,16 @@ class TestDocument2(object):
     assert_equal(-1, data['status'], data)
     assert_true('circular dependency' in data['message'], data)
 
+    # Test simple case where directory is saved to self as parent
+    dir = Directory.objects.create(name='dir', owner=self.user)
+    response = self.client.post('/desktop/api2/doc/move', {
+      'source_doc_uuid': json.dumps(dir.uuid),
+      'destination_doc_uuid': json.dumps(dir.uuid)
+    })
+    data = json.loads(response.content)
+    assert_equal(-1, data['status'], data)
+    assert_true('circular dependency' in data['message'], data)
+
 
   def test_api_get_data(self):
     doc_data = {'info': 'hello', 'is_history': False}