Skip to content

Conversation

@arvid-e
Copy link
Contributor

@arvid-e arvid-e commented Dec 24, 2025

https://redmine.weseek.co.jp/issues/174756

Block viewing of other user's pages when hiding user pages

@arvid-e arvid-e requested a review from yuki-takei December 24, 2025 08:38
…-visibility-in-pagetree

feat: User pages gets hidden from in the page tree when the user page visibility is set to hide
@arvid-e arvid-e force-pushed the feat/174756-block-viewing-other-user-pages branch from 5a898a4 to 81d11a0 Compare December 25, 2025 04:42
Copy link
Contributor

Choose a reason for hiding this comment

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

サービス層ではなく route でやりましょう

@arvid-e arvid-e requested a review from yuki-takei January 5, 2026 06:40
@yuki-takei
Copy link
Contributor

現状の実装

  • middleware として実装している
  • 欠点:
    • アクセスごとに DB からのページデータ取得が1回多くなる
    • PageRedirect document が存在する場合に対応できていない
    • req.url = /404_${Math.random().toString(36).substring(7)}; という URL 書き換えの挙動は、ユーザーから見るとなぜこうなるのか理解しがたい

改修案

  1. API route 向け実装
    • 各 API で、取得したページデータの path を使って判定する
    • PageRedirect document が存在する場合については対応しない
  2. Next.js route 向け実装
    • getServerSidePropsForInitial および getServerSidePropsForSameRoute 内で取得したページデータの path を使って判定する
      • これは PageRedirect document の存在に対応している

判定についてのヒント

ユーザーページの判定

import { isUserPage } from '@growi/core/dist/utils/page-path-utils';

必要であれば、同パッケージから isUsersTopPage, isUsersHomepage, isUsersProtectedPages などを利用できる

API path の判定

API path かどうかは、login-required.js の以下の判定を参考にする

    // is api path
    const baseUrl = req.baseUrl || '';
    if (baseUrl.match(/^\/_api\/.+$/)) {
        ...
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

v7.3 ベースのコードのように見える

master ブランチからの乖離が激しいので follow してから再実装してください

@arvid-e arvid-e force-pushed the feat/174756-block-viewing-other-user-pages branch from a9236ca to dc1954e Compare January 7, 2026 06:24
@arvid-e arvid-e requested a review from yuki-takei January 7, 2026 06:38
user?: IUser,
showPagesRestrictedByOwner?: boolean,
showPagesRestrictedByGroup?: boolean,
hideUserPages?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

この行は不要ではないか?

if (isTargetUserPage) return false;

return true;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

この filter もうちょっとシンプルに書ける

});
}

if (pages.length === 0 && path != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

path != null という条件はなんのために必要なんだっけ?

@arvid-e arvid-e force-pushed the feat/175627-admin-can-hide-user-pages branch from fc136ec to 464f9d3 Compare January 13, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants