Repository navigation
fix(weko-gridlayout): ウィジェットのアップロードファイルを未ログインでも取得できるようにする - #1937
Conversation
facd5ab で /widget/uploaded/<filename>[/<community_id>] (uploaded_file) に System/Repository/Community Administrator のロール必須が付いた。この URL は ウィジェットに埋め込んだ画像などを公開ページのブラウザが直接読み込むもの (WidgetBucket.save_file が返す URL) なので、未ログインでは 401、一般ユーザでは 403 になり、公開ページのウィジェット画像が表示されなくなっていた。 - uploaded_file のロール必須を外す。load_widget_type (管理画面の ウィジェット作成でだけ使う) は管理者限定のまま - test_uploaded_file が同名で2つ定義され、後の定義が前を上書きしていたので、 未ログイン・各ロールで取得できることを確かめる1つのテストにまとめる - test_load_widget_type が users[id]['obj'] でログインしていたため、 users[4] (generaluser) の obj が sysadmin になっている fixture では システム管理者としてログインし、403 の確認が失敗していた。email で ログインするように直す Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideThis PR fixes the regression that prevented public pages from loading widget-uploaded assets by removing authentication requirements from the file-serving GET endpoint, while preserving admin-only widget-type loading and strengthening authorization regression tests. The module test suite passed with 329 tests passed and 3 expected failures. Sequence diagram for public widget asset loadingsequenceDiagram
actor Visitor
participant Browser
participant UploadedFile as uploaded_file
participant WidgetBucket
Visitor->>Browser: Open public page
Browser->>UploadedFile: GET /widget/uploaded/filename/community_id
UploadedFile->>WidgetBucket: Read widget asset
WidgetBucket-->>UploadedFile: File contents
UploadedFile-->>Browser: 200 asset response
Browser-->>Visitor: Display widget asset
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Sourcery assessment
Needs a human reviewer. This removes the authorization check from a file-download endpoint, making every uploaded widget file reachable by unauthenticated callers who can guess or obtain its filename and community ID. Reverting stops future unauthenticated access, but any files already exposed or downloaded cannot be recovered; the access-policy change is also wrong for everyone immediately if these uploads were not all intended to be public.
API インベントリ差分(件数のみ)
ベースラインとの差分(生成されませんでした) 台帳との突き合わせ(生成されませんでした) ソース由来の経路検知(生成されませんでした) |
概要 (Summary)
develop_v2.1.0 では、ウィジェット経由でアップロードした画像などが、公開ページで未ログインの利用者や一般ユーザに表示されない。
/widget/uploaded/<filename>[/<community_id>](weko_gridlayout.views.uploaded_file)に、System/Repository/Community Administrator のロールを必須とする@roles_requiredが付いた。WidgetBucket.save_fileが返すもの。ウィジェット(自由記述など)に埋め込まれ、公開ページでブラウザが直接読み込む。変更内容
uploaded_file:ロールの必須化を外し、未ログインでも取得できる元の挙動に戻す。docstring に理由を書いた。load_widget_type(/api/admin/load_widget_type):facd5abf7 で管理者に限定された。管理画面のウィジェット作成でだけ使う API なので、限定は残す。test_uploaded_fileが同じ名前で2つ定義されていて、後の定義が前を上書きしていた。そのため、ロールごとの判定を確かめるテストは実際には実行されていなかった。これを1つにまとめ、未ログイン・各管理者ロール・Contributor・ロールの無いユーザが、Root Indexと通常のコミュニティの両方で 200 になることを確認する。1セグメントの URL(/widget/uploaded/<filename>)も確認する。test_load_widget_typeはusers[id]['obj']でログインしていた。users フィクスチャではusers[4](generaluser)のobjが sysadmin になっているため、実際にはシステム管理者としてログインし、403 を期待した確認が失敗していた(develop_v2.1.0 でも失敗する)。ほかのテストと同じくemailでログインするように直した。関連Issue / チケット (Related Issues)
変更タイプ (Type of Change)
🤖 0. CI 自動チェック (API Inventory Drift)
API を追加・変更した場合(必須)
api_snapshot.jsonを更新し、対応する PR を出した/widget/uploaded/...の2行)を更新した🔒 1. セキュリティ & API アクセス制御チェック (必須)
uploaded_fileは公開ページの静的ファイル配信なので、認証は付けない(facd5abf7 より前の挙動)。load_widget_typeの管理者限定は維持している。/widget/uploads/...)は変更していない。🧪 2. テストコード観点チェック
uploaded_fileは未ログインで 200(公開配信が仕様)であることをテストで確認した。load_widget_typeは、管理者ロールの無いユーザ(Contributor、General)で 403 になることを確認した(ログイン方法を直したテスト)。🛡️ 3. データ保護 & 破壊的変更防止チェック
対象外(データの書き込みに変更はない)。
⚙️ 4. マイグレーション & システム影響チェック
対象外(DB・検索インデックス・設定に変更はない)。
📚 5. ドキュメント・仕様書更新チェック (weko-document)
📋 6. 動作検証エビデンス (Verification Evidence)
CI と同じ手順(
scripts/ci/run-module-tests.sh、docker-compose2.yml:docker-compose.ci.yml)で weko-gridlayout のテストを実行した。手元で動いていた別の WEKO スタックとホストのポートがぶつかるため、サービスはホストにポートを公開しない設定で起動している。実行環境は aarch64。test_uploaded_file:12ケースとtest_uploaded_file_without_communityがすべて PASSED。test_load_widget_type:[0-403] [1-200] [2-200] [3-200] [4-403]がすべて PASSED。修正前は[4-403]が失敗していた。🤖 Generated with Claude Code
Summary by Sourcery
Restore anonymous access to widget-uploaded files while retaining administrator-only access for widget type loading.
Bug Fixes:
Tests: