Przeglądaj źródła

fix not found and forbidden logic for API

Yuki Takei 5 miesięcy temu
rodzic
commit
9042e585c3

+ 1 - 1
apps/app/src/server/routes/apiv3/page/index.ts

@@ -215,7 +215,7 @@ module.exports = (crowi: Crowi) => {
       const { meta } = pageWithMeta;
       const { meta } = pageWithMeta;
 
 
       // not found or forbidden
       // not found or forbidden
-      if (page == null && (pages == null || pages.length === 0)) {
+      if (isIPageNotFoundInfo(meta) || (Array.isArray(pages) && pages.length === 0)) {
         if (isIPageNotFoundInfo(meta) && meta.isForbidden) {
         if (isIPageNotFoundInfo(meta) && meta.isForbidden) {
           return res.apiv3Err(new ErrorV3('Page is forbidden', 'page-is-forbidden', undefined, meta), 403);
           return res.apiv3Err(new ErrorV3('Page is forbidden', 'page-is-forbidden', undefined, meta), 403);
         }
         }

+ 2 - 2
packages/core/src/interfaces/page.ts

@@ -86,6 +86,7 @@ export type IPageHasId = IPage & HasObjectId;
 export type IPageNotFoundInfo = {
 export type IPageNotFoundInfo = {
   isNotFound: true;
   isNotFound: true;
   isForbidden: boolean;
   isForbidden: boolean;
+  isEmpty?: true;
 };
 };
 
 
 export type IPageInfo = {
 export type IPageInfo = {
@@ -132,8 +133,7 @@ export const isIPageNotFoundInfo = (
   return (
   return (
     pageInfo != null &&
     pageInfo != null &&
     pageInfo instanceof Object &&
     pageInfo instanceof Object &&
-    pageInfo.isNotFound === true &&
-    !('isEmpty' in pageInfo)
+    pageInfo.isNotFound === true
   );
   );
 };
 };