浏览代码

HUE-4706 [core] Importing documents should ignore reserved directories (home and trash)

Jenny Kim 9 年之前
父节点
当前提交
cb8264a
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      desktop/core/src/desktop/api2.py

+ 5 - 2
desktop/core/src/desktop/api2.py

@@ -392,6 +392,9 @@ def export_documents(request):
 
 
 @ensure_csrf_cookie
 @ensure_csrf_cookie
 def import_documents(request):
 def import_documents(request):
+  def is_reserved_directory(doc):
+    return doc['fields']['type'] == 'directory' and doc['fields']['name'] in (Document2.HOME_DIR, Document2.TRASH_DIR)
+
   try:
   try:
     if request.FILES.get('documents'):
     if request.FILES.get('documents'):
       documents = request.FILES['documents'].read()
       documents = request.FILES['documents'].read()
@@ -408,11 +411,11 @@ def import_documents(request):
 
 
   docs = []
   docs = []
 
 
-  uuids_map = dict((doc['fields']['uuid'], None) for doc in documents)
+  uuids_map = dict((doc['fields']['uuid'], None) for doc in documents if not is_reserved_directory(doc))
 
 
   for doc in documents:
   for doc in documents:
     # Filter docs to import, ignoring reserved directories (home and Trash) and history docs
     # Filter docs to import, ignoring reserved directories (home and Trash) and history docs
-    if doc['fields']['type'] != 'directory' or doc['fields']['name'] not in (Document2.HOME_DIR, Document2.TRASH_DIR):
+    if not is_reserved_directory(doc):
       # Remove any deprecated fields
       # Remove any deprecated fields
       if 'tags' in doc['fields']:
       if 'tags' in doc['fields']:
         doc['fields'].pop('tags')
         doc['fields'].pop('tags')