diff options
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 []; + } } |