diff options
author | Joas Schilling <coding@schilljs.com> | 2019-08-22 17:36:58 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-08-23 14:33:05 +0300 |
commit | fd6cc4a5487124cbb165fe5bd2a77e9174e5af8c (patch) | |
tree | 4fa7f064a65804bd16ee55700a10bb25afc28fc9 /lib/Files | |
parent | c63217dfbe05cc729b29d843baae70c975e3aa3c (diff) |
Support file calls in groupfolders
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Files')
-rw-r--r-- | lib/Files/Listener.php | 5 | ||||
-rw-r--r-- | lib/Files/Util.php | 35 |
2 files changed, 38 insertions, 2 deletions
diff --git a/lib/Files/Listener.php b/lib/Files/Listener.php index 8b169cb94..caad44a87 100644 --- a/lib/Files/Listener.php +++ b/lib/Files/Listener.php @@ -102,7 +102,10 @@ class Listener { $share = $this->util->getAnyDirectShareOfFileAccessibleByUser($room->getObjectId(), $userId); if (!$share) { - throw new UnauthorizedException('User does not have direct access to the file'); + $groupFolder = $this->util->getGroupFolderNode($room->getObjectId(), $userId); + if (!$groupFolder) { + throw new UnauthorizedException('User does not have direct access to the file'); + } } } diff --git a/lib/Files/Util.php b/lib/Files/Util.php index bb4f20bce..fc546e193 100644 --- a/lib/Files/Util.php +++ b/lib/Files/Util.php @@ -23,6 +23,8 @@ declare(strict_types=1); namespace OCA\Spreed\Files; +use OCA\GroupFolders\Mount\GroupFolderStorage; +use OCP\Files\FileInfo; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -88,7 +90,7 @@ class Util { } $nodes = array_filter($nodes, function($node) { - return $node->getType() === \OCP\Files\FileInfo::TYPE_FILE; + return $node->getType() === FileInfo::TYPE_FILE; }); while (!empty($nodes)) { @@ -169,4 +171,35 @@ class Util { return null; } + /** + * ... + * + * @param string $fileId + * @param string $userId + * @return Node|null + */ + public function getGroupFolderNode(string $fileId, string $userId): ?Node { + $userFolder = $this->rootFolder->getUserFolder($userId); + $nodes = $userFolder->getById($fileId); + if (empty($nodes)) { + return null; + } + + $nodes = array_filter($nodes, function(Node $node) { + return $node->getType() === FileInfo::TYPE_FILE; + }); + + /** @var Node $node */ + $node = array_pop($nodes); + try { + $storage = $node->getStorage(); + if ($storage->instanceOfStorage(GroupFolderStorage::class)) { + return $node; + } + } catch (NotFoundException $e) { + } + + return null; + } + } |