Просмотр исходного кода

consider overwriteScopesOfDescendants option

Yuki Takei 3 лет назад
Родитель
Сommit
5541faa2af
2 измененных файлов с 9 добавлено и 6 удалено
  1. 8 5
      packages/app/src/server/models/page.ts
  2. 1 1
      packages/app/src/server/routes/page.js

+ 8 - 5
packages/app/src/server/models/page.ts

@@ -1001,7 +1001,7 @@ export default (crowi): any => {
       body: string | null,
       previousBody: string | null,
       user,
-      options: {grant?: PageGrant, grantUserGroupId?: ObjectIdLike, isSyncRevisionToHackmd?: boolean} = {},
+      options: {grant?: PageGrant, grantUserGroupId?: ObjectIdLike, isSyncRevisionToHackmd?: boolean, overwriteScopesOfDescendants?: boolean} = {},
   ) {
     if (crowi.configManager == null || crowi.pageGrantService == null || crowi.pageService == null) {
       throw Error('Crowi is not set up');
@@ -1026,10 +1026,13 @@ export default (crowi): any => {
 
     const newPageData = pageData;
 
+    const { pageService, pageGrantService } = crowi;
+
     if (shouldBeOnTree) {
       let isGrantNormalized = false;
       try {
-        isGrantNormalized = await crowi.pageGrantService.isGrantNormalized(user, pageData.path, grant, grantedUserIds, grantUserGroupId, true);
+        const shouldCheckDescendants = options.overwriteScopesOfDescendants !== true;
+        isGrantNormalized = await pageGrantService.isGrantNormalized(user, pageData.path, grant, grantedUserIds, grantUserGroupId, shouldCheckDescendants);
       }
       catch (err) {
         logger.error(`Failed to validate grant of page at "${pageData.path}" of grant ${grant}:`, err);
@@ -1040,7 +1043,7 @@ export default (crowi): any => {
       }
 
       if (!wasOnTree) {
-        const newParent = await crowi.pageService.getParentAndFillAncestorsByUser(user, newPageData.path);
+        const newParent = await pageService.getParentAndFillAncestorsByUser(user, newPageData.path);
         newPageData.parent = newParent._id;
       }
     }
@@ -1103,14 +1106,14 @@ export default (crowi): any => {
     const shouldPlusDescCount = !wasOnTree && shouldBeOnTree;
     const shouldMinusDescCount = wasOnTree && !shouldBeOnTree;
     if (shouldPlusDescCount) {
-      await crowi.pageService.updateDescendantCountOfAncestors(newPageData._id, 1, false);
+      await pageService.updateDescendantCountOfAncestors(newPageData._id, 1, false);
       const newDescendantCount = await this.recountDescendantCount(newPageData._id);
       await this.updateOne({ _id: newPageData._id }, { descendantCount: newDescendantCount });
     }
     else if (shouldMinusDescCount) {
       // Update from parent. Parent is null if newPageData.grant is RESTRECTED.
       if (newPageData.grant === GRANT_RESTRICTED) {
-        await crowi.pageService.updateDescendantCountOfAncestors(exParent, -1, true);
+        await pageService.updateDescendantCountOfAncestors(exParent, -1, true);
       }
     }
 

+ 1 - 1
packages/app/src/server/routes/page.js

@@ -1014,7 +1014,7 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error('Posted param "revisionId" is outdated.', 'conflict', returnLatestRevision));
     }
 
-    const options = { isSyncRevisionToHackmd };
+    const options = { isSyncRevisionToHackmd, overwriteScopesOfDescendants };
     if (grant != null) {
       options.grant = grant;
       options.grantUserGroupId = grantUserGroupId;