yuken 3 лет назад
Родитель
Сommit
d015ab562b

+ 4 - 2
packages/app/src/components/Page/FixPageGrantAlert.tsx

@@ -8,7 +8,7 @@ import {
 import { toastError, toastSuccess } from '~/client/util/apiNotification';
 import { apiv3Put } from '~/client/util/apiv3-client';
 import { PageGrant } from '~/interfaces/page';
-import { IRecordApplicableGrant } from '~/interfaces/page-grant';
+import { IRecordApplicableGrant, IResIsGrantNormalizedGrantData } from '~/interfaces/page-grant';
 import { useCurrentPageId, useHasParent } from '~/stores/context';
 import { useSWRxApplicableGrant, useSWRxIsGrantNormalized } from '~/stores/page';
 
@@ -16,6 +16,7 @@ type ModalProps = {
   isOpen: boolean
   pageId: string
   dataApplicableGrant: IRecordApplicableGrant
+  grantData: IResIsGrantNormalizedGrantData
   close(): void
 }
 
@@ -194,7 +195,7 @@ const FixPageGrantAlert = (): JSX.Element => {
   if (!hasParent) {
     return <></>;
   }
-  if (dataIsGrantNormalized?.isGrantNormalized == null || dataIsGrantNormalized.isGrantNormalized) {
+  if (dataIsGrantNormalized?.grantData == null || dataIsGrantNormalized?.isGrantNormalized == null || dataIsGrantNormalized.isGrantNormalized) {
     return <></>;
   }
 
@@ -218,6 +219,7 @@ const FixPageGrantAlert = (): JSX.Element => {
             isOpen={isOpen}
             pageId={pageId}
             dataApplicableGrant={dataApplicableGrant}
+            grantData={dataIsGrantNormalized.grantData}
             close={() => setOpen(false)}
           />
         )

+ 16 - 0
packages/app/src/interfaces/page-grant.ts

@@ -9,3 +9,19 @@ export type IRecordApplicableGrant = Record<PageGrant, IDataApplicableGrant>
 export type IResApplicableGrant = {
   data?: IRecordApplicableGrant
 }
+type IPageGrantData = {
+  grant: number,
+  grantedGroup?: {
+    id: string,
+    name: string
+  }
+}
+export type IResIsGrantNormalizedGrantData = {
+  isForbidden: boolean,
+  currentPageGrant: IPageGrantData,
+  parentPageGrant?: IPageGrantData
+}
+export type IResIsGrantNormalized = {
+  isGrantNormalized: boolean,
+  grantData: IResIsGrantNormalizedGrantData
+};

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

@@ -425,6 +425,7 @@ module.exports = (crowi) => {
 
     const Page = crowi.model('Page');
     const page = await Page.findByIdAndViewer(pageId, req.user, null, false);
+    const parentPage = await Page.findByIdAndViewer(page.parent, req.user, null, false);
 
     if (page == null) {
       return res.apiv3Err(new ErrorV3('Page is unreachable or empty.', 'page_unreachable_or_empty'), 400);
@@ -443,7 +444,33 @@ module.exports = (crowi) => {
       return res.apiv3Err(err, 500);
     }
 
-    return res.apiv3({ isGrantNormalized });
+    const currentPageGrant = {
+      grant,
+      grantedGroup: grantedGroup != null
+        ? {
+          id: grantedGroup._id,
+          name: grantedGroup.name,
+        }
+        : null,
+    };
+
+    const parentPageGrant = {
+      grant: parentPage.grant,
+      grantedGroup: parentPage.grantedGroup != null
+        ? {
+          id: parentPage.grantedGroup._id,
+          name: parentPage.grantedGroup.name,
+        }
+        : null,
+    };
+
+    const grantData = {
+      isForbidden: parentPage != null,
+      currentPageGrant,
+      parentPageGrant: parentPage != null ? parentPageGrant : null,
+    };
+
+    return res.apiv3({ isGrantNormalized, grantData });
   });
 
   router.get('/applicable-grant', loginRequiredStrictly, validator.applicableGrant, apiV3FormValidator, async(req, res) => {

+ 1 - 2
packages/app/src/stores/page.tsx

@@ -7,7 +7,7 @@ import { HasObjectId } from '~/interfaces/has-object-id';
 import {
   IPageInfo, IPageHasId, IPageInfoForOperation, IPageInfoForListing, IDataWithMeta,
 } from '~/interfaces/page';
-import { IRecordApplicableGrant } from '~/interfaces/page-grant';
+import { IRecordApplicableGrant, IResIsGrantNormalized } from '~/interfaces/page-grant';
 import { IPagingResult } from '~/interfaces/paging-result';
 
 import { apiGet } from '../client/util/apiv1-client';
@@ -151,7 +151,6 @@ export const useSWRxPageInfoForList = (
 /*
  * Grant normalization fetching hooks
  */
-export type IResIsGrantNormalized = { isGrantNormalized: boolean };
 export const useSWRxIsGrantNormalized = (
     pageId: string | null | undefined,
 ): SWRResponse<IResIsGrantNormalized, Error> => {