Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-08-22 17:36:58 +0300
committerJoas Schilling <coding@schilljs.com>2019-08-23 14:33:05 +0300
commitfd6cc4a5487124cbb165fe5bd2a77e9174e5af8c (patch)
tree4fa7f064a65804bd16ee55700a10bb25afc28fc9 /lib
parentc63217dfbe05cc729b29d843baae70c975e3aa3c (diff)
Support file calls in groupfolders
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/FilesController.php18
-rw-r--r--lib/Files/Listener.php5
-rw-r--r--lib/Files/Util.php35
3 files changed, 51 insertions, 7 deletions
diff --git a/lib/Controller/FilesController.php b/lib/Controller/FilesController.php
index bc45eda10..be16d07dc 100644
--- a/lib/Controller/FilesController.php
+++ b/lib/Controller/FilesController.php
@@ -89,17 +89,25 @@ class FilesController extends OCSController {
*/
public function getRoom(string $fileId): DataResponse {
$share = $this->util->getAnyDirectShareOfFileAccessibleByUser($fileId, $this->currentUser);
+ $groupFolder = null;
if (!$share) {
- throw new OCSNotFoundException($this->l->t('File is not shared, or shared but not with the user'));
+ $groupFolder = $this->util->getGroupFolderNode($fileId, $this->currentUser);
+ if (!$groupFolder) {
+ throw new OCSNotFoundException($this->l->t('File is not shared, or shared but not with the user'));
+ }
}
try {
$room = $this->manager->getRoomByObject('file', $fileId);
} catch (RoomNotFoundException $e) {
- try {
- $name = $this->getFileName($share, $fileId);
- } catch (NotFoundException $e) {
- throw new OCSNotFoundException($this->l->t('File is not shared, or shared but not with the user'));
+ if ($share) {
+ try {
+ $name = $this->getFileName($share, $fileId);
+ } catch (NotFoundException $e) {
+ throw new OCSNotFoundException($this->l->t('File is not shared, or shared but not with the user'));
+ }
+ } else {
+ $name = $groupFolder->getName();
}
$room = $this->manager->createPublicRoom($name, 'file', $fileId);
}
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;
+ }
+
}