yuken il y a 3 ans
Parent
commit
2c8d26880e

+ 45 - 5
packages/app/src/components/Page/FixPageGrantAlert.tsx

@@ -8,7 +8,7 @@ import {
 import { toastError, toastSuccess } from '~/client/util/apiNotification';
 import { toastError, toastSuccess } from '~/client/util/apiNotification';
 import { apiv3Put } from '~/client/util/apiv3-client';
 import { apiv3Put } from '~/client/util/apiv3-client';
 import { PageGrant } from '~/interfaces/page';
 import { PageGrant } from '~/interfaces/page';
-import { IRecordApplicableGrant, IResIsGrantNormalizedGrantData } from '~/interfaces/page-grant';
+import { IRecordApplicableGrant, IResIsGrantNormalizedGrantData, IPageGrantData } from '~/interfaces/page-grant';
 import { useCurrentPageId, useHasParent } from '~/stores/context';
 import { useCurrentPageId, useHasParent } from '~/stores/context';
 import { useSWRxApplicableGrant, useSWRxIsGrantNormalized } from '~/stores/page';
 import { useSWRxApplicableGrant, useSWRxIsGrantNormalized } from '~/stores/page';
 
 
@@ -16,7 +16,7 @@ type ModalProps = {
   isOpen: boolean
   isOpen: boolean
   pageId: string
   pageId: string
   dataApplicableGrant: IRecordApplicableGrant
   dataApplicableGrant: IRecordApplicableGrant
-  grantData: IResIsGrantNormalizedGrantData
+  currentAndParentPageGrantData: IResIsGrantNormalizedGrantData
   close(): void
   close(): void
 }
 }
 
 
@@ -24,7 +24,7 @@ const FixPageGrantModal = (props: ModalProps): JSX.Element => {
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
   const {
   const {
-    isOpen, pageId, dataApplicableGrant, close,
+    isOpen, pageId, dataApplicableGrant, currentAndParentPageGrantData, close,
   } = props;
   } = props;
 
 
   const [selectedGrant, setSelectedGrant] = useState<PageGrant>(PageGrant.GRANT_OWNER);
   const [selectedGrant, setSelectedGrant] = useState<PageGrant>(PageGrant.GRANT_OWNER);
@@ -66,6 +66,42 @@ const FixPageGrantModal = (props: ModalProps): JSX.Element => {
     }
     }
   };
   };
 
 
+  const grantLabel = (isForbidden: boolean, grantData?: IPageGrantData): string => {
+
+    if (!isForbidden) {
+      return '権限の表示が許可されていません';
+    }
+
+    if (grantData == null) {
+      return '';
+    }
+
+    if (grantData.grant === 4) {
+      return t('fix_page_grant.modal.radio_btn.only_me');
+    }
+
+    if (grantData.grant === 5) {
+      if (grantData.grantedGroup == null) { return '' }
+      return `${t('fix_page_grant.modal.radio_btn.grant_group')}: (${grantData.grantedGroup.name})`;
+    }
+
+    return '';
+  };
+
+  const renderGrantDataLabel = () => {
+    const { isForbidden, currentPageGrant, parentPageGrant } = currentAndParentPageGrantData;
+
+    const currentGrantLabel = grantLabel(true, currentPageGrant);
+    const parentGrantLabel = grantLabel(isForbidden, parentPageGrant);
+
+    return (
+      <>
+        <p>親のページの権限: {parentGrantLabel}</p>
+        <p>このページの権限: {currentGrantLabel}</p>
+      </>
+    );
+  };
+
   const renderModalBodyAndFooter = () => {
   const renderModalBodyAndFooter = () => {
     const isGrantAvailable = Object.keys(dataApplicableGrant || {}).length > 0;
     const isGrantAvailable = Object.keys(dataApplicableGrant || {}).length > 0;
 
 
@@ -83,6 +119,10 @@ const FixPageGrantModal = (props: ModalProps): JSX.Element => {
           <div className="form-group">
           <div className="form-group">
             {/* eslint-disable-next-line react/no-danger */}
             {/* eslint-disable-next-line react/no-danger */}
             <p className="mb-2" dangerouslySetInnerHTML={{ __html: t('fix_page_grant.modal.need_to_fix_grant') }} />
             <p className="mb-2" dangerouslySetInnerHTML={{ __html: t('fix_page_grant.modal.need_to_fix_grant') }} />
+
+            {/* grant data label */}
+            {renderGrantDataLabel()}
+
             <div className="ml-2">
             <div className="ml-2">
               <div className="custom-control custom-radio mb-3">
               <div className="custom-control custom-radio mb-3">
                 <input
                 <input
@@ -195,7 +235,7 @@ const FixPageGrantAlert = (): JSX.Element => {
   if (!hasParent) {
   if (!hasParent) {
     return <></>;
     return <></>;
   }
   }
-  if (dataIsGrantNormalized?.grantData == null || dataIsGrantNormalized?.isGrantNormalized == null || dataIsGrantNormalized.isGrantNormalized) {
+  if (dataIsGrantNormalized?.isGrantNormalized == null || dataIsGrantNormalized.isGrantNormalized) {
     return <></>;
     return <></>;
   }
   }
 
 
@@ -219,7 +259,7 @@ const FixPageGrantAlert = (): JSX.Element => {
             isOpen={isOpen}
             isOpen={isOpen}
             pageId={pageId}
             pageId={pageId}
             dataApplicableGrant={dataApplicableGrant}
             dataApplicableGrant={dataApplicableGrant}
-            grantData={dataIsGrantNormalized.grantData}
+            currentAndParentPageGrantData={dataIsGrantNormalized.grantData}
             close={() => setOpen(false)}
             close={() => setOpen(false)}
           />
           />
         )
         )

+ 1 - 1
packages/app/src/interfaces/page-grant.ts

@@ -9,7 +9,7 @@ export type IRecordApplicableGrant = Record<PageGrant, IDataApplicableGrant>
 export type IResApplicableGrant = {
 export type IResApplicableGrant = {
   data?: IRecordApplicableGrant
   data?: IRecordApplicableGrant
 }
 }
-type IPageGrantData = {
+export type IPageGrantData = {
   grant: number,
   grant: number,
   grantedGroup?: {
   grantedGroup?: {
     id: string,
     id: string,

+ 1 - 1
packages/app/src/server/models/obsolete-page.js

@@ -375,7 +375,7 @@ export const getPageSchema = (crowi) => {
 
 
     const builder = new this.PageQueryBuilder(this.findOne({ path }), includeEmpty);
     const builder = new this.PageQueryBuilder(this.findOne({ path }), includeEmpty);
 
 
-    return builder.query.exec();
+    return builder.query;
   };
   };
 
 
   /**
   /**

+ 10 - 6
packages/app/src/server/routes/apiv3/page.js

@@ -2,6 +2,7 @@ import { pagePathUtils } from '@growi/core';
 
 
 import { AllSubscriptionStatusType } from '~/interfaces/subscription';
 import { AllSubscriptionStatusType } from '~/interfaces/subscription';
 import Subscription from '~/server/models/subscription';
 import Subscription from '~/server/models/subscription';
+import UserGroup from '~/server/models/user-group';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
 import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
 import { apiV3FormValidator } from '../../middlewares/apiv3-form-validator';
@@ -444,22 +445,25 @@ module.exports = (crowi) => {
       return res.apiv3Err(err, 500);
       return res.apiv3Err(err, 500);
     }
     }
 
 
+    const currentPageUserGroup = await UserGroup.findOne({ _id: grantedGroup });
+    const parentPageUserGroup = await UserGroup.findOne({ _id: parentPage.grantedGroup });
+
     const currentPageGrant = {
     const currentPageGrant = {
       grant,
       grant,
-      grantedGroup: grantedGroup != null
+      grantedGroup: currentPageUserGroup != null
         ? {
         ? {
-          id: grantedGroup._id,
-          name: grantedGroup.name,
+          id: currentPageUserGroup._id,
+          name: currentPageUserGroup.name,
         }
         }
         : null,
         : null,
     };
     };
 
 
     const parentPageGrant = {
     const parentPageGrant = {
       grant: parentPage.grant,
       grant: parentPage.grant,
-      grantedGroup: parentPage.grantedGroup != null
+      grantedGroup: parentPageUserGroup != null
         ? {
         ? {
-          id: parentPage.grantedGroup._id,
-          name: parentPage.grantedGroup.name,
+          id: parentPageUserGroup._id,
+          name: parentPageUserGroup.name,
         }
         }
         : null,
         : null,
     };
     };