Skip to content

fix #4299 ユーザーが存在するユーザーグループを削除できないようにする#4329

Open
kawaseryoma wants to merge 1 commit intobaserproject:5.2.xfrom
RyoK513:#4299
Open

fix #4299 ユーザーが存在するユーザーグループを削除できないようにする#4329
kawaseryoma wants to merge 1 commit intobaserproject:5.2.xfrom
RyoK513:#4299

Conversation

@kawaseryoma
Copy link
Contributor

概要

Issue #4299 の対応です。

ユーザーが所属しているユーザーグループを削除できないようにする機能を実装しました。

変更内容

  • UserGroupsService::delete() で所属ユーザーの存在確認を追加
  • ユーザーが所属している場合は BcException をスローして削除を拒否
  • API/管理画面コントローラーにエラーハンドリングを追加
  • ユニットテストと統合テストを追加

動作

  • ユーザーが所属しているユーザーグループを削除しようとすると、エラーメッセージ「ユーザーが所属しているユーザーグループは削除できません。」が表示される
  • ユーザーが所属していないユーザーグループは正常に削除可能
  • API経由では400エラー、管理画面ではフラッシュメッセージでエラーを通知

テスト

すべてのテストが成功しています:

  • ✅ UserGroupsServiceTest: 12 tests, 15 assertions
  • ✅ API UserGroupsControllerTest: 8 tests, 20 assertions
  • ✅ Admin UserGroupsControllerTest: 7 tests, 16 assertions

関連Issue

Closes #4299

- UserGroupsService::delete() で所属ユーザーの存在確認を追加
- ユーザーが所属している場合は BcException をスローして削除を拒否
- API/管理画面コントローラーにエラーハンドリングを追加
- ユニットテストと統合テストを追加

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 15, 2026 08:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Issue #4299 対応として、所属ユーザーが存在するユーザーグループを削除できないようにし、API/管理画面側でその例外を適切に扱えるようにする変更です。

Changes:

  • UserGroupsService::delete() で所属ユーザー有無を確認し、存在する場合は BcException を投げて削除を拒否
  • API/管理画面のユーザーグループ削除処理に BcException のハンドリングを追加
  • 上記仕様に対するサービス・API・管理画面のテストを追加/更新

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
plugins/baser-core/src/Service/UserGroupsService.php 所属ユーザーがいるユーザーグループの削除を BcException で拒否
plugins/baser-core/src/Controller/Api/Admin/UserGroupsController.php API削除で BcException を 400 として返却
plugins/baser-core/src/Controller/Admin/UserGroupsController.php 管理画面削除で BcException をフラッシュメッセージとして表示
plugins/baser-core/tests/TestCase/Service/UserGroupsServiceTest.php サービス層で「所属ユーザーがいる場合は削除不可」を検証するテスト追加
plugins/baser-core/tests/TestCase/Controller/Api/Admin/UserGroupsControllerTest.php API削除の成功/失敗(所属ユーザーあり)を検証するテスト更新/追加
plugins/baser-core/tests/TestCase/Controller/Admin/UserGroupsControllerTest.php 管理画面削除の成功/失敗(所属ユーザーあり)を検証するテスト更新/追加

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +181 to +197
// ユーザーを作成
$user = UserFactory::make([
'id' => 200,
'name' => 'test_user2',
'password' => 'password',
'real_name_1' => 'test',
'real_name_2' => 'user',
'email' => 'testuser2@example.com',
'nickname' => 'テストユーザー2',
'status' => true
])->persist();

// ユーザーグループとユーザーの関連付けを作成
UsersUserGroupFactory::make([
'user_id' => 200,
'user_group_id' => 2
])->persist();
Comment on lines +183 to +186
$userGroup = $this->UserGroups->get($id, ['contain' => ['Users']]);
if (!empty($userGroup->users)) {
throw new BcException(__d('baser_core', 'ユーザーが所属しているユーザーグループは削除できません。'));
}
Comment on lines +154 to +171
// ユーザーを作成
$user = UserFactory::make([
'id' => 100,
'name' => 'test_user',
'password' => 'password',
'real_name_1' => 'test',
'real_name_2' => 'user',
'email' => 'testuser@example.com',
'nickname' => 'テストユーザー',
'status' => true
])->persist();

// ユーザーグループとユーザーの関連付けを作成
UsersUserGroupFactory::make([
'user_id' => 100,
'user_group_id' => 2
])->persist();

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.

【ユーザー】ユーザーが存在するユーザーグループを削除できないようにしたい

2 participants