-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(admin-delegation): Prevent delegation to group if delegation already #56646
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
base: master
Are you sure you want to change the base?
Conversation
8cd9c11 to
74a6b24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR prevents duplicate admin delegation assignments by adding validation to check if a group is already delegated to a specific settings class before creating a new assignment.
Key Changes:
- Introduces duplicate detection logic in
AuthorizedGroupService::create()that throwsConflictExceptionwhen attempting to assign the same group to the same class twice - Updates the CLI command to handle the conflict gracefully with a warning message and appropriate exit code
- Adds comprehensive unit and integration tests to verify duplicate prevention behavior
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/settings/lib/Service/ConflictException.php | New exception class for signaling duplicate assignment conflicts |
| apps/settings/lib/Service/AuthorizedGroupService.php | Adds duplicate check before creating assignments, throwing ConflictException when duplicates are detected |
| apps/settings/lib/Command/AdminDelegation/Add.php | Catches ConflictException and displays warning message with exit code 4 |
| apps/settings/tests/Service/AuthorizedGroupServiceTest.php | Unit tests verifying duplicate prevention and allowed multi-group/multi-class scenarios |
| apps/settings/tests/Command/AdminDelegation/AddTest.php | Unit test for CLI command's duplicate handling behavior |
| apps/settings/tests/Integration/DuplicateAssignmentIntegrationTest.php | Integration tests validating end-to-end duplicate prevention workflow |
| apps/settings/composer/composer/autoload_static.php | Registers new ConflictException class in autoloader |
| apps/settings/composer/composer/autoload_classmap.php | Adds ConflictException to class map |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $existing = $this->mapper->findByGroupIdAndClass($groupId, $class); | ||
| if ($existing) { | ||
| throw new ConflictException('Group is already assigned to this class'); | ||
| } |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition if ($existing) is redundant. The findByGroupIdAndClass method will either return an entity or throw DoesNotExistException. If it returns, the entity will always be truthy. The exception should be thrown immediately after the method call without the conditional check.
| $existing = $this->mapper->findByGroupIdAndClass($groupId, $class); | |
| if ($existing) { | |
| throw new ConflictException('Group is already assigned to this class'); | |
| } | |
| $this->mapper->findByGroupIdAndClass($groupId, $class); | |
| throw new ConflictException('Group is already assigned to this class'); |
| $this->service->delete($initialId); | ||
|
|
||
| // Verify it's deleted by trying to find it | ||
| $this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class); |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test expects DoesNotExistException on line 111 but catches NotFoundException on line 114. These are different exception types. The expectException should be removed since the test is manually catching and handling the exception, or the caught exception type should match the expected one.
| $this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class); |
come-nc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a bit cleaner to add a unique constraint on the table and simply ignore the exception on insert if it’s a REASON_UNIQUE_CONSTRAINT_VIOLATION I think. But that would require a migration to remove existing duplicates and stuff, not sure it’s worth it.
apps/settings/tests/Integration/DuplicateAssignmentIntegrationTest.php
Outdated
Show resolved
Hide resolved
d6116fc to
59d9bf4
Compare
59d9bf4 to
72b3a51
Compare
…ady exist Signed-off-by: Misha M.-Kupriyanov <[email protected]>
72b3a51 to
8192a06
Compare
Before
Multiple delegation to same group is possible
After fix
Fixes issue with delegation via occ and web.
No multiple entries in DB.
Checklist
3. to review, feature component)stable32)