Skip to content

Conversation

@printminion-co
Copy link
Contributor

Before

Multiple delegation to same group is possible

$ php occ admin-delegation:add OCA\\Settings\\Settings\\Admin\\Overview admin
 [OK] Administration of OCA\Settings\Settings\Admin\Overview delegated to admin.                                        

$ php occ admin-delegation:add OCA\\Settings\\Settings\\Admin\\Overview admin
 [OK] Administration of OCA\Settings\Settings\Admin\Overview delegated to admin.                                        

$ php occ admin-delegation:add OCA\\Settings\\Settings\\Admin\\Overview admin
 [OK] Administration of OCA\Settings\Settings\Admin\Overview delegated to admin.                                        

$ php occ admin-delegation:show 

Current delegations
===================

Section: overview
-----------------

 ------------------------- -------------------------------------- --------------------- 
  Name                      SettingId                              Delegated to groups  
 ------------------------- -------------------------------------- --------------------- 
  Security & setup checks   OCA\Settings\Settings\Admin\Overview   admin, admin, admin  
 ------------------------- -------------------------------------- --------------------- 

After fix

Fixes issue with delegation via occ and web.
No multiple entries in DB.

php occ admin-delegation:add OCA\\Settings\\Settings\\Admin\\Overview admin
 [OK] Administration of OCA\Settings\Settings\Admin\Overview delegated to admin.                                        
php occ admin-delegation:add OCA\\Settings\\Settings\\Admin\\Overview admin
 [WARNING] The OCA\Settings\Settings\Admin\Overview is already delegated to admin.                                      

Checklist

@printminion-co printminion-co requested a review from a team as a code owner November 24, 2025 20:56
@printminion-co printminion-co requested review from Altahrim, leftybournes, salmart-dev and yemkareems and removed request for a team November 24, 2025 20:56
@printminion-co printminion-co force-pushed the fix/no_double_admin_delegations branch from 8cd9c11 to 74a6b24 Compare November 24, 2025 21:05
@AndyScherzinger AndyScherzinger added the 3. to review Waiting for reviews label Nov 24, 2025
Copy link

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

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 throws ConflictException when 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.

Comment on lines +65 to +68
$existing = $this->mapper->findByGroupIdAndClass($groupId, $class);
if ($existing) {
throw new ConflictException('Group is already assigned to this class');
}
Copy link

Copilot AI Nov 24, 2025

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.

Suggested change
$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');

Copilot uses AI. Check for mistakes.
$this->service->delete($initialId);

// Verify it's deleted by trying to find it
$this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class);
Copy link

Copilot AI Nov 24, 2025

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.

Suggested change
$this->expectException(\OCP\AppFramework\Db\DoesNotExistException::class);

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@come-nc come-nc left a 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.

@printminion-co printminion-co force-pushed the fix/no_double_admin_delegations branch 3 times, most recently from d6116fc to 59d9bf4 Compare November 27, 2025 13:18
@artonge artonge requested a review from come-nc December 2, 2025 09:58
@printminion-co printminion-co force-pushed the fix/no_double_admin_delegations branch from 59d9bf4 to 72b3a51 Compare December 2, 2025 11:16
@printminion-co printminion-co force-pushed the fix/no_double_admin_delegations branch from 72b3a51 to 8192a06 Compare December 4, 2025 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: occ admin-delegation:add allows adding the same delegation multiple times

6 participants