diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-06-10 13:26:09 +0300 |
---|---|---|
committer | backportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com> | 2022-06-21 01:40:37 +0300 |
commit | e6c27dac35324f22b32bdabc2844dc6c9c89b49f (patch) | |
tree | f7a1ab0a4605d62949535b8ac16fcdbb3c43175b | |
parent | cfa9b2a26683a933ec540d9b9802d74054c44fda (diff) |
Display group names in occ outputbackport/2022/stable24
This is also what is displayed in the webui
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
-rw-r--r-- | lib/Command/ListCommand.php | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/Command/ListCommand.php b/lib/Command/ListCommand.php index fd61fd77..39ffdf06 100644 --- a/lib/Command/ListCommand.php +++ b/lib/Command/ListCommand.php @@ -27,6 +27,7 @@ use OC\Core\Command\Base; use OCA\GroupFolders\Folder\FolderManager; use OCP\Constants; use OCP\Files\IRootFolder; +use OCP\IGroupManager; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -41,11 +42,13 @@ class ListCommand extends Base { private FolderManager $folderManager; private IRootFolder $rootFolder; + private IGroupManager $groupManager; - public function __construct(FolderManager $folderManager, IRootFolder $rootFolder) { + public function __construct(FolderManager $folderManager, IRootFolder $rootFolder, IGroupManager $groupManager) { parent::__construct(); $this->folderManager = $folderManager; $this->rootFolder = $rootFolder; + $this->groupManager = $groupManager; } protected function configure() { @@ -56,6 +59,11 @@ class ListCommand extends Base { } protected function execute(InputInterface $input, OutputInterface $output) { + $groups = $this->groupManager->search(''); + $groupNames = []; + foreach ($groups as $group) { + $groupNames[$group->getGID()] = $group->getDisplayName(); + } $folders = $this->folderManager->getAllFoldersWithSize($this->rootFolder->getMountPoint()->getNumericStorageId()); usort($folders, function ($a, $b) { return $a['id'] - $b['id']; @@ -76,11 +84,12 @@ class ListCommand extends Base { } else { $table = new Table($output); $table->setHeaders(['Folder Id', 'Name', 'Groups', 'Quota', 'Size', 'Advanced Permissions', 'Manage advanced permissions']); - $table->setRows(array_map(function ($folder) { + $table->setRows(array_map(function (array $folder) use ($groupNames): array { $folder['size'] = \OCP\Util::humanFileSize($folder['size']); $folder['quota'] = ($folder['quota'] > 0) ? \OCP\Util::humanFileSize($folder['quota']) : 'Unlimited'; - $groupStrings = array_map(function (string $groupId, int $permissions) { - return $groupId . ': ' . $this->permissionsToString($permissions); + $groupStrings = array_map(function (string $groupId, int $permissions) use ($groupNames): string { + $groupName = array_key_exists($groupId, $groupNames) && ($groupNames[$groupId] !== $groupId) ? $groupNames[$groupId] . ' (' . $groupId . ')' : $groupId; + return $groupName . ': ' . $this->permissionsToString($permissions); }, array_keys($folder['groups']), array_values($folder['groups'])); $folder['groups'] = implode("\n", $groupStrings); $folder['acl'] = $folder['acl'] ? 'Enabled' : 'Disabled'; |