Sfoglia il codice sorgente

HUE-8758 [api] Add list of document types to config

To avoid hardcoding https://github.com/cloudera/hue/blob/master/desktop/core/src/desktop/js/doc/docSupport.js#L19

Filter search in assist will be consistent with user documents.

We might want to refresh at some point when creating the first
documents.
Romain 5 anni fa
parent
commit
7be9392eb6

+ 9 - 3
desktop/core/src/desktop/api2.py

@@ -84,10 +84,14 @@ def api_error_handler(func):
 def get_config(request):
   config = get_cluster_config(request.user)
   config['clusters'] = list(get_clusters(request.user).values())
+  config['documents'] = {
+    'types': list(Document2.objects.documents(user=request.user).distinct().values_list('type', flat=True))
+  }
   config['status'] = 0
 
   return JsonResponse(config)
 
+
 @api_error_handler
 def get_hue_config(request):
   if not is_admin(request.user):
@@ -582,7 +586,6 @@ def copy_document(request):
   if not uuid:
     raise PopupException(_('copy_document requires uuid'))
 
-
   # Document2 and Document model objects are linked and both are saved when saving
   document = Document2.objects.get_by_uuid(user=request.user, uuid=uuid)
   # Document model object
@@ -643,6 +646,7 @@ def copy_document(request):
     'document': copy_document.to_dict()
   })
 
+
 @api_error_handler
 @require_POST
 def restore_document(request):
@@ -1013,7 +1017,8 @@ def search_entities_interactive(request):
           'uuid': e.uuid,
           'parentUuid': e.parent_directory.uuid,
           'originalName': escape(e.name)
-        } for e in entities['documents']
+        }
+        for e in entities['documents']
       ],
       'count': len(entities['documents']),
       'status': 0
@@ -1177,7 +1182,8 @@ def __filter_documents(type_filters, sort, search_text, queryset, flatten=True):
   documents = queryset.search_documents(
       types=type_filters,
       search_text=search_text,
-      order_by=sort)
+      order_by=sort
+  )
 
   # Roll up documents to common directory
   if not flatten:

+ 28 - 0
desktop/core/src/desktop/api2_tests.py

@@ -62,6 +62,7 @@ class TestApi2(object):
     finally:
       query.delete()
 
+
   def test_get_hue_config(self):
     client = make_logged_in_client(username="api2_superuser", groupname="default", recreate=True, is_superuser=True)
     user = User.objects.get(username="api2_superuser")
@@ -112,6 +113,33 @@ class TestApi2(object):
     # There should be more private than non-private
     assert_true(len(response.content) < len(private_response.content))
 
+
+  def test_get_config(self):
+    response = self.client.get('/desktop/api2/get_config')
+
+    assert_equal(200, response.status_code)
+    config = json.loads(response.content)
+
+    assert_true('types' in config['documents'])
+    assert_false('query-TestApi2.test_get_config' in config['documents']['types'], config)
+
+    doc = Document2.objects.create(
+        name='Query xxx',
+        type='query-TestApi2.test_get_config',
+        owner=self.user
+    )
+
+    try:
+      response = self.client.get('/desktop/api2/get_config')
+
+      assert_equal(200, response.status_code)
+      config = json.loads(response.content)
+
+      assert_true('query-TestApi2.test_get_config' in config['documents']['types'], config)
+    finally:
+      doc.delete()
+
+
 class TestDocumentApiSharingPermissions(object):
 
   def setUp(self):

+ 1 - 1
desktop/core/src/desktop/js/ko/components/assist/ko.assistDocumentsPanel.js

@@ -49,7 +49,7 @@ const TEMPLATE = `
       'Share'
     )}</a></li>
   </script>
-  
+
   <script type="text/html" id="assist-document-header-actions">
     <div class="assist-db-header-actions">
       <!-- ko if: !loading() -->

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

@@ -1484,6 +1484,7 @@ class Document2(models.Model):
       permissions['link_read'] = link_read_perm.is_link_on
     if link_write_perm:
       permissions['link_write'] = link_write_perm.is_link_on
+
     permissions['link_sharing_on'] = permissions['link_read'] or permissions['link_write']
 
     return permissions
@@ -1518,6 +1519,7 @@ class Document2(models.Model):
 
     slow = self
     fast = self
+
     while True:
       slow = slow.parent_directory
       if slow and slow.uuid == self.uuid: