aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Group
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/Group')
-rw-r--r--core/Command/Group/Add.php35
-rw-r--r--core/Command/Group/AddUser.php66
-rw-r--r--core/Command/Group/Delete.php50
-rw-r--r--core/Command/Group/Info.php73
-rw-r--r--core/Command/Group/ListCommand.php88
-rw-r--r--core/Command/Group/RemoveUser.php63
6 files changed, 207 insertions, 168 deletions
diff --git a/core/Command/Group/Add.php b/core/Command/Group/Add.php
index 14b733f9af1..26d44c7ea83 100644
--- a/core/Command/Group/Add.php
+++ b/core/Command/Group/Add.php
@@ -3,29 +3,9 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Denis Mosolov <denismosolov@gmail.com>
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Denis Mosolov <denismosolov@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Core\Command\Group;
use OC\Core\Command\Base;
@@ -37,14 +17,9 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Add extends Base {
- /** @var IGroupManager */
- protected $groupManager;
-
- /**
- * @param IGroupManager $groupManager
- */
- public function __construct(IGroupManager $groupManager) {
- $this->groupManager = $groupManager;
+ public function __construct(
+ protected IGroupManager $groupManager,
+ ) {
parent::__construct();
}
diff --git a/core/Command/Group/AddUser.php b/core/Command/Group/AddUser.php
index a1deb74395f..999113390af 100644
--- a/core/Command/Group/AddUser.php
+++ b/core/Command/Group/AddUser.php
@@ -1,49 +1,26 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Core\Command\Group;
use OC\Core\Command\Base;
+use OCP\IGroup;
use OCP\IGroupManager;
+use OCP\IUser;
use OCP\IUserManager;
+use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class AddUser extends Base {
- /** @var IUserManager */
- protected $userManager;
- /** @var IGroupManager */
- protected $groupManager;
-
- /**
- * @param IUserManager $userManager
- * @param IGroupManager $groupManager
- */
- public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
- $this->userManager = $userManager;
- $this->groupManager = $groupManager;
+ public function __construct(
+ protected IUserManager $userManager,
+ protected IGroupManager $groupManager,
+ ) {
parent::__construct();
}
@@ -76,4 +53,27 @@ class AddUser extends Base {
$group->addUser($user);
return 0;
}
+
+ /**
+ * @param string $argumentName
+ * @param CompletionContext $context
+ * @return string[]
+ */
+ public function completeArgumentValues($argumentName, CompletionContext $context) {
+ if ($argumentName === 'group') {
+ return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
+ }
+ if ($argumentName === 'user') {
+ $groupId = $context->getWordAtIndex($context->getWordIndex() - 1);
+ $group = $this->groupManager->get($groupId);
+ if ($group === null) {
+ return [];
+ }
+
+ $members = array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord()));
+ $users = array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
+ return array_diff($users, $members);
+ }
+ return [];
+ }
}
diff --git a/core/Command/Group/Delete.php b/core/Command/Group/Delete.php
index 8ef88b44442..a2736476920 100644
--- a/core/Command/Group/Delete.php
+++ b/core/Command/Group/Delete.php
@@ -3,45 +3,23 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Denis Mosolov <denismosolov@gmail.com>
- *
- * @author Denis Mosolov <denismosolov@gmail.com>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Core\Command\Group;
use OC\Core\Command\Base;
+use OCP\IGroup;
use OCP\IGroupManager;
+use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Delete extends Base {
- /** @var IGroupManager */
- protected $groupManager;
-
- /**
- * @param IGroupManager $groupManager
- */
- public function __construct(IGroupManager $groupManager) {
- $this->groupManager = $groupManager;
+ public function __construct(
+ protected IGroupManager $groupManager,
+ ) {
parent::__construct();
}
@@ -62,7 +40,7 @@ class Delete extends Base {
$output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>');
return 1;
}
- if (! $this->groupManager->groupExists($gid)) {
+ if (!$this->groupManager->groupExists($gid)) {
$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
return 1;
}
@@ -75,4 +53,16 @@ class Delete extends Base {
}
return 0;
}
+
+ /**
+ * @param string $argumentName
+ * @param CompletionContext $context
+ * @return string[]
+ */
+ public function completeArgumentValues($argumentName, CompletionContext $context) {
+ if ($argumentName === 'groupid') {
+ return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
+ }
+ return [];
+ }
}
diff --git a/core/Command/Group/Info.php b/core/Command/Group/Info.php
new file mode 100644
index 00000000000..d42d2a64577
--- /dev/null
+++ b/core/Command/Group/Info.php
@@ -0,0 +1,73 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Core\Command\Group;
+
+use OC\Core\Command\Base;
+use OCP\IGroup;
+use OCP\IGroupManager;
+use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class Info extends Base {
+ public function __construct(
+ protected IGroupManager $groupManager,
+ ) {
+ parent::__construct();
+ }
+
+ protected function configure() {
+ $this
+ ->setName('group:info')
+ ->setDescription('Show information about a group')
+ ->addArgument(
+ 'groupid',
+ InputArgument::REQUIRED,
+ 'Group id'
+ )->addOption(
+ 'output',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'Output format (plain, json or json_pretty, default is plain)',
+ $this->defaultOutputFormat
+ );
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ $gid = $input->getArgument('groupid');
+ $group = $this->groupManager->get($gid);
+ if (!$group instanceof IGroup) {
+ $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
+ return 1;
+ } else {
+ $groupOutput = [
+ 'groupID' => $gid,
+ 'displayName' => $group->getDisplayName(),
+ 'backends' => $group->getBackendNames(),
+ ];
+
+ $this->writeArrayInOutputFormat($input, $output, $groupOutput);
+ return 0;
+ }
+ }
+
+ /**
+ * @param string $argumentName
+ * @param CompletionContext $context
+ * @return string[]
+ */
+ public function completeArgumentValues($argumentName, CompletionContext $context) {
+ if ($argumentName === 'groupid') {
+ return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
+ }
+ return [];
+ }
+}
diff --git a/core/Command/Group/ListCommand.php b/core/Command/Group/ListCommand.php
index 846c36fab39..01522a23f7f 100644
--- a/core/Command/Group/ListCommand.php
+++ b/core/Command/Group/ListCommand.php
@@ -1,45 +1,23 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Core\Command\Group;
use OC\Core\Command\Base;
use OCP\IGroup;
use OCP\IGroupManager;
+use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ListCommand extends Base {
- /** @var IGroupManager */
- protected $groupManager;
-
- /**
- * @param IGroupManager $groupManager
- */
- public function __construct(IGroupManager $groupManager) {
- $this->groupManager = $groupManager;
+ public function __construct(
+ protected IGroupManager $groupManager,
+ ) {
parent::__construct();
}
@@ -47,18 +25,29 @@ class ListCommand extends Base {
$this
->setName('group:list')
->setDescription('list configured groups')
+ ->addArgument(
+ 'searchstring',
+ InputArgument::OPTIONAL,
+ 'Filter the groups to only those matching the search string',
+ ''
+ )
->addOption(
'limit',
'l',
InputOption::VALUE_OPTIONAL,
'Number of groups to retrieve',
- 500
+ '500'
)->addOption(
'offset',
'o',
InputOption::VALUE_OPTIONAL,
'Offset for retrieving groups',
- 0
+ '0'
+ )->addOption(
+ 'info',
+ 'i',
+ InputOption::VALUE_NONE,
+ 'Show additional info (backend)'
)->addOption(
'output',
null,
@@ -69,22 +58,37 @@ class ListCommand extends Base {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $groups = $this->groupManager->search('', (int)$input->getOption('limit'), (int)$input->getOption('offset'));
- $this->writeArrayInOutputFormat($input, $output, $this->formatGroups($groups));
+ $groups = $this->groupManager->search((string)$input->getArgument('searchstring'), (int)$input->getOption('limit'), (int)$input->getOption('offset'));
+ $this->writeArrayInOutputFormat($input, $output, $this->formatGroups($groups, (bool)$input->getOption('info')));
return 0;
}
/**
+ * @param IGroup $group
+ * @return string[]
+ */
+ public function usersForGroup(IGroup $group) {
+ $users = array_keys($group->getUsers());
+ return array_map(function ($userId) {
+ return (string)$userId;
+ }, $users);
+ }
+
+ /**
* @param IGroup[] $groups
- * @return array
*/
- private function formatGroups(array $groups) {
- $keys = array_map(function (IGroup $group) {
- return $group->getGID();
- }, $groups);
- $values = array_map(function (IGroup $group) {
- return array_keys($group->getUsers());
- }, $groups);
- return array_combine($keys, $values);
+ private function formatGroups(array $groups, bool $addInfo = false): \Generator {
+ foreach ($groups as $group) {
+ if ($addInfo) {
+ $value = [
+ 'displayName' => $group->getDisplayName(),
+ 'backends' => $group->getBackendNames(),
+ 'users' => $this->usersForGroup($group),
+ ];
+ } else {
+ $value = $this->usersForGroup($group);
+ }
+ yield $group->getGID() => $value;
+ }
}
}
diff --git a/core/Command/Group/RemoveUser.php b/core/Command/Group/RemoveUser.php
index cb848effb92..952fc6e7712 100644
--- a/core/Command/Group/RemoveUser.php
+++ b/core/Command/Group/RemoveUser.php
@@ -1,49 +1,26 @@
<?php
+
/**
- * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Core\Command\Group;
use OC\Core\Command\Base;
+use OCP\IGroup;
use OCP\IGroupManager;
+use OCP\IUser;
use OCP\IUserManager;
+use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class RemoveUser extends Base {
- /** @var IUserManager */
- protected $userManager;
- /** @var IGroupManager */
- protected $groupManager;
-
- /**
- * @param IUserManager $userManager
- * @param IGroupManager $groupManager
- */
- public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
- $this->userManager = $userManager;
- $this->groupManager = $groupManager;
+ public function __construct(
+ protected IUserManager $userManager,
+ protected IGroupManager $groupManager,
+ ) {
parent::__construct();
}
@@ -76,4 +53,24 @@ class RemoveUser extends Base {
$group->removeUser($user);
return 0;
}
+
+ /**
+ * @param string $argumentName
+ * @param CompletionContext $context
+ * @return string[]
+ */
+ public function completeArgumentValues($argumentName, CompletionContext $context) {
+ if ($argumentName === 'group') {
+ return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
+ }
+ if ($argumentName === 'user') {
+ $groupId = $context->getWordAtIndex($context->getWordIndex() - 1);
+ $group = $this->groupManager->get($groupId);
+ if ($group === null) {
+ return [];
+ }
+ return array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord()));
+ }
+ return [];
+ }
}