Przeglądaj źródła

Merge pull request #9587 from overleaf/em-dropbox-to-overleaf

Record metadata on Dropbox-to-Overleaf updates

GitOrigin-RevId: 34eb774a52d1c683fb1dddecc1c4c646bfc9eb2e
Eric Mc Sween 3 lat temu
rodzic
commit
76e0265ed7

+ 2 - 2
services/web/app/src/Features/Editor/EditorController.js

@@ -213,7 +213,7 @@ const EditorController = {
                 userId
               )
             }
-            callback(null, doc)
+            callback(null, { doc, folder: lastFolder })
           }
         )
       }
@@ -273,7 +273,7 @@ const EditorController = {
               linkedFileData,
               userId
             )
-            callback(null, newFile)
+            callback(null, { file: newFile, folder: lastFolder })
           }
         )
       }

+ 5 - 1
services/web/app/src/Features/ThirdPartyDataStore/TpdsController.js

@@ -55,9 +55,13 @@ async function mergeUpdate(req, res) {
     status: 'applied',
     entityId: metadata.entityId.toString(),
     entityType: metadata.entityType,
+    folderId: metadata.folderId.toString(),
   }
+
+  // When the update is a doc edit, the update is merged in docupdater and
+  // doesn't generate a new rev.
   if (metadata.rev != null) {
-    payload.rev = metadata.rev
+    payload.rev = metadata.rev.toString()
   }
   res.json(payload)
 }

+ 28 - 10
services/web/app/src/Features/ThirdPartyDataStore/UpdateMerger.js

@@ -75,15 +75,33 @@ async function _mergeUpdate(userId, projectId, path, fsPath, source) {
   const fileType = await _determineFileType(projectId, path, fsPath)
 
   if (fileType === 'file') {
-    const file = await _processFile(projectId, fsPath, path, source, userId)
-    return { entityType: 'file', entityId: file._id, rev: file.rev }
+    const { file, folder } = await _processFile(
+      projectId,
+      fsPath,
+      path,
+      source,
+      userId
+    )
+    return {
+      entityType: 'file',
+      entityId: file._id,
+      rev: file.rev,
+      folderId: folder._id,
+    }
   } else if (fileType === 'doc') {
-    const doc = await _processDoc(projectId, userId, fsPath, path, source)
-    // The doc entry doesn't have a rev. Since the document is set in
-    // docupdater, it's possible that the next rev contains a merge of changes
-    // in Dropbox and changes from docupdater.
-    const metadata = { entityType: 'doc', entityId: doc._id, rev: doc.rev }
-    return metadata
+    const { doc, folder } = await _processDoc(
+      projectId,
+      userId,
+      fsPath,
+      path,
+      source
+    )
+    return {
+      entityType: 'doc',
+      entityId: doc._id,
+      rev: doc.rev,
+      folderId: folder._id,
+    }
   } else {
     throw new Error('unrecognized file')
   }
@@ -119,7 +137,7 @@ async function _processDoc(projectId, userId, fsPath, path, source) {
 }
 
 async function _processFile(projectId, fsPath, path, source, userId) {
-  const file = await EditorController.promises.upsertFileWithPath(
+  const { file, folder } = await EditorController.promises.upsertFileWithPath(
     projectId,
     path,
     fsPath,
@@ -127,7 +145,7 @@ async function _processFile(projectId, fsPath, path, source, userId) {
     source,
     userId
   )
-  return file
+  return { file, folder }
 }
 
 async function _readFileIntoTextArray(path) {

+ 3 - 1
services/web/test/unit/src/ThirdPartyDataStore/TpdsControllerTests.js

@@ -11,6 +11,7 @@ describe('TpdsController', function () {
   beforeEach(function () {
     this.metadata = {
       entityId: ObjectId(),
+      folderId: ObjectId(),
       entityType: 'doc',
       rev: 2,
     }
@@ -69,8 +70,9 @@ describe('TpdsController', function () {
           expect(payload).to.deep.equal({
             status: 'applied',
             entityId: this.metadata.entityId.toString(),
+            folderId: this.metadata.folderId.toString(),
             entityType: this.metadata.entityType,
-            rev: this.metadata.rev,
+            rev: this.metadata.rev.toString(),
           })
           this.TpdsUpdateHandler.promises.newUpdate
             .calledWith(

+ 10 - 2
services/web/test/unit/src/ThirdPartyDataStore/UpdateMergerTests.js

@@ -49,11 +49,19 @@ describe('UpdateMerger :', function () {
       rev: 6,
     }
 
+    this.folder = {
+      _id: ObjectId(),
+    }
+
     this.EditorController = {
       promises: {
         deleteEntityWithPath: sinon.stub().resolves(),
-        upsertDocWithPath: sinon.stub().resolves(this.doc),
-        upsertFileWithPath: sinon.stub().resolves(this.file),
+        upsertDocWithPath: sinon
+          .stub()
+          .resolves({ doc: this.doc, folder: this.folder }),
+        upsertFileWithPath: sinon
+          .stub()
+          .resolves({ file: this.file, folder: this.folder }),
       },
     }