@@ -30,54 +30,54 @@ |
||
30 | 30 | use Symfony\Component\Console\Output\OutputInterface; |
31 | 31 | |
32 | 32 | class ListCommand extends Base { |
33 | - public function __construct( |
|
34 | - protected ISystemTagManager $systemTagManager, |
|
35 | - ) { |
|
36 | - parent::__construct(); |
|
37 | - } |
|
33 | + public function __construct( |
|
34 | + protected ISystemTagManager $systemTagManager, |
|
35 | + ) { |
|
36 | + parent::__construct(); |
|
37 | + } |
|
38 | 38 | |
39 | - protected function configure() { |
|
40 | - $this |
|
41 | - ->setName('tag:list') |
|
42 | - ->setDescription('list tags') |
|
43 | - ->addOption( |
|
44 | - 'visibilityFilter', |
|
45 | - null, |
|
46 | - InputOption::VALUE_OPTIONAL, |
|
47 | - 'filter by visibility (1,0)' |
|
48 | - ) |
|
49 | - ->addOption( |
|
50 | - 'nameSearchPattern', |
|
51 | - null, |
|
52 | - InputOption::VALUE_OPTIONAL, |
|
53 | - 'optional search pattern for the tag name (infix)' |
|
54 | - ); |
|
55 | - parent::configure(); |
|
56 | - } |
|
39 | + protected function configure() { |
|
40 | + $this |
|
41 | + ->setName('tag:list') |
|
42 | + ->setDescription('list tags') |
|
43 | + ->addOption( |
|
44 | + 'visibilityFilter', |
|
45 | + null, |
|
46 | + InputOption::VALUE_OPTIONAL, |
|
47 | + 'filter by visibility (1,0)' |
|
48 | + ) |
|
49 | + ->addOption( |
|
50 | + 'nameSearchPattern', |
|
51 | + null, |
|
52 | + InputOption::VALUE_OPTIONAL, |
|
53 | + 'optional search pattern for the tag name (infix)' |
|
54 | + ); |
|
55 | + parent::configure(); |
|
56 | + } |
|
57 | 57 | |
58 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
59 | - $tags = $this->systemTagManager->getAllTags( |
|
60 | - $input->getOption('visibilityFilter'), |
|
61 | - $input->getOption('nameSearchPattern') |
|
62 | - ); |
|
58 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
59 | + $tags = $this->systemTagManager->getAllTags( |
|
60 | + $input->getOption('visibilityFilter'), |
|
61 | + $input->getOption('nameSearchPattern') |
|
62 | + ); |
|
63 | 63 | |
64 | - $this->writeArrayInOutputFormat($input, $output, $this->formatTags($tags)); |
|
65 | - return 0; |
|
66 | - } |
|
64 | + $this->writeArrayInOutputFormat($input, $output, $this->formatTags($tags)); |
|
65 | + return 0; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param ISystemtag[] $tags |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - private function formatTags(array $tags): array { |
|
73 | - $result = []; |
|
68 | + /** |
|
69 | + * @param ISystemtag[] $tags |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + private function formatTags(array $tags): array { |
|
73 | + $result = []; |
|
74 | 74 | |
75 | - foreach ($tags as $tag) { |
|
76 | - $result[$tag->getId()] = [ |
|
77 | - 'name' => $tag->getName(), |
|
78 | - 'access' => ISystemTag::ACCESS_LEVEL_LOOKUP[$tag->getAccessLevel()], |
|
79 | - ]; |
|
80 | - } |
|
81 | - return $result; |
|
82 | - } |
|
75 | + foreach ($tags as $tag) { |
|
76 | + $result[$tag->getId()] = [ |
|
77 | + 'name' => $tag->getName(), |
|
78 | + 'access' => ISystemTag::ACCESS_LEVEL_LOOKUP[$tag->getAccessLevel()], |
|
79 | + ]; |
|
80 | + } |
|
81 | + return $result; |
|
82 | + } |
|
83 | 83 | } |
@@ -30,27 +30,27 @@ |
||
30 | 30 | use Symfony\Component\Console\Output\OutputInterface; |
31 | 31 | |
32 | 32 | class RemoveCertificate extends Base { |
33 | - public function __construct( |
|
34 | - protected ICertificateManager $certificateManager, |
|
35 | - ) { |
|
36 | - parent::__construct(); |
|
37 | - } |
|
33 | + public function __construct( |
|
34 | + protected ICertificateManager $certificateManager, |
|
35 | + ) { |
|
36 | + parent::__construct(); |
|
37 | + } |
|
38 | 38 | |
39 | - protected function configure() { |
|
40 | - $this |
|
41 | - ->setName('security:certificates:remove') |
|
42 | - ->setDescription('remove trusted certificate') |
|
43 | - ->addArgument( |
|
44 | - 'name', |
|
45 | - InputArgument::REQUIRED, |
|
46 | - 'the file name of the certificate to remove' |
|
47 | - ); |
|
48 | - } |
|
39 | + protected function configure() { |
|
40 | + $this |
|
41 | + ->setName('security:certificates:remove') |
|
42 | + ->setDescription('remove trusted certificate') |
|
43 | + ->addArgument( |
|
44 | + 'name', |
|
45 | + InputArgument::REQUIRED, |
|
46 | + 'the file name of the certificate to remove' |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
51 | - $name = $input->getArgument('name'); |
|
50 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
51 | + $name = $input->getArgument('name'); |
|
52 | 52 | |
53 | - $this->certificateManager->removeCertificate($name); |
|
54 | - return 0; |
|
55 | - } |
|
53 | + $this->certificateManager->removeCertificate($name); |
|
54 | + return 0; |
|
55 | + } |
|
56 | 56 | } |
@@ -26,56 +26,56 @@ |
||
26 | 26 | use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
27 | 27 | |
28 | 28 | abstract class Base extends \OC\Core\Command\Base { |
29 | - public function __construct( |
|
30 | - protected SystemConfig $systemConfig, |
|
31 | - ) { |
|
32 | - parent::__construct(); |
|
33 | - } |
|
29 | + public function __construct( |
|
30 | + protected SystemConfig $systemConfig, |
|
31 | + ) { |
|
32 | + parent::__construct(); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $argumentName |
|
37 | - * @param CompletionContext $context |
|
38 | - * @return string[] |
|
39 | - */ |
|
40 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
41 | - if ($argumentName === 'name') { |
|
42 | - $words = $this->getPreviousNames($context, $context->getWordIndex()); |
|
43 | - if (empty($words)) { |
|
44 | - $completions = $this->systemConfig->getKeys(); |
|
45 | - } else { |
|
46 | - $key = array_shift($words); |
|
47 | - $value = $this->systemConfig->getValue($key); |
|
48 | - $completions = array_keys($value); |
|
35 | + /** |
|
36 | + * @param string $argumentName |
|
37 | + * @param CompletionContext $context |
|
38 | + * @return string[] |
|
39 | + */ |
|
40 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
41 | + if ($argumentName === 'name') { |
|
42 | + $words = $this->getPreviousNames($context, $context->getWordIndex()); |
|
43 | + if (empty($words)) { |
|
44 | + $completions = $this->systemConfig->getKeys(); |
|
45 | + } else { |
|
46 | + $key = array_shift($words); |
|
47 | + $value = $this->systemConfig->getValue($key); |
|
48 | + $completions = array_keys($value); |
|
49 | 49 | |
50 | - while (!empty($words) && is_array($value)) { |
|
51 | - $key = array_shift($words); |
|
52 | - if (!isset($value[$key]) || !is_array($value[$key])) { |
|
53 | - break; |
|
54 | - } |
|
50 | + while (!empty($words) && is_array($value)) { |
|
51 | + $key = array_shift($words); |
|
52 | + if (!isset($value[$key]) || !is_array($value[$key])) { |
|
53 | + break; |
|
54 | + } |
|
55 | 55 | |
56 | - $value = $value[$key]; |
|
57 | - $completions = array_keys($value); |
|
58 | - } |
|
59 | - } |
|
56 | + $value = $value[$key]; |
|
57 | + $completions = array_keys($value); |
|
58 | + } |
|
59 | + } |
|
60 | 60 | |
61 | - return $completions; |
|
62 | - } |
|
63 | - return parent::completeArgumentValues($argumentName, $context); |
|
64 | - } |
|
61 | + return $completions; |
|
62 | + } |
|
63 | + return parent::completeArgumentValues($argumentName, $context); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param CompletionContext $context |
|
68 | - * @param int $currentIndex |
|
69 | - * @return string[] |
|
70 | - */ |
|
71 | - protected function getPreviousNames(CompletionContext $context, $currentIndex) { |
|
72 | - $word = $context->getWordAtIndex($currentIndex - 1); |
|
73 | - if ($word === $this->getName() || $currentIndex <= 0) { |
|
74 | - return []; |
|
75 | - } |
|
66 | + /** |
|
67 | + * @param CompletionContext $context |
|
68 | + * @param int $currentIndex |
|
69 | + * @return string[] |
|
70 | + */ |
|
71 | + protected function getPreviousNames(CompletionContext $context, $currentIndex) { |
|
72 | + $word = $context->getWordAtIndex($currentIndex - 1); |
|
73 | + if ($word === $this->getName() || $currentIndex <= 0) { |
|
74 | + return []; |
|
75 | + } |
|
76 | 76 | |
77 | - $words = $this->getPreviousNames($context, $currentIndex - 1); |
|
78 | - $words[] = $word; |
|
79 | - return $words; |
|
80 | - } |
|
77 | + $words = $this->getPreviousNames($context, $currentIndex - 1); |
|
78 | + $words[] = $word; |
|
79 | + return $words; |
|
80 | + } |
|
81 | 81 | } |
@@ -30,83 +30,83 @@ |
||
30 | 30 | use Symfony\Component\Console\Output\OutputInterface; |
31 | 31 | |
32 | 32 | class DeleteConfig extends Base { |
33 | - public function __construct( |
|
34 | - SystemConfig $systemConfig, |
|
35 | - ) { |
|
36 | - parent::__construct($systemConfig); |
|
37 | - } |
|
33 | + public function __construct( |
|
34 | + SystemConfig $systemConfig, |
|
35 | + ) { |
|
36 | + parent::__construct($systemConfig); |
|
37 | + } |
|
38 | 38 | |
39 | - protected function configure() { |
|
40 | - parent::configure(); |
|
39 | + protected function configure() { |
|
40 | + parent::configure(); |
|
41 | 41 | |
42 | - $this |
|
43 | - ->setName('config:system:delete') |
|
44 | - ->setDescription('Delete a system config value') |
|
45 | - ->addArgument( |
|
46 | - 'name', |
|
47 | - InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
48 | - 'Name of the config to delete, specify multiple for array parameter' |
|
49 | - ) |
|
50 | - ->addOption( |
|
51 | - 'error-if-not-exists', |
|
52 | - null, |
|
53 | - InputOption::VALUE_NONE, |
|
54 | - 'Checks whether the config exists before deleting it' |
|
55 | - ) |
|
56 | - ; |
|
57 | - } |
|
42 | + $this |
|
43 | + ->setName('config:system:delete') |
|
44 | + ->setDescription('Delete a system config value') |
|
45 | + ->addArgument( |
|
46 | + 'name', |
|
47 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
48 | + 'Name of the config to delete, specify multiple for array parameter' |
|
49 | + ) |
|
50 | + ->addOption( |
|
51 | + 'error-if-not-exists', |
|
52 | + null, |
|
53 | + InputOption::VALUE_NONE, |
|
54 | + 'Checks whether the config exists before deleting it' |
|
55 | + ) |
|
56 | + ; |
|
57 | + } |
|
58 | 58 | |
59 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | - $configNames = $input->getArgument('name'); |
|
61 | - $configName = $configNames[0]; |
|
59 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | + $configNames = $input->getArgument('name'); |
|
61 | + $configName = $configNames[0]; |
|
62 | 62 | |
63 | - if (count($configNames) > 1) { |
|
64 | - if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
65 | - $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
66 | - return 1; |
|
67 | - } |
|
63 | + if (count($configNames) > 1) { |
|
64 | + if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
65 | + $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
66 | + return 1; |
|
67 | + } |
|
68 | 68 | |
69 | - $value = $this->systemConfig->getValue($configName); |
|
69 | + $value = $this->systemConfig->getValue($configName); |
|
70 | 70 | |
71 | - try { |
|
72 | - $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists')); |
|
73 | - } catch (\UnexpectedValueException $e) { |
|
74 | - $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
75 | - return 1; |
|
76 | - } |
|
71 | + try { |
|
72 | + $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists')); |
|
73 | + } catch (\UnexpectedValueException $e) { |
|
74 | + $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
75 | + return 1; |
|
76 | + } |
|
77 | 77 | |
78 | - $this->systemConfig->setValue($configName, $value); |
|
79 | - $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>'); |
|
80 | - return 0; |
|
81 | - } else { |
|
82 | - if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
83 | - $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>'); |
|
84 | - return 1; |
|
85 | - } |
|
78 | + $this->systemConfig->setValue($configName, $value); |
|
79 | + $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>'); |
|
80 | + return 0; |
|
81 | + } else { |
|
82 | + if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
83 | + $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>'); |
|
84 | + return 1; |
|
85 | + } |
|
86 | 86 | |
87 | - $this->systemConfig->deleteValue($configName); |
|
88 | - $output->writeln('<info>System config value ' . $configName . ' deleted</info>'); |
|
89 | - return 0; |
|
90 | - } |
|
91 | - } |
|
87 | + $this->systemConfig->deleteValue($configName); |
|
88 | + $output->writeln('<info>System config value ' . $configName . ' deleted</info>'); |
|
89 | + return 0; |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - protected function removeSubValue($keys, $currentValue, $throwError) { |
|
94 | - $nextKey = array_shift($keys); |
|
93 | + protected function removeSubValue($keys, $currentValue, $throwError) { |
|
94 | + $nextKey = array_shift($keys); |
|
95 | 95 | |
96 | - if (is_array($currentValue)) { |
|
97 | - if (isset($currentValue[$nextKey])) { |
|
98 | - if (empty($keys)) { |
|
99 | - unset($currentValue[$nextKey]); |
|
100 | - } else { |
|
101 | - $currentValue[$nextKey] = $this->removeSubValue($keys, $currentValue[$nextKey], $throwError); |
|
102 | - } |
|
103 | - } elseif ($throwError) { |
|
104 | - throw new \UnexpectedValueException('Config parameter does not exist'); |
|
105 | - } |
|
106 | - } elseif ($throwError) { |
|
107 | - throw new \UnexpectedValueException('Config parameter does not exist'); |
|
108 | - } |
|
96 | + if (is_array($currentValue)) { |
|
97 | + if (isset($currentValue[$nextKey])) { |
|
98 | + if (empty($keys)) { |
|
99 | + unset($currentValue[$nextKey]); |
|
100 | + } else { |
|
101 | + $currentValue[$nextKey] = $this->removeSubValue($keys, $currentValue[$nextKey], $throwError); |
|
102 | + } |
|
103 | + } elseif ($throwError) { |
|
104 | + throw new \UnexpectedValueException('Config parameter does not exist'); |
|
105 | + } |
|
106 | + } elseif ($throwError) { |
|
107 | + throw new \UnexpectedValueException('Config parameter does not exist'); |
|
108 | + } |
|
109 | 109 | |
110 | - return $currentValue; |
|
111 | - } |
|
110 | + return $currentValue; |
|
111 | + } |
|
112 | 112 | } |
@@ -34,63 +34,63 @@ |
||
34 | 34 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 35 | |
36 | 36 | class AddUser extends Base { |
37 | - public function __construct( |
|
38 | - protected IUserManager $userManager, |
|
39 | - protected IGroupManager $groupManager, |
|
40 | - ) { |
|
41 | - parent::__construct(); |
|
42 | - } |
|
37 | + public function __construct( |
|
38 | + protected IUserManager $userManager, |
|
39 | + protected IGroupManager $groupManager, |
|
40 | + ) { |
|
41 | + parent::__construct(); |
|
42 | + } |
|
43 | 43 | |
44 | - protected function configure() { |
|
45 | - $this |
|
46 | - ->setName('group:adduser') |
|
47 | - ->setDescription('add a user to a group') |
|
48 | - ->addArgument( |
|
49 | - 'group', |
|
50 | - InputArgument::REQUIRED, |
|
51 | - 'group to add the user to' |
|
52 | - )->addArgument( |
|
53 | - 'user', |
|
54 | - InputArgument::REQUIRED, |
|
55 | - 'user to add to the group' |
|
56 | - ); |
|
57 | - } |
|
44 | + protected function configure() { |
|
45 | + $this |
|
46 | + ->setName('group:adduser') |
|
47 | + ->setDescription('add a user to a group') |
|
48 | + ->addArgument( |
|
49 | + 'group', |
|
50 | + InputArgument::REQUIRED, |
|
51 | + 'group to add the user to' |
|
52 | + )->addArgument( |
|
53 | + 'user', |
|
54 | + InputArgument::REQUIRED, |
|
55 | + 'user to add to the group' |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | - $group = $this->groupManager->get($input->getArgument('group')); |
|
61 | - if (is_null($group)) { |
|
62 | - $output->writeln('<error>group not found</error>'); |
|
63 | - return 1; |
|
64 | - } |
|
65 | - $user = $this->userManager->get($input->getArgument('user')); |
|
66 | - if (is_null($user)) { |
|
67 | - $output->writeln('<error>user not found</error>'); |
|
68 | - return 1; |
|
69 | - } |
|
70 | - $group->addUser($user); |
|
71 | - return 0; |
|
72 | - } |
|
59 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | + $group = $this->groupManager->get($input->getArgument('group')); |
|
61 | + if (is_null($group)) { |
|
62 | + $output->writeln('<error>group not found</error>'); |
|
63 | + return 1; |
|
64 | + } |
|
65 | + $user = $this->userManager->get($input->getArgument('user')); |
|
66 | + if (is_null($user)) { |
|
67 | + $output->writeln('<error>user not found</error>'); |
|
68 | + return 1; |
|
69 | + } |
|
70 | + $group->addUser($user); |
|
71 | + return 0; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $argumentName |
|
76 | - * @param CompletionContext $context |
|
77 | - * @return string[] |
|
78 | - */ |
|
79 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
80 | - if ($argumentName === 'group') { |
|
81 | - return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
82 | - } |
|
83 | - if ($argumentName === 'user') { |
|
84 | - $groupId = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
85 | - $group = $this->groupManager->get($groupId); |
|
86 | - if ($group === null) { |
|
87 | - return []; |
|
88 | - } |
|
74 | + /** |
|
75 | + * @param string $argumentName |
|
76 | + * @param CompletionContext $context |
|
77 | + * @return string[] |
|
78 | + */ |
|
79 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
80 | + if ($argumentName === 'group') { |
|
81 | + return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
82 | + } |
|
83 | + if ($argumentName === 'user') { |
|
84 | + $groupId = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
85 | + $group = $this->groupManager->get($groupId); |
|
86 | + if ($group === null) { |
|
87 | + return []; |
|
88 | + } |
|
89 | 89 | |
90 | - $members = array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord())); |
|
91 | - $users = array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord())); |
|
92 | - return array_diff($users, $members); |
|
93 | - } |
|
94 | - return []; |
|
95 | - } |
|
90 | + $members = array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord())); |
|
91 | + $users = array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord())); |
|
92 | + return array_diff($users, $members); |
|
93 | + } |
|
94 | + return []; |
|
95 | + } |
|
96 | 96 | } |
@@ -36,48 +36,48 @@ |
||
36 | 36 | use Symfony\Component\Console\Output\OutputInterface; |
37 | 37 | |
38 | 38 | class Add extends Base { |
39 | - public function __construct( |
|
40 | - protected IGroupManager $groupManager, |
|
41 | - ) { |
|
42 | - parent::__construct(); |
|
43 | - } |
|
39 | + public function __construct( |
|
40 | + protected IGroupManager $groupManager, |
|
41 | + ) { |
|
42 | + parent::__construct(); |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('group:add') |
|
48 | - ->setDescription('Add a group') |
|
49 | - ->addArgument( |
|
50 | - 'groupid', |
|
51 | - InputArgument::REQUIRED, |
|
52 | - 'Group id' |
|
53 | - ) |
|
54 | - ->addOption( |
|
55 | - 'display-name', |
|
56 | - null, |
|
57 | - InputOption::VALUE_REQUIRED, |
|
58 | - 'Group name used in the web UI (can contain any characters)' |
|
59 | - ); |
|
60 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('group:add') |
|
48 | + ->setDescription('Add a group') |
|
49 | + ->addArgument( |
|
50 | + 'groupid', |
|
51 | + InputArgument::REQUIRED, |
|
52 | + 'Group id' |
|
53 | + ) |
|
54 | + ->addOption( |
|
55 | + 'display-name', |
|
56 | + null, |
|
57 | + InputOption::VALUE_REQUIRED, |
|
58 | + 'Group name used in the web UI (can contain any characters)' |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | - $gid = $input->getArgument('groupid'); |
|
64 | - $group = $this->groupManager->get($gid); |
|
65 | - if ($group) { |
|
66 | - $output->writeln('<error>Group "' . $gid . '" already exists.</error>'); |
|
67 | - return 1; |
|
68 | - } else { |
|
69 | - $group = $this->groupManager->createGroup($gid); |
|
70 | - if (!$group instanceof IGroup) { |
|
71 | - $output->writeln('<error>Could not create group</error>'); |
|
72 | - return 2; |
|
73 | - } |
|
74 | - $output->writeln('Created group "' . $group->getGID() . '"'); |
|
62 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
63 | + $gid = $input->getArgument('groupid'); |
|
64 | + $group = $this->groupManager->get($gid); |
|
65 | + if ($group) { |
|
66 | + $output->writeln('<error>Group "' . $gid . '" already exists.</error>'); |
|
67 | + return 1; |
|
68 | + } else { |
|
69 | + $group = $this->groupManager->createGroup($gid); |
|
70 | + if (!$group instanceof IGroup) { |
|
71 | + $output->writeln('<error>Could not create group</error>'); |
|
72 | + return 2; |
|
73 | + } |
|
74 | + $output->writeln('Created group "' . $group->getGID() . '"'); |
|
75 | 75 | |
76 | - $displayName = trim((string)$input->getOption('display-name')); |
|
77 | - if ($displayName !== '') { |
|
78 | - $group->setDisplayName($displayName); |
|
79 | - } |
|
80 | - } |
|
81 | - return 0; |
|
82 | - } |
|
76 | + $displayName = trim((string)$input->getOption('display-name')); |
|
77 | + if ($displayName !== '') { |
|
78 | + $group->setDisplayName($displayName); |
|
79 | + } |
|
80 | + } |
|
81 | + return 0; |
|
82 | + } |
|
83 | 83 | } |
@@ -35,56 +35,56 @@ |
||
35 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | 36 | |
37 | 37 | class Info extends Base { |
38 | - public function __construct( |
|
39 | - protected IGroupManager $groupManager, |
|
40 | - ) { |
|
41 | - parent::__construct(); |
|
42 | - } |
|
38 | + public function __construct( |
|
39 | + protected IGroupManager $groupManager, |
|
40 | + ) { |
|
41 | + parent::__construct(); |
|
42 | + } |
|
43 | 43 | |
44 | - protected function configure() { |
|
45 | - $this |
|
46 | - ->setName('group:info') |
|
47 | - ->setDescription('Show information about a group') |
|
48 | - ->addArgument( |
|
49 | - 'groupid', |
|
50 | - InputArgument::REQUIRED, |
|
51 | - 'Group id' |
|
52 | - )->addOption( |
|
53 | - 'output', |
|
54 | - null, |
|
55 | - InputOption::VALUE_OPTIONAL, |
|
56 | - 'Output format (plain, json or json_pretty, default is plain)', |
|
57 | - $this->defaultOutputFormat |
|
58 | - ); |
|
59 | - } |
|
44 | + protected function configure() { |
|
45 | + $this |
|
46 | + ->setName('group:info') |
|
47 | + ->setDescription('Show information about a group') |
|
48 | + ->addArgument( |
|
49 | + 'groupid', |
|
50 | + InputArgument::REQUIRED, |
|
51 | + 'Group id' |
|
52 | + )->addOption( |
|
53 | + 'output', |
|
54 | + null, |
|
55 | + InputOption::VALUE_OPTIONAL, |
|
56 | + 'Output format (plain, json or json_pretty, default is plain)', |
|
57 | + $this->defaultOutputFormat |
|
58 | + ); |
|
59 | + } |
|
60 | 60 | |
61 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
62 | - $gid = $input->getArgument('groupid'); |
|
63 | - $group = $this->groupManager->get($gid); |
|
64 | - if (!$group instanceof IGroup) { |
|
65 | - $output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
66 | - return 1; |
|
67 | - } else { |
|
68 | - $groupOutput = [ |
|
69 | - 'groupID' => $gid, |
|
70 | - 'displayName' => $group->getDisplayName(), |
|
71 | - 'backends' => $group->getBackendNames(), |
|
72 | - ]; |
|
61 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
62 | + $gid = $input->getArgument('groupid'); |
|
63 | + $group = $this->groupManager->get($gid); |
|
64 | + if (!$group instanceof IGroup) { |
|
65 | + $output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
66 | + return 1; |
|
67 | + } else { |
|
68 | + $groupOutput = [ |
|
69 | + 'groupID' => $gid, |
|
70 | + 'displayName' => $group->getDisplayName(), |
|
71 | + 'backends' => $group->getBackendNames(), |
|
72 | + ]; |
|
73 | 73 | |
74 | - $this->writeArrayInOutputFormat($input, $output, $groupOutput); |
|
75 | - return 0; |
|
76 | - } |
|
77 | - } |
|
74 | + $this->writeArrayInOutputFormat($input, $output, $groupOutput); |
|
75 | + return 0; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param string $argumentName |
|
81 | - * @param CompletionContext $context |
|
82 | - * @return string[] |
|
83 | - */ |
|
84 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
85 | - if ($argumentName === 'groupid') { |
|
86 | - return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
87 | - } |
|
88 | - return []; |
|
89 | - } |
|
79 | + /** |
|
80 | + * @param string $argumentName |
|
81 | + * @param CompletionContext $context |
|
82 | + * @return string[] |
|
83 | + */ |
|
84 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
85 | + if ($argumentName === 'groupid') { |
|
86 | + return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
87 | + } |
|
88 | + return []; |
|
89 | + } |
|
90 | 90 | } |
@@ -35,52 +35,52 @@ |
||
35 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | 36 | |
37 | 37 | class Delete extends Base { |
38 | - public function __construct( |
|
39 | - protected IGroupManager $groupManager, |
|
40 | - ) { |
|
41 | - parent::__construct(); |
|
42 | - } |
|
38 | + public function __construct( |
|
39 | + protected IGroupManager $groupManager, |
|
40 | + ) { |
|
41 | + parent::__construct(); |
|
42 | + } |
|
43 | 43 | |
44 | - protected function configure() { |
|
45 | - $this |
|
46 | - ->setName('group:delete') |
|
47 | - ->setDescription('Remove a group') |
|
48 | - ->addArgument( |
|
49 | - 'groupid', |
|
50 | - InputArgument::REQUIRED, |
|
51 | - 'Group name' |
|
52 | - ); |
|
53 | - } |
|
44 | + protected function configure() { |
|
45 | + $this |
|
46 | + ->setName('group:delete') |
|
47 | + ->setDescription('Remove a group') |
|
48 | + ->addArgument( |
|
49 | + 'groupid', |
|
50 | + InputArgument::REQUIRED, |
|
51 | + 'Group name' |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
56 | - $gid = $input->getArgument('groupid'); |
|
57 | - if ($gid === 'admin') { |
|
58 | - $output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>'); |
|
59 | - return 1; |
|
60 | - } |
|
61 | - if (!$this->groupManager->groupExists($gid)) { |
|
62 | - $output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
63 | - return 1; |
|
64 | - } |
|
65 | - $group = $this->groupManager->get($gid); |
|
66 | - if ($group->delete()) { |
|
67 | - $output->writeln('Group "' . $gid . '" was removed'); |
|
68 | - } else { |
|
69 | - $output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>'); |
|
70 | - return 1; |
|
71 | - } |
|
72 | - return 0; |
|
73 | - } |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
56 | + $gid = $input->getArgument('groupid'); |
|
57 | + if ($gid === 'admin') { |
|
58 | + $output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>'); |
|
59 | + return 1; |
|
60 | + } |
|
61 | + if (!$this->groupManager->groupExists($gid)) { |
|
62 | + $output->writeln('<error>Group "' . $gid . '" does not exist.</error>'); |
|
63 | + return 1; |
|
64 | + } |
|
65 | + $group = $this->groupManager->get($gid); |
|
66 | + if ($group->delete()) { |
|
67 | + $output->writeln('Group "' . $gid . '" was removed'); |
|
68 | + } else { |
|
69 | + $output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>'); |
|
70 | + return 1; |
|
71 | + } |
|
72 | + return 0; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param string $argumentName |
|
77 | - * @param CompletionContext $context |
|
78 | - * @return string[] |
|
79 | - */ |
|
80 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
81 | - if ($argumentName === 'groupid') { |
|
82 | - return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
83 | - } |
|
84 | - return []; |
|
85 | - } |
|
75 | + /** |
|
76 | + * @param string $argumentName |
|
77 | + * @param CompletionContext $context |
|
78 | + * @return string[] |
|
79 | + */ |
|
80 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
81 | + if ($argumentName === 'groupid') { |
|
82 | + return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
83 | + } |
|
84 | + return []; |
|
85 | + } |
|
86 | 86 | } |
@@ -34,60 +34,60 @@ |
||
34 | 34 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 35 | |
36 | 36 | class RemoveUser extends Base { |
37 | - public function __construct( |
|
38 | - protected IUserManager $userManager, |
|
39 | - protected IGroupManager $groupManager, |
|
40 | - ) { |
|
41 | - parent::__construct(); |
|
42 | - } |
|
37 | + public function __construct( |
|
38 | + protected IUserManager $userManager, |
|
39 | + protected IGroupManager $groupManager, |
|
40 | + ) { |
|
41 | + parent::__construct(); |
|
42 | + } |
|
43 | 43 | |
44 | - protected function configure() { |
|
45 | - $this |
|
46 | - ->setName('group:removeuser') |
|
47 | - ->setDescription('remove a user from a group') |
|
48 | - ->addArgument( |
|
49 | - 'group', |
|
50 | - InputArgument::REQUIRED, |
|
51 | - 'group to remove the user from' |
|
52 | - )->addArgument( |
|
53 | - 'user', |
|
54 | - InputArgument::REQUIRED, |
|
55 | - 'user to remove from the group' |
|
56 | - ); |
|
57 | - } |
|
44 | + protected function configure() { |
|
45 | + $this |
|
46 | + ->setName('group:removeuser') |
|
47 | + ->setDescription('remove a user from a group') |
|
48 | + ->addArgument( |
|
49 | + 'group', |
|
50 | + InputArgument::REQUIRED, |
|
51 | + 'group to remove the user from' |
|
52 | + )->addArgument( |
|
53 | + 'user', |
|
54 | + InputArgument::REQUIRED, |
|
55 | + 'user to remove from the group' |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | - $group = $this->groupManager->get($input->getArgument('group')); |
|
61 | - if (is_null($group)) { |
|
62 | - $output->writeln('<error>group not found</error>'); |
|
63 | - return 1; |
|
64 | - } |
|
65 | - $user = $this->userManager->get($input->getArgument('user')); |
|
66 | - if (is_null($user)) { |
|
67 | - $output->writeln('<error>user not found</error>'); |
|
68 | - return 1; |
|
69 | - } |
|
70 | - $group->removeUser($user); |
|
71 | - return 0; |
|
72 | - } |
|
59 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
60 | + $group = $this->groupManager->get($input->getArgument('group')); |
|
61 | + if (is_null($group)) { |
|
62 | + $output->writeln('<error>group not found</error>'); |
|
63 | + return 1; |
|
64 | + } |
|
65 | + $user = $this->userManager->get($input->getArgument('user')); |
|
66 | + if (is_null($user)) { |
|
67 | + $output->writeln('<error>user not found</error>'); |
|
68 | + return 1; |
|
69 | + } |
|
70 | + $group->removeUser($user); |
|
71 | + return 0; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $argumentName |
|
76 | - * @param CompletionContext $context |
|
77 | - * @return string[] |
|
78 | - */ |
|
79 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
80 | - if ($argumentName === 'group') { |
|
81 | - return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
82 | - } |
|
83 | - if ($argumentName === 'user') { |
|
84 | - $groupId = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
85 | - $group = $this->groupManager->get($groupId); |
|
86 | - if ($group === null) { |
|
87 | - return []; |
|
88 | - } |
|
89 | - return array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord())); |
|
90 | - } |
|
91 | - return []; |
|
92 | - } |
|
74 | + /** |
|
75 | + * @param string $argumentName |
|
76 | + * @param CompletionContext $context |
|
77 | + * @return string[] |
|
78 | + */ |
|
79 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
80 | + if ($argumentName === 'group') { |
|
81 | + return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord())); |
|
82 | + } |
|
83 | + if ($argumentName === 'user') { |
|
84 | + $groupId = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
85 | + $group = $this->groupManager->get($groupId); |
|
86 | + if ($group === null) { |
|
87 | + return []; |
|
88 | + } |
|
89 | + return array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord())); |
|
90 | + } |
|
91 | + return []; |
|
92 | + } |
|
93 | 93 | } |