Skip to content

refs #363 画面から管理権限を付与・解除できるようにする#369

Open
aomrikti wants to merge 5 commits into
masterfrom
i363
Open

refs #363 画面から管理権限を付与・解除できるようにする#369
aomrikti wants to merge 5 commits into
masterfrom
i363

Conversation

@aomrikti

Copy link
Copy Markdown
Collaborator

first_boot やコンソール以外から admin を操作できるようにした。
新規ユーザ作成時のチェックボックスと、ユーザ・従業員一覧からの付与・解除に対応。
#361 の最後の一人ガードを admin 解除にも拡張した。

first_boot やコンソール以外から admin を操作できるようにした。
新規ユーザ作成時のチェックボックスと、ユーザ・従業員一覧からの付与・解除に対応。
#361 の最後の一人ガードを admin 解除にも拡張した。
Copilot AI review requested due to automatic review settings June 26, 2026 06:39

Copilot AI 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.

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.

Comment thread app/controllers/mm/users_controller.rb
Comment thread app/controllers/mm/users_controller.rb
Comment thread app/controllers/mm/users_controller.rb
Comment thread app/controllers/mm/users_controller.rb Outdated
:zip_code, :address, :sex, :business_office_id, :birth, :my_number
]
]
permitted << :admin if current_user.admin? && action_name == 'create'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ここで、 current_user.admin? かどうかを確認していますが、管理者以外がこの画面にアクセスできるでしょうか?
config/acl.yml 的には管理者のみアクセス可で保護されているように見えました。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ご指摘ありがとうざいます。
ACLにより管理者以外はこの画面にアクセスできないため、current_user.adimin?は不要である事を理解しました。該当の箇所を削除しました。

あわせて、ビューにも同様に不要なcurrent_user.admin?が書かれている箇所がある事を認識しましたので、削除しました。
削除後も挙動に変化はないことを確認しました。

@ichylinux ichylinux assigned aomrikti and unassigned ichylinux Jun 30, 2026
@aomrikti aomrikti assigned ichylinux and unassigned aomrikti Jul 1, 2026
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.

3 participants