diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 3be7e61d01081..1d9dab96ddcb3 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -8,6 +8,8 @@ namespace OCA\Files\Controller; use OC\Files\FilenameValidator; +use OC\Files\Search\SearchComparison; +use OC\Files\Search\SearchQuery; use OCA\Files\Activity\Helper; use OCA\Files\AppInfo\Application; use OCA\Files\Event\LoadAdditionalScriptsEvent; @@ -26,9 +28,11 @@ use OCP\AppFramework\Services\IInitialState; use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as ResourcesLoadAdditionalScriptsEvent; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\Cache\ICacheEntry; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; +use OCP\Files\Search\ISearchComparison; use OCP\Files\Template\ITemplateManager; use OCP\IConfig; use OCP\IL10N; @@ -160,6 +164,35 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $favElements = []; } + try { + $userFolder = $this->rootFolder->getUserFolder($userId); + $searchQuery = new SearchQuery( + new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE), + 0, + 0, + [], + $this->userSession->getUser(), + false, + ); + /** @var Folder[] $folders */ + $folders = $userFolder->search($searchQuery); + $folderTreeFolders = array_values(array_map(fn (Folder $folder) => [ + 'fileid' => $folder->getId(), + 'displayname' => $folder->getName(), + 'owner' => $folder->getOwner()?->getUID(), + 'path' => $userFolder->getRelativePath($folder->getPath()), + 'parentid' => $folder->getParentId(), + 'mountType' => $folder->getMountPoint()->getMountType(), + 'mime' => $folder->getMimetype(), + 'size' => $folder->getSize(), + 'mtime' => $folder->getMTime(), + 'crtime' => $folder->getCreationTime(), + 'permissions' => $folder->getPermissions(), + ], $folders)); + } catch (\RuntimeException $e) { + $folderTreeFolders = []; + } + // If the file doesn't exists in the folder and // exists in only one occurrence, redirect to that file // in the correct folder @@ -190,6 +223,7 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal $this->initialState->provideInitialState('config', $this->userConfig->getConfigs()); $this->initialState->provideInitialState('viewConfigs', $this->viewConfig->getConfigs()); $this->initialState->provideInitialState('favoriteFolders', $favElements); + $this->initialState->provideInitialState('folderTreeFolders', $folderTreeFolders); // File sorting user config $filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);