Conversation
first_boot やコンソール以外から admin を操作できるようにした。 新規ユーザ作成時のチェックボックスと、ユーザ・従業員一覧からの付与・解除に対応。 #361 の最後の一人ガードを admin 解除にも拡張した。
Contributor
There was a problem hiding this comment.
Pull request overview
管理権限(admin)を first_boot/コンソール以外の画面操作で付与・解除できるようにし、あわせて「ログイン可能な admin が 0 人になる操作」を防止するガードを admin 解除にも拡張するPRです。
Changes:
- ユーザー作成時の admin チェックボックス追加、一覧画面からの admin 付与/解除導線追加
- 「最後のログイン可能 admin」ガードを admin 解除(admin=true→false)にも適用
loginable?/active_admin?/user_loginable?追加と、一覧のN+1回避(includes)対応、関連テスト追加
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/models/validators/last_active_admin_validator_test.rb | admin 解除時の「最後のログイン可能 admin」ガードのテスト追加 |
| test/models/user_test.rb | loginable? / active_admin? の挙動テスト追加 |
| test/models/employee_test.rb | Employee#user_loginable? の挙動テスト追加 |
| test/controllers/mm/users_controller_test.rb | admin 付与/解除アクションと作成時付与のテスト追加、既存テストの調整 |
| config/routes/mm.rb | mm/users#grant_admin / revoke_admin のmemberルート追加 |
| config/locales/hyacc.ja.yml | user.admin の表示名追加 |
| app/views/mm/users/index.html.erb | ユーザー一覧に admin 列と付与/解除ボタンを追加(adminのみ表示) |
| app/views/mm/users/_form.html.erb | 新規作成フォームに admin チェックボックス追加(adminのみ表示) |
| app/views/mm/employees/index.html.erb | 従業員一覧に admin 列と付与/解除ボタンを追加(adminのみ表示) |
| app/utils/hyacc_errors.rb | admin 解除ガード用エラーメッセージ追加 |
| app/models/validators/last_active_admin_validator.rb | admin解除も「最後のログイン可能 admin」ガード対象に追加 |
| app/models/user.rb | loginable? 追加、active_admin? の整理、ガード判定ロジック拡張 |
| app/models/employee.rb | user_loginable? 追加 |
| app/models/employee_finder.rb | 一覧で user を eager load してN+1回避 |
| app/controllers/mm/users_controller.rb | 一覧で employee eager load、admin付与/解除アクション追加、作成時のみ admin をpermit |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ichylinux
reviewed
Jun 30, 2026
| :zip_code, :address, :sex, :business_office_id, :birth, :my_number | ||
| ] | ||
| ] | ||
| permitted << :admin if current_user.admin? && action_name == 'create' |
Member
There was a problem hiding this comment.
ここで、 current_user.admin? かどうかを確認していますが、管理者以外がこの画面にアクセスできるでしょうか?
config/acl.yml 的には管理者のみアクセス可で保護されているように見えました。
Collaborator
Author
There was a problem hiding this comment.
ご指摘ありがとうざいます。
ACLにより管理者以外はこの画面にアクセスできないため、current_user.adimin?は不要である事を理解しました。該当の箇所を削除しました。
あわせて、ビューにも同様に不要なcurrent_user.admin?が書かれている箇所がある事を認識しましたので、削除しました。
削除後も挙動に変化はないことを確認しました。
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.
first_boot やコンソール以外から admin を操作できるようにした。
新規ユーザ作成時のチェックボックスと、ユーザ・従業員一覧からの付与・解除に対応。
#361 の最後の一人ガードを admin 解除にも拡張した。