Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions apps/app/src/client/components/PageControls/PageControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
import {
isIPageInfoForEntity, isIPageInfoForOperation,
} from '@growi/core';
import { pagePathUtils } from '@growi/core/dist/utils';
import { useRect } from '@growi/ui/dist/utils';
import { useTranslation } from 'next-i18next';
import { DropdownItem } from 'reactstrap';
Expand All @@ -17,7 +18,9 @@ import {
} from '~/client/services/page-operation';
import { toastError } from '~/client/util/toastr';
import OpenDefaultAiAssistantButton from '~/features/openai/client/components/AiAssistant/OpenDefaultAiAssistantButton';
import { useIsGuestUser, useIsReadOnlyUser, useIsSearchPage } from '~/stores-universal/context';
import {
useIsGuestUser, useIsReadOnlyUser, useIsSearchPage, useIsUsersHomepageDeletionEnabled,
} from '~/stores-universal/context';
import {
EditorMode, useEditorMode,
} from '~/stores-universal/ui';
Expand All @@ -27,7 +30,7 @@ import {
} from '~/stores/ui';
import loggerFactory from '~/utils/logger';

import { useSWRxPageInfo, useSWRxTagsInfo } from '../../../stores/page';
import { useSWRxPageInfo, useSWRxTagsInfo, useCurrentPagePath } from '../../../stores/page';
import { useSWRxUsersList } from '../../../stores/user';
import type { AdditionalMenuItemsRendererProps, ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
import {
Expand Down Expand Up @@ -134,6 +137,10 @@ const PageControlsSubstance = (props: PageControlsSubstanceProps): JSX.Element =
const { data: editorMode } = useEditorMode();
const { data: isDeviceLargerThanMd } = useIsDeviceLargerThanMd();
const { data: isSearchPage } = useIsSearchPage();
const { data: isUsersHomepageDeletionEnabled } = useIsUsersHomepageDeletionEnabled();
const { data: currentPagePath } = useCurrentPagePath();

const isUsersHomepage = currentPagePath == null ? false : pagePathUtils.isUsersHomepage(currentPagePath);

const { mutate: mutatePageInfo } = useSWRxPageInfo(pageId, shareLinkId);

Expand Down Expand Up @@ -249,6 +256,22 @@ const PageControlsSubstance = (props: PageControlsSubstanceProps): JSX.Element =
}
}, [expandContentWidth, isGuestUser, isReadOnlyUser, onClickSwitchContentWidth, pageId, pageInfo]);

const isEnableActions = useMemo(() => {
if (isGuestUser) {
return false;
}

if (currentPagePath == null) {
return false;
}

if (isUsersHomepage && !isUsersHomepageDeletionEnabled) {
return false;
}

return true;
}, [isGuestUser, isUsersHomepage, isUsersHomepageDeletionEnabled]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentPagePath が取得できていない (null) 場合を考慮してください

以下 AI の説明


currentPagePath が取得できていない場合(=値が undefinednull の場合)、このコードでは以下のように記述されています:

const isUsersHomepage = pagePathUtils.isUsersHomepage(currentPagePath ?? '');

ここで currentPagePath ?? '' となっているため、currentPagePath が「null または undefined の場合」は空文字列 ''pagePathUtils.isUsersHomepage に渡されます。

どうなるか?

  • pagePathUtils.isUsersHomepage('') の返り値がどうなるか次第です。
  • 一般的に「ユーザーのホームページかどうか」を判定する関数なら、空文字列は「ユーザーのホームページではない」と判定され、false を返す設計が多いです。

結果として

  • currentPagePath が取得できていない場合、isUsersHomepage はたいてい false になる。
  • isEnableActions の値は
    • ゲストユーザーなら false
    • それ以外は trueisUsersHomepagefalse なので2番目の if に入らないため)

要約
currentPagePath が取得できていない場合は「ユーザーのホームページではない」とみなされ、isEnableActions の判定にも特に悪影響はありません(通常どおりの権限判定になります)。

Copy link
Contributor

@yuki-takei yuki-takei Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentPagePath はなにか、を本質的に考えないといけない

currentPagePath が取得できないということは、システムグローバルに「今何のページを表示しているのか」を特定できていないということだ。
現状のコードでは、今何のページを表示しているのかを特定できないにも関わらず、isEnableActions は true となり、PageItemControl の各種ドロップダウンアイテムを表示して良い、という挙動になる。
つまり、「何のページかわからんけど削除メニュー表示しとくね」という挙動が有り得ることになる。

修正案

currentPagePath が取得できていない場合は isEnableActions を false にする


const additionalMenuItemOnTopRenderer = useMemo(() => {
if (!isIPageInfoForEntity(pageInfo)) {
return undefined;
Expand Down Expand Up @@ -332,7 +355,7 @@ const PageControlsSubstance = (props: PageControlsSubstanceProps): JSX.Element =
<PageItemControl
pageId={pageId}
pageInfo={pageInfo}
isEnableActions={!isGuestUser}
isEnableActions={isEnableActions}
isReadOnlyUser={!!isReadOnlyUser}
forceHideMenuItems={forceHideMenuItemsWithAdditions}
additionalMenuItemOnTopRenderer={!isReadOnlyUser ? additionalMenuItemOnTopRenderer : undefined}
Expand Down
8 changes: 6 additions & 2 deletions apps/app/src/pages/[[...path]].page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
useIsLocalAccountRegistrationEnabled,
useIsRomUserAllowedToComment,
useIsPdfBulkExportEnabled,
useIsAiEnabled, useLimitLearnablePageCountPerAssistant,
useIsAiEnabled, useLimitLearnablePageCountPerAssistant, useIsUsersHomepageDeletionEnabled,
} from '~/stores-universal/context';
import { useEditingMarkdown } from '~/stores/editor';
import {
Expand Down Expand Up @@ -200,6 +200,7 @@ type Props = CommonProps & {

aiEnabled: boolean,
limitLearnablePageCountPerAssistant: number,
isUsersHomepageDeletionEnabled: boolean,
};

const Page: NextPageWithLayout<Props> = (props: Props) => {
Expand Down Expand Up @@ -258,6 +259,9 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
useIsAiEnabled(props.aiEnabled);
useLimitLearnablePageCountPerAssistant(props.limitLearnablePageCountPerAssistant);

useIsUsersHomepageDeletionEnabled(props.isUsersHomepageDeletionEnabled);


const { pageWithMeta } = props;

const pageId = pageWithMeta?.data._id;
Expand Down Expand Up @@ -576,7 +580,7 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P

props.aiEnabled = configManager.getConfig('app:aiEnabled');
props.limitLearnablePageCountPerAssistant = configManager.getConfig('openai:limitLearnablePageCountPerAssistant');

props.isUsersHomepageDeletionEnabled = configManager.getConfig('security:user-homepage-deletion:isEnabled');
props.isSearchServiceConfigured = searchService.isConfigured;
props.isSearchServiceReachable = searchService.isReachable;
props.isSearchScopeChildrenAsDefault = configManager.getConfig('customize:isSearchScopeChildrenAsDefault');
Expand Down
6 changes: 6 additions & 0 deletions apps/app/src/stores-universal/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,14 @@ export const useLimitLearnablePageCountPerAssistant = (initialData?: number): SW
return useContextSWR('limitLearnablePageCountPerAssistant', initialData);
};


export const useIsUsersHomepageDeletionEnabled = (initialData?: boolean): SWRResponse<boolean, false> => {
return useContextSWR('isUsersHomepageDeletionEnabled', initialData);
};

export const useIsEnableUnifiedMergeView = (initialData?: boolean): SWRResponse<boolean, Error> => {
return useSWRStatic<boolean, Error>('isEnableUnifiedMergeView', initialData, { fallbackData: false });

};

/** **********************************************************
Expand Down
Loading