Explorar el Código

WIP: impl when update

Yuki Takei hace 7 años
padre
commit
2c11c33bbf
Se han modificado 2 ficheros con 29 adiciones y 24 borrados
  1. 23 23
      src/server/models/page.js
  2. 6 1
      src/server/routes/page.js

+ 23 - 23
src/server/models/page.js

@@ -859,29 +859,6 @@ module.exports = function(crowi) {
     }
   }
 
-  async function applyScopesToDescendantsAsyncronously(parentPage, user) {
-    const builder = new PageQueryBuilder(this.find());
-    builder.addConditionToListWithDescendants(parentPage.path);
-
-    builder.addConditionToExcludeRedirect();
-
-    // add grant conditions
-    await addConditionToFilteringByViewerForList(builder, user);
-
-    // get all pages that the specified user can update
-    const pages = builder.query.exec();
-
-    for (const page in pages) {
-      // skip parentPage
-      if (page._id === parentPage._id) {
-        continue;
-      }
-
-      applyScope(page, user, parentPage.grant, parentPage.grantedGroup);
-      page.save();
-    }
-  }
-
   pageSchema.statics.create = function(path, body, user, options = {}) {
     validateCrowi();
 
@@ -970,6 +947,29 @@ module.exports = function(crowi) {
     return savedPage;
   };
 
+  pageSchema.statics.applyScopesToDescendantsAsyncronously = async function(parentPage, user) {
+    const builder = new PageQueryBuilder(this.find());
+    builder.addConditionToListWithDescendants(parentPage.path);
+
+    builder.addConditionToExcludeRedirect();
+
+    // add grant conditions
+    await addConditionToFilteringByViewerForList(builder, user);
+
+    // get all pages that the specified user can update
+    const pages = await builder.query.exec();
+
+    for (const page of pages) {
+      // skip parentPage
+      if (page.id === parentPage.id) {
+        continue;
+      }
+
+      applyScope(page, user, parentPage.grant, parentPage.grantedGroup);
+      page.save();
+    }
+  };
+
   pageSchema.statics.deletePage = async function(pageData, user, options = {}) {
     const newPath = this.getDeletedPageName(pageData.path)
       , isTrashed = checkIfTrashed(pageData.path)

+ 6 - 1
src/server/routes/page.js

@@ -595,7 +595,7 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error('Posted param "revisionId" is outdated.', 'outdated'));
     }
 
-    const options = {overwriteScopesOfDescendants, isSyncRevisionToHackmd, socketClientId};
+    const options = {isSyncRevisionToHackmd, socketClientId};
     if (grant != null) {
       options.grant = grant;
     }
@@ -617,6 +617,11 @@ module.exports = function(crowi, app) {
     result.page.lastUpdateUser = User.filterToPublicFields(page.lastUpdateUser);
     res.json(ApiResponse.success(result));
 
+    // update scopes for descendants
+    if (overwriteScopesOfDescendants) {
+      Page.applyScopesToDescendantsAsyncronously(page, req.user);
+    }
+
     // global notification
     try {
       await globalNotificationService.notifyPageEdit(page);