Explorar o código

HUE-6310 [doc2] [doc2] Create missing doc1 links for delete and copy operations

Added a wrapper method in Document2 class that creates the missing doc1 links
krish %!s(int64=8) %!d(string=hai) anos
pai
achega
1534ccc

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

@@ -1341,6 +1341,24 @@ class Document2(models.Model):
 
     perm.save()
 
+  def _get_doc1(self, doc2_type=None):
+    if not doc2_type:
+      doc2_type = self.type
+
+    try:
+      doc = self.doc.get()
+    except Exception, e:
+      LOG.error('Exception when retrieving document object for saved query: %s' % e)
+      doc = Document.objects.link(
+        self,
+        owner=self.owner,
+        name=self.name,
+        description=self.description,
+        extra=doc2_type
+      )
+
+    return doc
+
   def _massage_permissions(self):
     """
     Returns the permissions for a given document as a dictionary

+ 1 - 13
desktop/libs/notebook/src/notebook/api.py

@@ -327,19 +327,7 @@ def _save_notebook(notebook, user):
   notebook['isSaved'] = True
   notebook['isHistory'] = False
   notebook['id'] = notebook_doc.id
-
-  try:
-    notebook_doc1 = notebook_doc.doc.get()
-  except Exception, e:
-    LOG.error('Exception when retrieving document object for saved query: %s' % e)
-    notebook_doc1 = Document.objects.link(
-      notebook_doc,
-      owner=notebook_doc.owner,
-      name=notebook_doc.name,
-      description=notebook_doc.description,
-      extra=notebook_type
-    )
-
+  notebook_doc1 = notebook_doc._get_doc1(doc2_type=notebook_type)
   notebook_doc.update_data(notebook)
   notebook_doc.search = _get_statement(notebook)
   notebook_doc.name = notebook_doc1.name = notebook['name']

+ 2 - 3
desktop/libs/notebook/src/notebook/views.py

@@ -250,7 +250,7 @@ def delete(request):
     for notebook in notebooks:
       try:
         doc2 = Document2.objects.get_by_uuid(user=request.user, uuid=notebook['uuid'], perm_type='write')
-        doc = doc2.doc.get()
+        doc = doc2._get_doc1()
         doc.can_write_or_exception(request.user)
         doc2.trash()
         ctr += 1
@@ -282,8 +282,7 @@ def copy(request):
     for notebook in notebooks:
       try:
         doc2 = Document2.objects.get_by_uuid(user=request.user, uuid=notebook['uuid'])
-        doc = doc2.doc.get()
-
+        doc = doc2._get_doc1()
         name = doc2.name + '-copy'
         doc2 = doc2.copy(name=name, owner=request.user)