fix #4299 ユーザーが存在するユーザーグループを削除できないようにする#4329
Open
kawaseryoma wants to merge 1 commit intobaserproject:5.2.xfrom
Open
fix #4299 ユーザーが存在するユーザーグループを削除できないようにする#4329kawaseryoma wants to merge 1 commit intobaserproject:5.2.xfrom
kawaseryoma wants to merge 1 commit intobaserproject:5.2.xfrom
Conversation
- UserGroupsService::delete() で所属ユーザーの存在確認を追加 - ユーザーが所属している場合は BcException をスローして削除を拒否 - API/管理画面コントローラーにエラーハンドリングを追加 - ユニットテストと統合テストを追加 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
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(); | ||
|
|
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.
概要
Issue #4299 の対応です。
ユーザーが所属しているユーザーグループを削除できないようにする機能を実装しました。
変更内容
UserGroupsService::delete()で所属ユーザーの存在確認を追加BcExceptionをスローして削除を拒否動作
テスト
すべてのテストが成功しています:
関連Issue
Closes #4299