Remove.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types = 1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\Command\AdminDelegation;
  8. use OC\Core\Command\Base;
  9. use OCA\Settings\Service\AuthorizedGroupService;
  10. use OCP\IGroupManager;
  11. use OCP\Settings\IManager;
  12. use Symfony\Component\Console\Input\InputArgument;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\Console\Style\SymfonyStyle;
  16. class Remove extends Base {
  17. public function __construct(
  18. private IManager $settingManager,
  19. private AuthorizedGroupService $authorizedGroupService,
  20. private IGroupManager $groupManager,
  21. ) {
  22. parent::__construct();
  23. }
  24. protected function configure(): void {
  25. $this
  26. ->setName('admin-delegation:remove')
  27. ->setDescription('remove settings delegation from a group')
  28. ->addArgument('settingClass', InputArgument::REQUIRED, 'Admin setting class')
  29. ->addArgument('groupId', InputArgument::REQUIRED, 'Group ID to remove')
  30. ->addUsage('\'OCA\Settings\Settings\Admin\Server\' mygroup')
  31. ;
  32. }
  33. protected function execute(InputInterface $input, OutputInterface $output): int {
  34. $io = new SymfonyStyle($input, $output);
  35. $settingClass = $input->getArgument('settingClass');
  36. $groups = $this->authorizedGroupService->findExistingGroupsForClass($settingClass);
  37. $groupId = $input->getArgument('groupId');
  38. foreach ($groups as $group) {
  39. if ($group->getGroupId() === $groupId) {
  40. $this->authorizedGroupService->delete($group->getId());
  41. $io->success('Removed delegation of '.$settingClass.' to '.$groupId.'.');
  42. return 0;
  43. }
  44. }
  45. $io->success('Group '.$groupId.' didn’t have delegation for '.$settingClass.'.');
  46. return 0;
  47. }
  48. }