From 39291ca393e09a4bf28cee53fcf2f5ca308a5393 Mon Sep 17 00:00:00 2001 From: Josh Richards Date: Thu, 18 Jul 2024 11:29:11 -0400 Subject: [PATCH] fix: Don't permit duplicate groups in occ admin-delegation:add Signed-off-by: Josh Richards --- apps/settings/lib/Command/AdminDelegation/Add.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/settings/lib/Command/AdminDelegation/Add.php b/apps/settings/lib/Command/AdminDelegation/Add.php index 4ec6510f20538..73c995b476267 100644 --- a/apps/settings/lib/Command/AdminDelegation/Add.php +++ b/apps/settings/lib/Command/AdminDelegation/Add.php @@ -40,16 +40,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io = new SymfonyStyle($input, $output); $settingClass = $input->getArgument('settingClass'); if (!in_array(IDelegatedSettings::class, (array) class_implements($settingClass), true)) { - $io->error('The specified class isn’t a valid delegated setting.'); + $io->error('The specified class is not a valid delegated setting.'); return 2; } $groupId = $input->getArgument('groupId'); if (!$this->groupManager->groupExists($groupId)) { - $io->error('The specified group didn’t exist.'); + $io->error('The specified group does not exist.'); return 3; } + $groups = $this->authorizedGroupService->findExistingGroupsForClass($settingClass); + foreach ($groups as $group) { + if ($group->getGroupId() === $groupId) { + $io->error('The specified group has already been delegated to.'); + return 4; + } + } + $this->authorizedGroupService->create($groupId, $settingClass); $io->success('Administration of '.$settingClass.' delegated to '.$groupId.'.');