123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace OC\Encryption;
- use OCA\Files_External\Service\GlobalStoragesService;
- use OCP\App\IAppManager;
- use OCP\Cache\CappedMemoryCache;
- use OCP\Files\IRootFolder;
- use OCP\Files\NotFoundException;
- use OCP\Share\IManager;
- class File implements \OCP\Encryption\IFile {
- protected Util $util;
- private IRootFolder $rootFolder;
- private IManager $shareManager;
-
- protected CappedMemoryCache $cache;
- private ?IAppManager $appManager = null;
- public function __construct(Util $util,
- IRootFolder $rootFolder,
- IManager $shareManager) {
- $this->util = $util;
- $this->cache = new CappedMemoryCache();
- $this->rootFolder = $rootFolder;
- $this->shareManager = $shareManager;
- }
- public function getAppManager(): IAppManager {
-
- if ($this->appManager) {
- return $this->appManager;
- }
- $this->appManager = \OCP\Server::get(IAppManager::class);
- return $this->appManager;
- }
-
- public function getAccessList($path) {
-
- [$owner, $ownerPath] = $this->util->getUidAndFilename($path);
-
- $userIds = [$owner];
- if (!$this->util->isFile($owner . '/' . $ownerPath)) {
- return ['users' => $userIds, 'public' => false];
- }
- $ownerPath = substr($ownerPath, strlen('/files'));
- $userFolder = $this->rootFolder->getUserFolder($owner);
- try {
- $file = $userFolder->get($ownerPath);
- } catch (NotFoundException $e) {
- $file = null;
- }
- $ownerPath = $this->util->stripPartialFileExtension($ownerPath);
-
-
- $parent = dirname($ownerPath);
- $parentNode = $userFolder->get($parent);
- if (isset($this->cache[$parent])) {
- $resultForParents = $this->cache[$parent];
- } else {
- $resultForParents = $this->shareManager->getAccessList($parentNode);
- $this->cache[$parent] = $resultForParents;
- }
- $userIds = array_merge($userIds, $resultForParents['users']);
- $public = $resultForParents['public'] || $resultForParents['remote'];
-
- if ($file !== null) {
- $resultForFile = $this->shareManager->getAccessList($file, false);
- $userIds = array_merge($userIds, $resultForFile['users']);
- $public = $resultForFile['public'] || $resultForFile['remote'] || $public;
- }
-
- if ($this->getAppManager()->isEnabledForUser("files_external")) {
-
- $storageService = \OC::$server->get(GlobalStoragesService::class);
- $storages = $storageService->getAllStorages();
- foreach ($storages as $storage) {
- if ($storage->getMountPoint() == substr($ownerPath, 0, strlen($storage->getMountPoint()))) {
- $mountedFor = $this->util->getUserWithAccessToMountPoint($storage->getApplicableUsers(), $storage->getApplicableGroups());
- $userIds = array_merge($userIds, $mountedFor);
- }
- }
- }
-
- $uniqueUserIds = array_unique($userIds);
- return ['users' => $uniqueUserIds, 'public' => $public];
- }
- }
|