Browse Source

Merge branch 'imprv/separate-main-sub-process' into feat/page-operation-model

Taichi Masuyama 4 years ago
parent
commit
b846e90612

+ 7 - 6
packages/app/src/server/service/page.ts

@@ -745,7 +745,7 @@ class PageService {
         /*
          * Sub Operation
          */
-        await this.duplicateDescendantsSubOperation(page, newPagePath, user, duplicatedTarget._id, nDuplicatedPages);
+        await this.duplicateDescendantsSubOperation(page, newPagePath, user, duplicatedTarget, nDuplicatedPages);
       })();
     }
 
@@ -754,7 +754,7 @@ class PageService {
     return result;
   }
 
-  async duplicateDescendantsSubOperation(page, newPagePath: string, user, duplicatedTargetId: ObjectIdLike, nDuplicatedPages: number): Promise<void> {
+  async duplicateDescendantsSubOperation(page, newPagePath: string, user, duplicatedTarget, nDuplicatedPages: number): Promise<void> {
     // normalize parent of descendant pages
     const shouldNormalize = this.shouldNormalizeParent(page);
     if (shouldNormalize) {
@@ -767,7 +767,7 @@ class PageService {
         throw err;
       }
     }
-    await this.updateDescendantCountOfAncestors(duplicatedTargetId, nDuplicatedPages, false);
+    await this.updateDescendantCountOfAncestors(duplicatedTarget._id, nDuplicatedPages, false);
   }
 
   async duplicateV4(page, newPagePath, user, isRecursively) {
@@ -1906,10 +1906,12 @@ class PageService {
       throw Error(`The maximum number of pageIds allowed is ${LIMIT_FOR_MULTIPLE_PAGE_OP}.`);
     }
 
+    const pagesToNormalize = omitDuplicateAreaPageFromPages(pages);
+
     let normalizablePages;
     let nonNormalizablePages;
     try {
-      [normalizablePages, nonNormalizablePages] = await this.crowi.pageGrantService.separateNormalizableAndNotNormalizablePages(pages);
+      [normalizablePages, nonNormalizablePages] = await this.crowi.pageGrantService.separateNormalizableAndNotNormalizablePages(pagesToNormalize);
     }
     catch (err) {
       throw err;
@@ -1928,8 +1930,7 @@ class PageService {
     /*
      * Sub Operation (s)
      */
-    const pagesToNormalize = omitDuplicateAreaPageFromPages(pages);
-    for await (const page of pagesToNormalize) {
+    for await (const page of normalizablePages) {
       await this.normalizeParentRecursivelySubOperation(page, user);
     }
   }

+ 5 - 3
packages/app/test/integration/service/v5-migration.test.js

@@ -56,14 +56,16 @@ describe('V5 page migration', () => {
           grantedUsers: [testUser1._id],
         },
       ]);
-      const additionalPages = (await Page.exists({ path: '/' })) ? null : await Page.insertMany([{ path: '/', grant: Page.GRANT_PUBLIC }]);
 
-      if (additionalPages != null) {
+      if (!await Page.exists({ path: '/' })) {
+        const additionalPages = await Page.insertMany([{ path: '/', grant: Page.GRANT_PUBLIC }]);
         pages = [...additionalPages, ...pages];
       }
 
+      const pagesToRun = await Page.find({ path: { $in: ['/private1', '/dummyParent/private1'] } });
+
       // migrate
-      await crowi.pageService.normalizeParentRecursivelyByPages(pages, testUser1);
+      await crowi.pageService.normalizeParentRecursivelyByPages(pagesToRun, testUser1);
 
       const migratedPages = await Page.find({
         path: {