fix: Don't permit duplicate groups in occ admin-delegation:add

Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
This commit is contained in:
Josh Richards 2024-07-18 11:29:11 -04:00
parent 9cd2e5bed9
commit 39291ca393

View file

@ -40,16 +40,24 @@ class Add extends Base {
$io = new SymfonyStyle($input, $output);
$settingClass = $input->getArgument('settingClass');
if (!in_array(IDelegatedSettings::class, (array) class_implements($settingClass), true)) {
$io->error('The specified class isnt 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 didnt 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.'.');