-
-
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
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
72b3a51 to
8192a06
Compare
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
8192a06 to
cd10528
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.
The suggestion should be enough to fix the nodb test
…ady exist Signed-off-by: Misha M.-Kupriyanov <[email protected]>
b778710 to
770ad62
Compare
|
/backport to stable31 |
|
/backport to stable32 |
|
The backport to # Switch to the target branch and update it
git checkout stable31
git pull origin stable31
# Create the new backport branch
git checkout -b backport/56646/stable31
# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts, resolve them
git cherry-pick 770ad624
# Push the cherry pick commit to the remote repository and open a pull request
git push origin backport/56646/stable31Error: Failed to check for changes with origin/stable31: No changes found in backport branch Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports. |
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)