Skip to content

給付金コースユーザーが通常コースのプラクティスの提出物を提出できないようにする#10224

Open
zecky1120 wants to merge 13 commits into
mainfrom
feature/prevent-students-in-Reskill-course-from-submitting-regular-practice-assignments
Open

給付金コースユーザーが通常コースのプラクティスの提出物を提出できないようにする#10224
zecky1120 wants to merge 13 commits into
mainfrom
feature/prevent-students-in-Reskill-course-from-submitting-regular-practice-assignments

Conversation

@zecky1120

@zecky1120 zecky1120 commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Issue

概要

給付金コースユーザーが通常コースのプラクティスに提出させないようにする間違いをなくしたい。
通常プラクティスに移動したら、

  • 提出物作成のボタンをクリックできないようにし、給付金コースへ遷移するボタンを配置する。
  • ステータスの箇所を給付金コースへ遷移するボタンを配置する。

変更確認方法

  1. feature/prevent-students-in-Reskill-course-from-submitting-regular-practice-assignmentsをローカルに取り込む
  2. grant-courseでログインする
  3. rubyをインストールするに移動する
  4. 大見出しの上部に「元プラクティス」「給付金コース」というボタンが設置されているか確認する
  5. 「元プラクティス」ボタンをクリックする
  6. 「給付金コースに移動する」ボタンと「進捗のステータス変更は、給付金コースのプラクティス側で行ってください。」というテキストが2箇所に設置されているか確認する
  7. 「給付金コース」ボタンをクリックする
  8. 進捗のステータスと修了ボタンがあるか確認する

Screenshot

変更前

6f97d81d-83ba-4c04-b381-ca8ae9272866

変更後

e390c201-c8c7-4cb7-a094-1754ea2ba1b4 2ef801b3-48c6-473c-8bf5-b3e21e1d2fe9

Summary by CodeRabbit

リリースノート

  • 改善
    • 給付金コース対象の学習ページで、「先頭アクション」やガイダンス文言を条件に応じて切り替えました。
    • 給付金コース対象では「給付金コースへ移動する」リンクと注意文を表示し、通常のステータスボタンや提出物なしの文言は抑止します(非対象・対象ページでも表示を整理)。
  • テスト
    • 給付金コース/非対象それぞれでの表示内容を確認するシステムテストを追加しました。

Flakewatch Report

Flakewatch Report

Review App

@zecky1120 zecky1120 self-assigned this Jun 21, 2026
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

給付金コース向けの判定メソッドを追加し、学習画面とプラクティス詳細画面の案内表示を条件分岐化しました。給付金コースユーザー、通常ユーザー、元プラクティスの表示差分を検証するシステムテストも追加されています。

Changes

給付金コース向け表示分岐

Layer / File(s) Summary
給付金コース判定メソッド追加
app/models/practice.rb
guide_to_grant_course?(user) を追加し、user.grant_course?source_id の条件で判定するようにした。
学習画面の案内切り替え
app/components/learnings/learning_component.html.slim, app/views/practices/_learning-status.html.slim
給付金コース誘導時は移動リンクと注記を表示し、それ以外は従来のアクションボタンやステータスボタンを表示するようにした。
詳細画面の案内条件更新
app/views/practices/show.html.slim
給付金コース誘導対象では提出関連の案内を表示しないようにした。
システムテスト追加
test/system/practices_test.rb
給付金コースユーザー、通常ユーザー、元プラクティス、給付金コースプラクティスの表示分岐を検証するテストを追加した。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant PracticeView
  participant Practice
  User->>PracticeView: プラクティスを表示
  PracticeView->>Practice: guide_to_grant_course?(current_user)
  Practice-->>PracticeView: true / false
  PracticeView-->>User: 誘導リンクまたは通常の進捗操作を表示
Loading

Possibly related PRs

  • fjordllc/bootcamp#9821: show.html.slim で給付金コースおよび元プラクティスの表示を条件分岐している点が共通しています。

Suggested reviewers: machida, zamami

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 主変更である給付金コースユーザー向けの通常コース制御を端的に表しており、内容とも整合しています。
Description check ✅ Passed Issue、概要、変更確認方法、Screenshot の各項目がそろっており、テンプレート要件を概ね満たしています。
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/prevent-students-in-Reskill-course-from-submitting-regular-practice-assignments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/components/learnings/learning_component.html.slim`:
- Line 5: The `@practice.copied_practices.first` call in the link_to on line 5
is unreliable because it arbitrarily picks the first copied practice without
considering business logic. Create a dedicated method in the Practice model that
resolves the correct copied practice based on user and course relationships,
then replace `@practice.copied_practices.first` with a call to this new method.
Apply this same method consistently in both templates to ensure stable
navigation.

In `@app/views/practices/_learning-status.html.slim`:
- Around line 12-14: The `li.practice-status-buttons__item` element and its
child button declaration are over-indented, creating a nested `li > li`
structure instead of the intended `ul > li` sibling structure. Reduce the
indentation of lines 12-14 (the li element with class
practice-status-buttons__item, the button_class assignment, and the content_tag
button call) by one indentation level so they align as siblings within the ul
container rather than nesting under the previous li element.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 99c22b21-d0da-4672-b24a-398a02b7c0a1

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbd2ea and 6e68c55.

📒 Files selected for processing (2)
  • app/components/learnings/learning_component.html.slim
  • app/views/practices/_learning-status.html.slim

Comment thread app/components/learnings/learning_component.html.slim Outdated
Comment thread app/views/practices/_learning-status.html.slim Outdated
@zecky1120 zecky1120 force-pushed the feature/prevent-students-in-Reskill-course-from-submitting-regular-practice-assignments branch from 88963be to 5d49580 Compare June 21, 2026 13:52
@zecky1120

Copy link
Copy Markdown
Contributor Author

@machida
お疲れ様です! 本PRのデザインをお願いします!

@machida

machida commented Jul 1, 2026

Copy link
Copy Markdown
Member

@zecky1120 お待たせしました!デザイン入れましたー

@zecky1120

Copy link
Copy Markdown
Contributor Author

@machida
ありがとうございました! 確認できました〜🙏

@zecky1120 zecky1120 marked this pull request as ready for review July 2, 2026 11:48
@github-actions github-actions Bot requested a review from okuramasafumi July 2, 2026 11:48
@zecky1120

Copy link
Copy Markdown
Contributor Author

@zamami
お疲れ様です! レビュー依頼をお願いしたいのですが可能でしょうか。
難しければ遠慮せず言ってください〜🥹

@zamami

zamami commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

@zecky1120
レビュー依頼ありがとうございます!
すぐにお返しできると思いますので少々お待ちください💪

@zecky1120 zecky1120 requested a review from zamami July 3, 2026 12:50
@zecky1120

Copy link
Copy Markdown
Contributor Author

@zamami
ありがとうございます! お手隙の時にOKです〜👌

@zamami zamami left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@zecky1120

今回、条件式で
@current_user.grant_course?
@practice.source_id.blank?

を使って給付金コースのページへ誘導するかを判定しているので、
guide_to_grant_course?(user)みたいなメソッドをmodels/practice.rbに作ることで他のファイルの条件式で||!を使わずに済むかなと思いました。



あとは、テストも他の条件式も追加するといいなと思いました。(回帰テスト)
コメントしてみたので参考にしてみてください。

私の方ではapproveとさせていただきます!

Comment thread app/components/learnings/learning_component.html.slim Outdated
Comment thread app/views/practices/_learning-status.html.slim Outdated
Comment thread app/views/practices/show.html.slim Outdated
Comment thread app/views/practices/show.html.slim Outdated
assert_no_text 'このプラクティスを修了にしてください。'
assert_no_text 'このプラクティスに提出物はありません。'
assert_no_text '修了条件をクリアしたら修了にしてください。'
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

今回、条件分岐が入ったので以下の2つの条件の場合のテストも追加するといいなと思いました。

・通常ユーザーが元プラクティスの画面を開いた場合
・給付金受給ユーザーがコピー元のプラクティスの画面を開いた場合

# 通常ユーザーが元プラクティスを開くと、給付金への誘導が出ず、通常のステータスボタン群が表示される
  test 'show normal status buttons on source practice for non grant course user' do
    source_practice = practices(:practice23)

    visit_with_auth practice_path(source_practice), 'kimura'

    assert_selector '.practice-status-buttons__start'
    assert_no_link '給付金コースへ移動する'
    assert_no_text '進捗のステータス変更は、給付金コースのプラクティス側で行ってください。'
    assert_no_text '提出・修了は、給付金コースのプラクティス側で行ってください。'
  end

# 給付金ユーザーがコピー側のプラクティスを開くと、誘導が出ず、通常のステータスボタン群が表示される
  test 'show normal status buttons on grant course practice for grant course user' do
    grant_course_practice = practices(:practice64)

    visit_with_auth practice_path(grant_course_practice), 'grant-course'

    assert_selector '.practice-status-buttons__start'
    assert_no_link '給付金コースへ移動する'
    assert_no_text '進捗のステータス変更は、給付金コースのプラクティス側で行ってください。'
  end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

画面でも確認もOKですー!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
app/models/practice.rb (1)

214-217: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

既存の grant_course? を再利用できます。

source_id.blank? は既存の grant_course?(Line 210-212)の否定と等価です。重複ロジックを避けるため再利用を検討してください。

♻️ 提案する差分
 def guide_to_grant_course?(user)
-  user.grant_course? && source_id.blank?
+  user.grant_course? && !grant_course?
 end
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/models/practice.rb` around lines 214 - 217, The guide_to_grant_course?
predicate duplicates logic by checking source_id.blank? directly; reuse the
existing grant_course? method instead of repeating the blank check. Update
guide_to_grant_course?(user) in Practice to express the same condition through
grant_course? combined with user.grant_course?, keeping the logic centralized
and consistent.
app/views/practices/_learning-status.html.slim (1)

3-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

共通パーシャル化の検討。

給付金コース誘導ブロック(リンク+注記)は learning_component.html.slim とほぼ同一構造で重複しています。文言(注記テキスト)だけが異なるため、テキストを引数化した共通パーシャルに切り出すと、今回のような二重ネストの取りこぼしを防ぎやすくなります。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/views/practices/_learning-status.html.slim` around lines 3 - 9, The
grant-course guidance block in the learning status view is duplicated with the
similar block in learning_component, with only the note text differing. Extract
the shared link-and-note UI into a common partial or helper, and make the note
text configurable so both call sites can reuse it. Use the existing
guide_to_grant_course? guard and the practice-status-buttons__grant-guidance /
practice-status-buttons__grant-link / practice-status-buttons__grant-note
structure to keep the behavior and styling consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/models/practice.rb`:
- Around line 214-217: Add unit coverage for Practice#guide_to_grant_course? in
the Practice model test file by exercising both inputs the method depends on: a
case where user.grant_course? is true and source_id is blank, and at least one
contrasting case where either user.grant_course? is false or source_id is
present. Use the guide_to_grant_course? method name in test setup/assertions so
the behavior stays tied to the existing predicate.

---

Nitpick comments:
In `@app/models/practice.rb`:
- Around line 214-217: The guide_to_grant_course? predicate duplicates logic by
checking source_id.blank? directly; reuse the existing grant_course? method
instead of repeating the blank check. Update guide_to_grant_course?(user) in
Practice to express the same condition through grant_course? combined with
user.grant_course?, keeping the logic centralized and consistent.

In `@app/views/practices/_learning-status.html.slim`:
- Around line 3-9: The grant-course guidance block in the learning status view
is duplicated with the similar block in learning_component, with only the note
text differing. Extract the shared link-and-note UI into a common partial or
helper, and make the note text configurable so both call sites can reuse it. Use
the existing guide_to_grant_course? guard and the
practice-status-buttons__grant-guidance / practice-status-buttons__grant-link /
practice-status-buttons__grant-note structure to keep the behavior and styling
consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a43ff6cb-888e-466e-88be-002026a03fbc

📥 Commits

Reviewing files that changed from the base of the PR and between a8f288a and f84ac5c.

📒 Files selected for processing (5)
  • app/components/learnings/learning_component.html.slim
  • app/models/practice.rb
  • app/views/practices/_learning-status.html.slim
  • app/views/practices/show.html.slim
  • test/system/practices_test.rb

Comment thread app/models/practice.rb
@zecky1120

Copy link
Copy Markdown
Contributor Author

@zamami
レビューありがとうございました! 一点こちら のご指摘に関してunless ~ elseだとRubocopに怒られてしまうので、

  - if @practice.guide_to_grant_course?(current_user)
...
          | 給付金コースへ移動する
        .practice-status-buttons__note.practice-status-buttons__grant-note
          | 進捗のステータス変更は、給付金コースのプラクティス側で行ってください。
  - else
    .practice-status-buttons__start
      .practice-status-buttons__label
        | ステータス
      ul.practice-status-buttons__items.is-button-group
...

通常のif ~ elseにして対応させていただきました🙇‍♂️

@okuramasafumi
お疲れ様です! こちらのPRですが、FBC生とのレビューが終わりましたのでメンターレビューをお願いします!🙏

@zamami

zamami commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@zecky1120
rubocop確認してませんでした💦
確認ありがとうございます!💪

Comment thread app/views/practices/show.html.slim Outdated
br
| このプラクティスを修了にしてください。
- else
- elsif !@practice.guide_to_grant_course?(current_user)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

既存のelse節を上書きしているため、else節が存在しない状態になっています。
!@practice.guide_to_grant_course?(current_user)falseであるとき(@practice.guide_to_grant_course?(current_user)trueであるとき)、上のif文はtrue_or_false && falseで常にfalse、このelsiffalseになるため、else節があればそちらに処理が移りますが、ないため何も起きなくなっています(具体的には、「このプラクティスに提出物はありません。」の文言が表示されません)。
字面だけでいっても、@practice.guide_to_grant_course?(current_user)trueであることは普通にありそうです。仕様の再確認をお願いします。


もしかしたら今の仕様でよいのかもしれませんが、一般に、else節はつけるべきだとされています(例としては https://docs.rubocop.org/rubocop/latest/cops_style.html#stylemissingelse)。`else`節に処理が来ることは往々にしてありますし、ありえない場合は`else raise`的に例外を上げるようにして「ここにこないことは検討済み」とコード上で示せるので有用な場合があります。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@okuramasafumi
ご確認いただきありがとうございました!
ご指摘いただいた箇所ですが、else文に戻してその中に条件分岐(unless文)にして対応させていただきました〜🙏

@okuramasafumi okuramasafumi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

わかりやすくなったと思います、LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants