diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-04-13 08:02:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-13 08:02:45 +0200 |
commit | ceefe019a05b1131d3640a8ab03adfe2d12ddf1c (patch) | |
tree | 637d6e40be0487607502ee5d950172ec0a1e6872 /core/Command/Group/AddUser.php | |
parent | c233acce1401df41b43d715def06b8456e04da45 (diff) | |
parent | cfd2e8cc2026222866dd78a77fecd8ed44532634 (diff) | |
download | nextcloud-server-ceefe019a05b1131d3640a8ab03adfe2d12ddf1c.tar.gz nextcloud-server-ceefe019a05b1131d3640a8ab03adfe2d12ddf1c.zip |
Merge pull request #31889 from nextcloud/feature/noid/allow-to-autocomplete-user-and-group-commands
Allow to autocomplete user and group ids in commands
Diffstat (limited to 'core/Command/Group/AddUser.php')
-rw-r--r-- | core/Command/Group/AddUser.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/core/Command/Group/AddUser.php b/core/Command/Group/AddUser.php index b5d0068acc6..141916953ab 100644 --- a/core/Command/Group/AddUser.php +++ b/core/Command/Group/AddUser.php @@ -24,8 +24,11 @@ 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; @@ -75,4 +78,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 []; + } } |