Просмотр исходного кода

Refactor AuthorizedRequest interface and update /info route logic to handle guest users

Shun Miyazawa 8 месяцев назад
Родитель
Сommit
19f7f3408f
1 измененных файлов с 6 добавлено и 4 удалено
  1. 6 4
      apps/app/src/server/routes/apiv3/page-listing.ts

+ 6 - 4
apps/app/src/server/routes/apiv3/page-listing.ts

@@ -1,5 +1,5 @@
 import type {
 import type {
-  IPageInfoForListing, IPageInfo, IPage,
+  IPageInfoForListing, IPageInfo, IPage, IUserHasId,
 } from '@growi/core';
 } from '@growi/core';
 import { getIdForRef, isIPageInfoForEntity } from '@growi/core';
 import { getIdForRef, isIPageInfoForEntity } from '@growi/core';
 import { ErrorV3 } from '@growi/core/dist/models';
 import { ErrorV3 } from '@growi/core/dist/models';
@@ -27,7 +27,7 @@ const logger = loggerFactory('growi:routes:apiv3:page-tree');
  * Types & Interfaces
  * Types & Interfaces
  */
  */
 interface AuthorizedRequest extends Request {
 interface AuthorizedRequest extends Request {
-  user?: any
+  user?: IUserHasId,
 }
 }
 
 
 /*
 /*
@@ -267,7 +267,7 @@ const routerFactory = (crowi: Crowi): Router => {
    *                 $ref: '#/components/schemas/PageInfoAll'
    *                 $ref: '#/components/schemas/PageInfoAll'
    */
    */
   // eslint-disable-next-line max-len
   // eslint-disable-next-line max-len
-  router.get('/info', accessTokenParser, loginRequired, validator.pageIdsOrPathRequired, validator.infoParams, apiV3FormValidator, async(req: AuthorizedRequest, res: ApiV3Response) => {
+  router.get('/info', accessTokenParser, validator.pageIdsOrPathRequired, validator.infoParams, apiV3FormValidator, async(req: AuthorizedRequest, res: ApiV3Response) => {
     const {
     const {
       pageIds, path, attachBookmarkCount: attachBookmarkCountParam, attachShortBody: attachShortBodyParam,
       pageIds, path, attachBookmarkCount: attachBookmarkCountParam, attachShortBody: attachShortBodyParam,
     } = req.query;
     } = req.query;
@@ -304,7 +304,9 @@ const routerFactory = (crowi: Crowi): Router => {
 
 
       const isGuestUser = req.user == null;
       const isGuestUser = req.user == null;
 
 
-      const userRelatedGroups = await pageGrantService.getUserRelatedGroups(req.user);
+      const userRelatedGroups = isGuestUser
+        ? []
+        : await pageGrantService.getUserRelatedGroups(req.user);
 
 
       for (const page of pages) {
       for (const page of pages) {
         // construct isIPageInfoForListing
         // construct isIPageInfoForListing