summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/MountProvider.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2016-06-15 09:47:33 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2016-08-03 10:16:28 +0200
commit04d546522876de430ffe02c12f8aa3f2ef4455fd (patch)
tree3502c7cb3532f08ade746e831f03515ed10b6002 /apps/files_sharing/lib/MountProvider.php
parent0874460e48fccffe7015d47e39b503504f9aaa24 (diff)
downloadnextcloud-server-04d546522876de430ffe02c12f8aa3f2ef4455fd.tar.gz
nextcloud-server-04d546522876de430ffe02c12f8aa3f2ef4455fd.zip
Group shares with same source and target
Fixes #24575 Note that this is a very limited solution and eventually we want smarter merging!
Diffstat (limited to 'apps/files_sharing/lib/MountProvider.php')
-rw-r--r--apps/files_sharing/lib/MountProvider.php70
1 files changed, 67 insertions, 3 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index 1a08b5e9b65..6bd6cf84d7c 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -75,16 +75,21 @@ class MountProvider implements IMountProvider {
return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID();
});
- $mounts = [];
- foreach ($shares as $share) {
+ $groupedShares = $this->groupShares($shares);
+
+ $superShares = $this->superShares($groupedShares);
+
+ $mounts = [];
+ foreach ($superShares as $share) {
try {
$mounts[] = new SharedMount(
'\OC\Files\Storage\Shared',
$mounts,
[
'user' => $user->getUID(),
- 'newShare' => $share,
+ 'superShare' => $share[0],
+ 'groupedShares' => $share[1],
],
$storageFactory
);
@@ -97,4 +102,63 @@ class MountProvider implements IMountProvider {
// array_filter removes the null values from the array
return array_filter($mounts);
}
+
+ /**
+ * @param \OCP\Share\IShare[] $shares
+ * @return \OCP\Share\IShare[]
+ */
+ private function groupShares(array $shares) {
+ $tmp = [];
+
+ foreach ($shares as $share) {
+ if (!isset($tmp[$share->getNodeId()])) {
+ $tmp[$share->getNodeId()] = [];
+ }
+ $tmp[$share->getNodeId()][$share->getTarget()][] = $share;
+ }
+
+ $result = [];
+ foreach ($tmp as $tmp2) {
+ foreach ($tmp2 as $item) {
+ $result[] = $item;
+ }
+ }
+
+ return $result;
+ }
+
+ /**
+ * Extract super shares
+ *
+ * @param array $shares Array of \OCP\Share\IShare[]
+ * @return array Tuple of [superShare, groupedShares]
+ */
+ private function superShares(array $groupedShares) {
+ $result = [];
+
+ /** @var \OCP\Share\IShare[] $shares */
+ foreach ($groupedShares as $shares) {
+ if (count($shares) === 0) {
+ continue;
+ }
+
+ $superShare = $this->shareManager->newShare();
+
+ $superShare->setId($shares[0]->getId())
+ ->setShareOwner($shares[0]->getShareOwner())
+ ->setNodeId($shares[0]->getNodeId())
+ ->setTarget($shares[0]->getTarget());
+
+ $permissions = 0;
+ foreach ($shares as $share) {
+ $permissions |= $share->getPermissions();
+ }
+
+ $superShare->setPermissions($permissions);
+
+ $result[] = [$superShare, $shares];
+ }
+
+ return $result;
+ }
}