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

refactor: replace USER_PAGE_REGEXP with isUserPage and isUsersTopPage functions for bookmark filtering

Shun Miyazawa 2 месяцев назад
Родитель
Сommit
3d7fdf1363

+ 7 - 2
apps/app/src/server/routes/apiv3/bookmarks.ts

@@ -1,7 +1,10 @@
 import type { IUserHasId } from '@growi/core';
 import { SCOPE } from '@growi/core/dist/interfaces';
 import { serializeUserSecurely } from '@growi/core/dist/models/serializers';
-import { USER_PAGE_REGEXP } from '@growi/core/dist/utils/page-path-utils';
+import {
+  isUserPage,
+  isUsersTopPage,
+} from '@growi/core/dist/utils/page-path-utils';
 import mongoose, { type HydratedDocument } from 'mongoose';
 
 import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
@@ -260,7 +263,9 @@ module.exports = (crowi) => {
 
         const filteredBookmarks = isHidingUserPages
           ? userRootBookmarks.filter(
-              (bookmark) => !USER_PAGE_REGEXP.test(bookmark.page.path),
+              (bookmark) =>
+                !isUserPage(bookmark.page.path) &&
+                !isUsersTopPage(bookmark.page.path),
             )
           : userRootBookmarks;
 

+ 2 - 7
packages/core/src/utils/page-path-utils/index.ts

@@ -8,12 +8,6 @@ export const isTopPage = _isTopPage;
 
 export * from './generate-children-regexp';
 
-/**
- * Regexp pattern for user page path
- * @see https://regex101.com/r/MwifLR/1
- */
-export const USER_PAGE_REGEXP = /^\/user\/.*?$/;
-
 /**
  * Whether path is the top page of users
  * @param path
@@ -64,7 +58,8 @@ export const isMovablePage = (path: string): boolean => {
  * @param path
  */
 export const isUserPage = (path: string): boolean => {
-  if (path.match(USER_PAGE_REGEXP)) {
+  // https://regex101.com/r/MwifLR/1
+  if (path.match(/^\/user\/.*?$/)) {
     return true;
   }