Taichi Masuyama 4 лет назад
Родитель
Сommit
bf2e978568

+ 5 - 4
packages/app/src/server/models/page.ts

@@ -35,7 +35,7 @@ export interface PageDocument extends IPage, Document {}
 export interface PageModel extends Model<PageDocument> {
   createEmptyPagesByPaths(paths: string[]): Promise<void>
   getParentIdAndFillAncestors(path: string): Promise<string | null>
-  findByPathAndViewerV5(path: string | null, user, userGroups): Promise<IPage[]>
+  findByPathAndViewer(path: string | null, user, userGroups): Promise<IPage[]>
   findSiblingsByPathAndViewer(path: string | null, user, userGroups): Promise<IPage[]>
   findAncestorsById(path: string): Promise<IPage[]>
 }
@@ -173,7 +173,7 @@ const addViewerCondition = async(queryBuilder: PageQueryBuilder, user, userGroup
   queryBuilder.addConditionToFilteringByViewer(user, relatedUserGroups, true);
 };
 
-schema.statics.findByPathAndViewer = async function(path: string | null, user, userGroups, useFindOne = true): Promise<IPage[]> {
+schema.statics.findByPathAndViewer = async function(path: string | null, user, userGroups, useFindOne = true): Promise<IPage | IPage[] | null> {
   if (path == null) {
     throw new Error('path is required.');
   }
@@ -190,11 +190,12 @@ schema.statics.findSiblingsByPathAndViewer = async function(path: string | null,
     throw new Error('path is required.');
   }
 
-  const parentPath = nodePath.dirname(path);
+  const _parentPath = nodePath.dirname(path);
 
   // regexr.com/6889f
   // ex. /parent/any_child OR /any_level1
-  let regexp = new RegExp(`^${parentPath}(\\/[^/]+)\\/?$`, 'g');
+  const parentPath = isTopPage(_parentPath) ? '' : _parentPath;
+  let regexp = new RegExp(`^${parentPath}(\\/[^/]+)\\/?$`);
   // ex. / OR /any_level1
   if (isTopPage(path)) regexp = /^\/[^/]*$/g;
 

+ 2 - 2
packages/app/src/server/routes/apiv3/apiv3-response.ts

@@ -1,6 +1,6 @@
 import { Response } from 'express';
 
 export interface ApiV3Response extends Response {
-  apiv3?(obj?: any, status?: number): any
-  apiv3Err?(_err: any, status?: number, info?: any): any
+  apiv3(obj?: any, status?: number): any
+  apiv3Err(_err: any, status?: number, info?: any): any
 }

+ 6 - 1
packages/app/src/server/routes/apiv3/page-tree.ts

@@ -8,6 +8,7 @@ import ErrorV3 from '../../models/vo/error-apiv3';
 import loggerFactory from '../../../utils/logger';
 import Crowi from '../../crowi';
 import { ApiV3Response } from './apiv3-response';
+import { isTopPage } from '^/../core/dist/cjs/utils/page-path-utils';
 
 const logger = loggerFactory('growi:routes:apiv3:page-tree');
 
@@ -24,7 +25,7 @@ interface AuthorizedRequest extends Request {
 const validator = {
   getPagesAroundTarget: [
     query('id').isMongoId().withMessage('id is required'),
-    query('path').isMongoId().withMessage('path is required'),
+    query('path').isString().withMessage('path is required'),
   ],
 };
 
@@ -61,6 +62,10 @@ export default (crowi: Crowi): Router => {
       throw Error('Target must exist.');
     }
 
+    if (isTopPage(path as string)) {
+      siblings = siblings.filter(page => !isTopPage(page.path));
+    }
+
     return res.apiv3({ target, ancestors, pages: siblings });
   });