Browse Source

set default value for onlyDuplicateUserRelatedGrantedGroups

Futa Arai 2 years ago
parent
commit
29d1178d43

+ 6 - 4
apps/app/src/server/service/page.ts

@@ -1012,7 +1012,7 @@ class PageService {
   /*
   /*
    * Duplicate
    * Duplicate
    */
    */
-  async duplicate(page: PageDocument, newPagePath: string, user, isRecursively: boolean, onlyDuplicateUserRelatedGrantedGroups: boolean) {
+  async duplicate(page: PageDocument, newPagePath: string, user, isRecursively: boolean, onlyDuplicateUserRelatedGrantedGroups = false) {
     /*
     /*
      * Common Operation
      * Common Operation
      */
      */
@@ -1146,7 +1146,7 @@ class PageService {
   }
   }
 
 
   async duplicateRecursivelyMainOperation(page: PageDocument, newPagePath: string, user, pageOpId: ObjectIdLike): Promise<void> {
   async duplicateRecursivelyMainOperation(page: PageDocument, newPagePath: string, user, pageOpId: ObjectIdLike): Promise<void> {
-    const nDuplicatedPages = await this.duplicateDescendantsWithStream(page, newPagePath, user, false);
+    const nDuplicatedPages = await this.duplicateDescendantsWithStream(page, newPagePath, user, false, false);
 
 
     // normalize parent of descendant pages
     // normalize parent of descendant pages
     const shouldNormalize = this.shouldNormalizeParent(page);
     const shouldNormalize = this.shouldNormalizeParent(page);
@@ -1294,6 +1294,8 @@ class PageService {
 
 
       let newPage;
       let newPage;
       if (!page.isEmpty) {
       if (!page.isEmpty) {
+        // TODO: GROUP_GRANT で、なおかつユーザが所属するグループが含まれている時のみ有効にすべき。そうでないと、誰もアクセスできないページとなってしまう。
+        // これはかなり複雑な仕様になるが、本当に他の方法はないのか検討
         const grantedGroups = onlyDuplicateUserRelatedGrantedGroups
         const grantedGroups = onlyDuplicateUserRelatedGrantedGroups
           ? this.pageGrantService.filterGrantedGroupsByIds(page, userRelatedGroupIds)
           ? this.pageGrantService.filterGrantedGroupsByIds(page, userRelatedGroupIds)
           : page.grantedGroups;
           : page.grantedGroups;
@@ -1365,7 +1367,7 @@ class PageService {
     await this.duplicateTags(pageIdMapping);
     await this.duplicateTags(pageIdMapping);
   }
   }
 
 
-  private async duplicateDescendantsWithStream(page, newPagePath, user, onlyDuplicateUserRelatedGrantedGroups: boolean, shouldUseV4Process = true) {
+  private async duplicateDescendantsWithStream(page, newPagePath, user, onlyDuplicateUserRelatedGrantedGroups = false, shouldUseV4Process = true) {
     if (shouldUseV4Process) {
     if (shouldUseV4Process) {
       return this.duplicateDescendantsWithStreamV4(page, newPagePath, user, onlyDuplicateUserRelatedGrantedGroups);
       return this.duplicateDescendantsWithStreamV4(page, newPagePath, user, onlyDuplicateUserRelatedGrantedGroups);
     }
     }
@@ -1413,7 +1415,7 @@ class PageService {
     return nNonEmptyDuplicatedPages;
     return nNonEmptyDuplicatedPages;
   }
   }
 
 
-  private async duplicateDescendantsWithStreamV4(page, newPagePath, user, onlyDuplicateUserRelatedGrantedGroups: boolean) {
+  private async duplicateDescendantsWithStreamV4(page, newPagePath, user, onlyDuplicateUserRelatedGrantedGroups = false) {
     const readStream = await this.generateReadStreamToOperateOnlyDescendants(page.path, user);
     const readStream = await this.generateReadStreamToOperateOnlyDescendants(page.path, user);
 
 
     const newPagePathPrefix = newPagePath;
     const newPagePathPrefix = newPagePath;

+ 14 - 4
apps/app/test/integration/service/v5.non-public-page.test.ts

@@ -507,7 +507,12 @@ describe('PageService page operations with non-public pages', () => {
         _id: pageIdDuplicate2,
         _id: pageIdDuplicate2,
         path: '/np_duplicate2',
         path: '/np_duplicate2',
         grant: Page.GRANT_USER_GROUP,
         grant: Page.GRANT_USER_GROUP,
-        grantedGroups: [{ item: groupIdA, type: GroupType.userGroup }, { item: externalGroupIdA, type: GroupType.externalUserGroup }],
+        grantedGroups: [
+          { item: groupIdA, type: GroupType.userGroup },
+          { item: externalGroupIdA, type: GroupType.externalUserGroup },
+          { item: groupIdC, type: GroupType.userGroup },
+          { item: externalGroupIdC, type: GroupType.externalUserGroup },
+        ],
         creator: npDummyUser1._id,
         creator: npDummyUser1._id,
         lastUpdateUser: npDummyUser1._id,
         lastUpdateUser: npDummyUser1._id,
         revision: revisionIdDuplicate2,
         revision: revisionIdDuplicate2,
@@ -517,7 +522,12 @@ describe('PageService page operations with non-public pages', () => {
         _id: pageIdDuplicate3,
         _id: pageIdDuplicate3,
         path: '/np_duplicate2/np_duplicate3',
         path: '/np_duplicate2/np_duplicate3',
         grant: Page.GRANT_USER_GROUP,
         grant: Page.GRANT_USER_GROUP,
-        grantedGroups: [{ item: groupIdB, type: GroupType.userGroup }, { item: externalGroupIdB, type: GroupType.externalUserGroup }],
+        grantedGroups: [
+          { item: groupIdB, type: GroupType.userGroup },
+          { item: externalGroupIdB, type: GroupType.externalUserGroup },
+          { item: groupIdC, type: GroupType.userGroup },
+          { item: externalGroupIdC, type: GroupType.externalUserGroup },
+        ],
         creator: npDummyUser2._id,
         creator: npDummyUser2._id,
         lastUpdateUser: npDummyUser2._id,
         lastUpdateUser: npDummyUser2._id,
         revision: revisionIdDuplicate3,
         revision: revisionIdDuplicate3,
@@ -1083,10 +1093,10 @@ describe('PageService page operations with non-public pages', () => {
   });
   });
   describe('Duplicate', () => {
   describe('Duplicate', () => {
 
 
-    const duplicate = async(page, newPagePath, user, isRecursively) => {
+    const duplicate = async(page, newPagePath, user, isRecursively, onlyDuplicateUserRelatedGrantedGroups = false) => {
       // mock return value
       // mock return value
       const mockedDuplicateRecursivelyMainOperation = jest.spyOn(crowi.pageService, 'duplicateRecursivelyMainOperation').mockReturnValue(null);
       const mockedDuplicateRecursivelyMainOperation = jest.spyOn(crowi.pageService, 'duplicateRecursivelyMainOperation').mockReturnValue(null);
-      const duplicatedPage = await crowi.pageService.duplicate(page, newPagePath, user, isRecursively);
+      const duplicatedPage = await crowi.pageService.duplicate(page, newPagePath, user, isRecursively, onlyDuplicateUserRelatedGrantedGroups);
 
 
       // retrieve the arguments passed when calling method duplicateRecursivelyMainOperation inside duplicate method
       // retrieve the arguments passed when calling method duplicateRecursivelyMainOperation inside duplicate method
       const argsForDuplicateRecursivelyMainOperation = mockedDuplicateRecursivelyMainOperation.mock.calls[0];
       const argsForDuplicateRecursivelyMainOperation = mockedDuplicateRecursivelyMainOperation.mock.calls[0];