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

+ 22 - 2
packages/app/src/pages/[[...path]].page.tsx

@@ -32,6 +32,7 @@ import type { CrowiRequest } from '~/interfaces/crowi-request';
 // import { useRendererSettings } from '~/stores/renderer';
 // import { EditorMode, useEditorMode, useIsMobile } from '~/stores/ui';
 import type { EditorConfig } from '~/interfaces/editor-settings';
+import { IPageGrantData } from '~/interfaces/page';
 import type { RendererConfig } from '~/interfaces/services/renderer';
 import type { ISidebarConfig } from '~/interfaces/sidebar-config';
 import type { IUserUISettings } from '~/interfaces/user-ui-settings';
@@ -184,6 +185,8 @@ type Props = CommonProps & {
   isIndentSizeForced: boolean,
   disableLinkSharing: boolean,
 
+  grantData?: IPageGrantData,
+
   rendererConfig: RendererConfig,
 
   // UI
@@ -283,8 +286,9 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
 
   // sync grant data
   useEffect(() => {
-    mutateSelectedGrant(grantData?.grantData.currentPageGrant);
-  }, [grantData?.grantData.currentPageGrant, mutateSelectedGrant]);
+    const grantDataToApply = props.grantData ? props.grantData : grantData?.grantData.currentPageGrant;
+    mutateSelectedGrant(grantDataToApply);
+  }, [grantData?.grantData.currentPageGrant, mutateSelectedGrant, props.grantData]);
 
   // sync pathname by Shallow Routing https://nextjs.org/docs/routing/shallow-routing
   useEffect(() => {
@@ -448,6 +452,22 @@ async function injectPageData(context: GetServerSidePropsContext, props: Props):
     if (templateData != null) {
       props.templateTagData = templateData.templateTags as string[];
       props.templateBodyData = templateData.templateBody as string;
+
+      // 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);
+      }
     }
   }