Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

プラクティス、コース、カテゴリーの編集権限を管理者からメンターに移行する #6344

Conversation

mono-nobe
Copy link
Contributor

@mono-nobe mono-nobe commented Mar 21, 2023

Issue

概要

プラクティス、コース、カテゴリーの編集権限を管理者からメンター(管理ページからメンターページ)に移行しました。
また、管理ページから上記項目を削除しました。

変更確認方法

  1. feature/grant-edit-permission-to-mentor-for-categories-courses-practices をローカルに取り込む
  2. mentormentaroでログインする
  3. ヘッダーからメンターページに移動する

スクリーンショット 2023-03-21 16 53 14

  1. プラクティス、コース、カテゴリーのタブがあることを確認する
  2. プラクティスページについて、以下の内容を確認する
    • プラクティス一覧が表示されている
    • 以下のリンクが正常に動作している
      • プラクティス
      • 所属カテゴリー
      • 提出物
      • 日報
      • Q&A
      • 編集
    • プラクティスを編集できる
  3. カテゴリーページについて、以下の内容を確認する
    • カテゴリー一覧が表示されている
    • 以下のリンクが正常に動作している
      • 名前
      • 操作
    • カテゴリーを作成できる
    • カテゴリーを編集できる
    • カテゴリーを削除できる
  4. コースページについて、以下の内容を確認する
    • コース一覧が表示されている
    • 以下のリンクが正常に動作している
      • コース名
      • 操作
        • 編集
        • 並び替え
    • コースを作成できる
    • コースを編集できる
    • コースを並び替えられる
      • 具体的な操作については後述します
    • プラクティスを並び替えられる
      • 具体的な操作については後述します
    • プラクティスを作成できる
  5. komagataでログインする
  6. ヘッダーから管理ページに移動する

スクリーンショット 2023-03-21 16 53 34

  1. プラクティス、コース、カテゴリーのタブが存在しないことを確認する

コースを並び替える操作

  1. メンターページへ移動する
    • 上記の手順3まで同じ
  2. コースタブをクリックする

スクリーンショット 2023-05-19 22 54 56

  1. 操作列のハンバーガーメニューをクリックし、カテゴリー並び替え画面へ移動する

スクリーンショット 2023-05-19 22 54 56

  1. 並び替えたいレコードの並び順カラムを上下にドラッグすることで、レコードを並び替える
    • 保存ボタンはなく、上記操作で自動的に並び順が保存される

スクリーンショット 2023-05-19 22 57 31

プラクティスを並び替える操作

  1. メンターページのコースタブをクリックする
    • コースを並び替える手順2まで同じ
  2. 適当なコースをクリックする

スクリーンショット 2023-05-19 23 13 29

  1. 順番変更ボタンをクリックし、並び替えモードにする

スクリーンショット 2023-05-19 23 15 14
スクリーンショット 2023-05-19 23 15 55

  1. 並び替えたいレコードのハンバーガーメニューをドラッグすることで、レコードを並び替える

スクリーンショット 2023-05-19 23 15 55

  1. 変更完了ボタンをクリックし、変更内容を保存する

スクリーンショット 2023-05-19 23 18 22

Screenshot

変更前

メンターページ

プラクティス、コース、カテゴリーのタブが存在しない

スクリーンショット 2023-03-21 17 00 38

管理ページ

プラクティス、コース、カテゴリーのタブが存在する

スクリーンショット 2023-03-21 16 57 12

変更後

メンターページ

プラクティス、コース、カテゴリーのタブが存在する

スクリーンショット 2023-03-21 16 56 47

管理ページ

プラクティス、コース、カテゴリーのタブが存在しない

スクリーンショット 2023-03-21 17 47 03

@mono-nobe mono-nobe self-assigned this Mar 21, 2023
@mono-nobe mono-nobe force-pushed the feature/grant-edit-permission-to-mentor-for-categories-courses-practices branch 2 times, most recently from cb05234 to 67d5207 Compare March 21, 2023 16:19
@mono-nobe mono-nobe marked this pull request as ready for review March 29, 2023 13:56
@mono-nobe
Copy link
Contributor Author

@wata00913
お疲れ様です!
もしご都合よろしければ、こちらレビューいただけないでしょうか?
差分がかなり多いため、PRの内容含め疑問点あればお気軽にご質問ください 🙇

@wata00913
Copy link
Contributor

@mono-nobe
お疲れ様です!
レビュー依頼ありがとうございます!
レビューに1週間ほど要しそうですが、大丈夫でしょうか?

@mono-nobe
Copy link
Contributor Author

@wata00913
はい!大丈夫です〜
よろしくお願いします! 🙏

@wata00913 wata00913 assigned komagata and unassigned komagata Mar 30, 2023
# frozen_string_literal: true

class API::Mentor::BaseController < ApplicationController
skip_before_action :require_active_user_login, raise: false
Copy link
Contributor

Choose a reason for hiding this comment

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

require_active_user_loginをスキップする理由は何故でしょうか?

Copy link
Contributor Author

@mono-nobe mono-nobe May 19, 2023

Choose a reason for hiding this comment

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

前提として、ApplicationControllerbefore_action :require_active_user_login が定義されているため、継承している API::Mentor::BaseController においても before_action :require_active_user_login が実行されてしまいます。
しかし、この Controller は API 専用であるため画面でのログインができないため、 skip_before_action しています!

代わりに、同 Controller 内にある before_action :require_mentor_login_for_api で権限チェックをしています。

before_action :require_mentor_login_for_api

Copy link
Contributor

Choose a reason for hiding this comment

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

詳しく説明して頂きありがとうございます!require_active_user_loginをスキップする理由が理解できました〜

@@ -17,7 +17,7 @@ def create
@category = Category.new(category_params)

if @category.save
redirect_to admin_categories_url, notice: 'カテゴリーを作成しました。'
redirect_to mentor_categories_url, notice: 'カテゴリーを作成しました。'
else
Copy link
Contributor

@wata00913 wata00913 Apr 5, 2023

Choose a reason for hiding this comment

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

以下のCoursesController#createアクションとMentor::CoursesController#createの処理が重複しているようです。CoursesController#createは削除しても良さそうです。
Mentor::CoursesController側の処理を残す理由は、名前空間のMentorがあるので責務がより明確になると思いました〜

Copy link
Contributor

@wata00913 wata00913 Apr 5, 2023

Choose a reason for hiding this comment

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

CoursesController#createはコース一覧画面/coursesの「コース作成」ボタンをクリック時に実行されるようです。
もし、Mentor::CoursesController#createに処理をまとめる場合は、「コース作成」ボタンの遷移先URLを変更する必要がありそうです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

確認したところ、同じ機能を持つ画面が複数存在しているようでした...
そのため、wataさんのおっしゃる通り mentor 用の画面( /mentor/courses/...)のみ残す方が良いかと思います!
しかし、そちらの対応は今回の issue のスコープ外である気もするため、一度駒形さんに確認させてください 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

📝
こちらで確認中
#6344 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

こちら別issueで対応する方針となりましたので、ご確認をお願いします!
#6344 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

こちらの確認、自分の方で早めに対応しておくべきでした。
もののべさんの負担をかけてすみませんでした🙇‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wata00913
いえいえ!
wataさんのご指摘がなかったら今後対応されることはなかったと思うのでとても助かりました!🙌


class Mentor::PracticesController < MentorController
def index; end
end
Copy link
Contributor

@wata00913 wata00913 Apr 5, 2023

Choose a reason for hiding this comment

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

以下のアクションをMentor::PracticesContorllerに移動させた方が責務が明確になるのではないかと思いました。いかがでしょうか?
ただし、処理を移す作業が大変そうなので駒形さんに意見を聞いた方が良さそうです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

影響範囲の調査までありがとうございます!
こちらも駒形さんに確認します!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

📝
こちらで確認中
#6344 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

同様に別issueで対応する方針となりました。
#6344 (comment)

@@ -14,9 +14,9 @@
v-if='category.completed_all_practices === true')
| 修了
.categories-item__description
.categories-item__edit.is-only-mentor(v-if='isRole("admin")')
.categories-item__edit.is-only-mentor(v-if='isRole("mentor")')
Copy link
Contributor

@wata00913 wata00913 Apr 5, 2023

Choose a reason for hiding this comment

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

adminの条件分岐を考慮をしなくても大丈夫でしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adminユーザーは必ずmentorユーザーでもあるため、mentorのみを考慮しています!

= render @courses.order(:created_at)
- elsif !current_user&.admin? && @courses.where(published: true).present?
- elsif !current_user&.mentor? && @courses.where(published: true).present?
Copy link
Contributor

Choose a reason for hiding this comment

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

こちら(18行目、20行目)もadminの条件分岐を考慮をしなくても大丈夫でしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

同様の理由でmentorのみ考慮しています。

.courses-item__title-icon.is-closed
| 非表示
span.courses-item__title-label
= course.title
.courses-item__description
= simple_format(course.description)
- if admin_login?
- if mentor_login?
Copy link
Contributor

Choose a reason for hiding this comment

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

こちらも同様です。

Copy link
Contributor Author

@mono-nobe mono-nobe May 19, 2023

Choose a reason for hiding this comment

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

同様の理由でmentorのみ考慮しています。

= link_to new_admin_category_path, class: 'a-button is-md is-secondary is-block' do
i.fa-regular.fa-plus
| カテゴリー作成
- if current_user.admin_or_mentor?
Copy link
Contributor

Choose a reason for hiding this comment

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

MentorControllerにてログインユーザーの判定をしているので削除して良いかなと思いました。

before_action :require_admin_or_mentor_login

Copy link
Contributor Author

Choose a reason for hiding this comment

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

おっしゃる通り、mentor専用のページでもあるため判定は不要ですね 👀
削除しました!

.page-header__inner
h2.page-header__title = title
.page-header-actions
- if current_user.admin_or_mentor?
Copy link
Contributor

@wata00913 wata00913 Apr 5, 2023

Choose a reason for hiding this comment

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

こちらの条件処理もMentorControllerにてログインユーザーの判定をしているので削除して良いかなと思いました。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

こちらも同様の理由で削除しました!

@@ -6,5 +6,12 @@ class Admin::HomeTest < ApplicationSystemTestCase
test 'GET /admin' do
visit_with_auth '/admin', 'komagata'
assert_equal '管理ページ | FBC', title
assert_selector '.page-tabs__item-link', text: '管理ページ', visible: true
Copy link
Contributor

Choose a reason for hiding this comment

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

visible: trueが必要なのは何故でしょうか?

Copy link
Contributor Author

@mono-nobe mono-nobe May 19, 2023

Choose a reason for hiding this comment

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

Capybara の仕様を正しく理解していませんでした...
オプション不要なため削除しました!

assert_selector '.page-tabs__item-link', text: 'ユーザー', visible: true
assert_selector '.page-tabs__item-link', text: '企業', visible: true
assert_selector '.page-tabs__item-link', text: 'お試し延長', visible: true
assert_no_selector '.page-tabs__item-link', text: 'プラクティス', visible: true
Copy link
Contributor

@wata00913 wata00913 Apr 5, 2023

Choose a reason for hiding this comment

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

タブがないことを保証するテストを書いてて良いですね!👍
もう少し抽象化出来ると良さそうです!例えば、.page-tabs__item-linkをもつselectorの個数が4つ(つまり表示されているタブの個数)であることを保証するテストコードに置き換えるのはどうでしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

タブがないことを保証するテストを書いてて良いですね!👍

ありがとうございます!😊

例えば、.page-tabs__item-linkをもつselectorの個数が4つ(つまり表示されているタブの個数)であることを保証するテストコードに置き換えるのはどうでしょうか?

確かに、現状だとタブが増えてもテストが通ってしまいますね... 🤔
何のタブが表示されているかのテストは残したいので、selector の個数も確認するよう追加しました!

assert_selector '.page-tabs__item-link', text: 'コース', visible: true
assert_no_selector '.page-tabs__item-link', text: 'ユーザー', visible: true
assert_no_selector '.page-tabs__item-link', text: '企業', visible: true
assert_no_selector '.page-tabs__item-link', text: 'お試し延長', visible: true
Copy link
Contributor

Choose a reason for hiding this comment

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

こちらのコメントと同じです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

同様にassertionを追加しました!

Copy link
Contributor

@wata00913 wata00913 left a comment

Choose a reason for hiding this comment

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

@mono-nobe
mononobeさん、お待たせしました🙏

動作確認について

動作確認はOKでした〜

変更確認方法について確認したいこと、指摘内容があります。

  • 確認したいこと
    1. 手順7.「コースページについて、以下の内容を確認する」の「コースを並び替えられる」での動作確認対象のページは、 /courses/{course_id}/categories で合っているでしょうか?
    2. 手順7.「コースページについて、以下の内容を確認する」の「プラクティスを並び替えられる」での動作確認対象のページは、 /courses/{course_id}/practices/sort で合っているでしょうか?
  • 指摘内容
    • 動作確認「コースを並び替えられる」と「プラクティスを並び替えられる」は具体的な操作方法が無いため、確認に戸惑ってしまいました。この2点のみでも、具体的な操作手順を書いた方が、初見の人でも対応しやすいのかなと思いました〜

    • 手順7.「コースページについて、以下の内容を確認する」で添付された以下の図が、どの操作に対してのものか不明でした。図についての説明があると分かりやすいと思いました。

      img

    • 手順7.「コースページについて、以下の内容を確認する」で、「コースを作成できる」の記述漏れがありました。動作確認はOKでした!

コードについて

細かいコメントはコード毎に記載しております。自分の観点でコメントしましたが、気になることや間違いがあれば是非ご指摘をよろしくお願いします🙏

あと、1点確認したいことがあります。
管理者はメンターの役割も必ず持つのでしょうか?
今回のIssueではプラクティスカテゴリーコースの編集権限を管理者だけでなく、メンターも追加することだと思いますが、メンターのみを考慮したコードが幾つかありました。
メンターでない管理者がいるケースだと、メンターのみを考慮したコードの修正が必要だと思います。

@mono-nobe
Copy link
Contributor Author

@wata00913
レビューありがとうございます!
対応までお時間いただくかと思いますが、引き続きよろしくお願いします... 🙇

@mono-nobe mono-nobe force-pushed the feature/grant-edit-permission-to-mentor-for-categories-courses-practices branch from 6eef41e to 8a9bb1e Compare May 19, 2023 07:00
@mono-nobe
Copy link
Contributor Author

@komagata
リファクタリングが必要そうな箇所があるのですが、本 issue で対応するべきかをご相談させてください。
現状、adminのみ実行できるControllerメソッドが、admin用のControllerがあるにも関わらず、一般?のController内で定義されております。
理想は、adminのみ実行できるメソッドはadmin用のControllerのみに定義するべきだと考えています。
しかし、これらを改修するとなると controller 以外も改修する必要があるため、対応範囲が大きくなってしまいます。
本 issue はあくまで admin 権限を mentor に移行することであるため、リファクタリングは別 issue での対応としたいのですが、いかがでしょうか? 👀

#6344 (comment)
#6344 (comment)

@mono-nobe
Copy link
Contributor Author

リファクタリングが必要そうな箇所があるのですが、本 issue で対応するべきかをご相談させてください。

こちら、リファクタリングは別Issueにしたいと思いますー
Issueを作ってもらえると助かります🙏

こちら @machida さんよりご回答いただき、別 issue(#6536) で実施することになった

https://discord.com/channels/715806612824260640/809595476847493192/1109043419441016862

@mono-nobe
Copy link
Contributor Author

@wata00913
大変お待たせしました。。 🙇
コードだけではなく、PRの内容や仕様周りも丁寧にレビューいただきとても助かります!
コメントいただいた内容について対応しましたので、ご確認をお願いします。
また、ご質問(指摘)に対する回答を以下に記載しておりますので、併せてご確認をお願いします。

確認したいこと

はい!どちらとも合っております! 🙆‍♂️

指摘内容

失礼しました。
見返すと確かに説明不足ですね... 😓
いただいた内容を追記しましたので、過不足ないか再度ご確認いただけると幸いです。

細かいコメントはコード毎に記載しております。自分の観点でコメントしましたが、気になることや間違いがあれば是非ご指摘をよろしくお願いします🙏

ありがとうございます!😊
本issueで対応するか迷った箇所については町田さんに確認し回答しております!

管理者はメンターの役割も必ず持つのでしょうか?

こちら確認したところ、管理者はメンターの役割を必ず持つとのことでした!

これからは時間が取りやすくなるため、今回のように時間がかかることはないかと思います。。
引き続きよろしくお願いします。

@mono-nobe
Copy link
Contributor Author

@wata00913
現在テストが落ちているため、通り次第再度ご連絡します 🙇

@wata00913
Copy link
Contributor

@mono-nobe

現在テストが落ちているため、通り次第再度ご連絡します 🙇

了解しました、動作確認やコードの確認はテストが通った後確認しようと思います!

それと、現在コンフリクトが起きているみたいなので、対応の方を後程よろしくお願いします!🙏

@mono-nobe mono-nobe force-pushed the feature/grant-edit-permission-to-mentor-for-categories-courses-practices branch from a3ea8b7 to 2ff8a75 Compare May 24, 2023 11:16
@mono-nobe mono-nobe force-pushed the feature/grant-edit-permission-to-mentor-for-categories-courses-practices branch from 0d4cb90 to e21f240 Compare July 2, 2023 09:41
@mono-nobe
Copy link
Contributor Author

@komagata
いただいた内容を修正しましたので、ご確認をお願いします!

Copy link
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

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

確認させて頂きました。OKです〜🙆‍♂️

@komagata komagata merged commit ca94879 into main Jul 11, 2023
2 checks passed
@komagata komagata deleted the feature/grant-edit-permission-to-mentor-for-categories-courses-practices branch July 11, 2023 12:42
@github-actions github-actions bot mentioned this pull request Jul 11, 2023
6 tasks
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.

4 participants