[GRDM-62315, 60282] mAP core グループ権限の対応漏れ / タイトルが長いプロジェクトでワークフローを開始できない の修正 - #776
Draft
yacchin1205 wants to merge 3 commits into
Draft
[GRDM-62315, 60282] mAP core グループ権限の対応漏れ / タイトルが長いプロジェクトでワークフローを開始できない の修正#776yacchin1205 wants to merge 3 commits into
yacchin1205 wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
mAP core グループ(#692)はノードの権限グループ(
node_<id>_admin/write/read)に紐づき、対応する権限レベルの Contributor と同等の権限を与える設計ですが、この設計が反映されていない箇所が2つ残っており、本PRで対応します。あわせて、同じくワークフローの開始を妨げる別の不具合(タイトルが長いプロジェクトで開始に失敗する)も修正します。ノード一覧 API の current_user_permissions がグループの権限を反映しない
グループを通じてプロジェクトの権限を持つユーザーの場合、ノード詳細 API の
current_user_permissionsには権限が正しく反映されますが、一覧 API(users/me/nodes/など)では空になります。このため、一覧 API の値を参照するクライアント(OASys のプロジェクト選択画面)では、ユーザーが write 権限を持つプロジェクトであっても権限なしとして扱われます。原因は、一覧 API が権限の算出に使う
optimize_node_querysetの annotation が、Django auth グループへの直接所属(osfuser_groups)だけを見ており、mAP core のメンバーシップ(osf_mapcore_user_group → osf_mapcore_node_group)を辿っていないためです。ノード単体の判定(has_permission/get_permissions)は対応済みで、一覧だけが未対応でした。workflow アドオンのアクセス判定がグループの権限を反映しない
グループ経由で権限を持つユーザーが workflow アドオンを使うと、ワークフローテンプレートの参照・開始に関わる API がいずれも 404 を返します。OASys ではプロジェクトを選択できるのに、ワークフローを開始できません。
原因は、テンプレート取得
_get_template_or_404/ エンジン取得_get_engine_or_404/ テンプレート一覧get_user_accessible_templatesの 3 箇所が Contributor かどうかで判定しており、グループの権限を考慮していないためです。タイトルが長いプロジェクトでワークフローを開始できない
ワークフロー開始時に発行する委任トークン(
ApiOAuth2PersonalToken)の名前を「Workflow delegation: ()」の形式で組み立てており、label にはプロジェクトタイトルを含む文字列が入ります。name カラムの max_length=100 を超えるとバリデーションエラーになるため、タイトルが長いプロジェクトではワークフローの開始に失敗します。Changes
get_permissions)と同じ結果を返すようにする(groups アドオンが無効なノードは対象外のまま)is_contributor_or_group_memberを、複数ノードにまたがる判定にはget_nodes_for_user(include_mapcore_groups=True)を使用build_token_nameを追加し、委任トークンの発行時に使用api_tests/users/views/test_user_nodes_mapcore_group_permissions.py(新規1件): 一覧 API のcurrent_user_permissionsが詳細 API と一致すること(修正前のコードでは失敗する)addons/workflow/tests/test_template_access.py(新規8件): アクセス判定が誰を許可し、誰を拒否するかをテストとして固定addons/workflow/tests/test_token.py(新規7件): トークン名が境界値・日本語ラベルを含めて 100 文字に収まることを確認QA Notes
Documentation
None
Side Effects
current_user_permissionsにグループ由来の権限が反映されるようになります(同上)Ticket