Yuken Tezuka пре 3 година
родитељ
комит
ba70062722
1 измењених фајлова са 16 додато и 11 уклоњено
  1. 16 11
      packages/app/src/pages/[[...path]].page.tsx

+ 16 - 11
packages/app/src/pages/[[...path]].page.tsx

@@ -396,6 +396,21 @@ class MultiplePagesHitsError extends ExtensibleCustomError {
 
 }
 
+// apply parent page grant fot creating page
+async function applyGrantToPage(props: Props, ancestor: any) {
+  await ancestor.populate('grantedGroup');
+  const grant = {
+    grant: ancestor.grant,
+  };
+  const grantedGroup = ancestor.grantedGroup ? {
+    grantedGroup: {
+      id: ancestor.grantedGroup.id,
+      name: ancestor.grantedGroup.name,
+    },
+  } : {};
+  props.grantData = Object.assign(grant, grantedGroup);
+}
+
 async function injectPageData(context: GetServerSidePropsContext, props: Props): Promise<void> {
   const { model: mongooseModel } = await import('mongoose');
 
@@ -456,17 +471,7 @@ async function injectPageData(context: GetServerSidePropsContext, props: Props):
       // take over pagrent page grant
       const ancestor = await Page.findAncestorByPathAndViewer(currentPathname, user);
       if (ancestor != null) {
-        await ancestor.populate('grantedGroup');
-        const grant = {
-          grant: ancestor.grant,
-        };
-        const grantedGroup = ancestor.grantedGroup ? {
-          grantedGroup: {
-            id: ancestor.grantedGroup.id,
-            name: ancestor.grantedGroup.name,
-          },
-        } : {};
-        props.grantData = Object.assign(grant, grantedGroup);
+        await applyGrantToPage(props, ancestor);
       }
     }
   }