1
0

Remove.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types = 1);
  3. /**
  4. * @copyright Copyright (c) 2023 Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
  5. *
  6. * @author Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Settings\Command\AdminDelegation;
  25. use OC\Core\Command\Base;
  26. use OCA\Settings\Service\AuthorizedGroupService;
  27. use OCP\IGroupManager;
  28. use OCP\Settings\IManager;
  29. use Symfony\Component\Console\Input\InputArgument;
  30. use Symfony\Component\Console\Input\InputInterface;
  31. use Symfony\Component\Console\Output\OutputInterface;
  32. use Symfony\Component\Console\Style\SymfonyStyle;
  33. class Remove extends Base {
  34. public function __construct(
  35. private IManager $settingManager,
  36. private AuthorizedGroupService $authorizedGroupService,
  37. private IGroupManager $groupManager,
  38. ) {
  39. parent::__construct();
  40. }
  41. protected function configure(): void {
  42. $this
  43. ->setName('admin-delegation:remove')
  44. ->setDescription('remove settings delegation from a group')
  45. ->addArgument('settingClass', InputArgument::REQUIRED, 'Admin setting class')
  46. ->addArgument('groupId', InputArgument::REQUIRED, 'Group ID to remove')
  47. ->addUsage('\'OCA\Settings\Settings\Admin\Server\' mygroup')
  48. ;
  49. }
  50. protected function execute(InputInterface $input, OutputInterface $output): int {
  51. $io = new SymfonyStyle($input, $output);
  52. $settingClass = $input->getArgument('settingClass');
  53. $groups = $this->authorizedGroupService->findExistingGroupsForClass($settingClass);
  54. $groupId = $input->getArgument('groupId');
  55. foreach ($groups as $group) {
  56. if ($group->getGroupId() === $groupId) {
  57. $this->authorizedGroupService->delete($group->getId());
  58. $io->success('Removed delegation of '.$settingClass.' to '.$groupId.'.');
  59. return 0;
  60. }
  61. }
  62. $io->success('Group '.$groupId.' didn’t have delegation for '.$settingClass.'.');
  63. return 0;
  64. }
  65. }