aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/lib/MountProvider.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib/MountProvider.php')
-rw-r--r--apps/files_sharing/lib/MountProvider.php74
1 files changed, 45 insertions, 29 deletions
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index b70c16872ee..b7b0582493e 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -11,6 +12,8 @@ use OCA\Files_Sharing\Event\ShareMountedEvent;
use OCP\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProvider;
+use OCP\Files\Mount\IMountManager;
+use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorageFactory;
use OCP\ICacheFactory;
use OCP\IConfig;
@@ -21,7 +24,7 @@ use Psr\Log\LoggerInterface;
class MountProvider implements IMountProvider {
/**
- * @param \OCP\IConfig $config
+ * @param IConfig $config
* @param IManager $shareManager
* @param LoggerInterface $logger
*/
@@ -30,48 +33,56 @@ class MountProvider implements IMountProvider {
protected IManager $shareManager,
protected LoggerInterface $logger,
protected IEventDispatcher $eventDispatcher,
- protected ICacheFactory $cacheFactory
+ protected ICacheFactory $cacheFactory,
+ protected IMountManager $mountManager,
) {
}
/**
* Get all mountpoints applicable for the user and check for shares where we need to update the etags
*
- * @param \OCP\IUser $user
- * @param \OCP\Files\Storage\IStorageFactory $loader
- * @return \OCP\Files\Mount\IMountPoint[]
+ * @param IUser $user
+ * @param IStorageFactory $loader
+ * @return IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
- $shares = $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_USER, null, -1);
- $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP, null, -1));
- $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_CIRCLE, null, -1));
- $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_ROOM, null, -1));
- $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_DECK, null, -1));
- $shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_SCIENCEMESH, null, -1));
-
+ $shares = array_merge(
+ $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_USER, null, -1),
+ $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_GROUP, null, -1),
+ $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_CIRCLE, null, -1),
+ $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_ROOM, null, -1),
+ $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_DECK, null, -1),
+ $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_SCIENCEMESH, null, -1),
+ );
// filter out excluded shares and group shares that includes self
- $shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) {
- return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID();
+ $shares = array_filter($shares, function (IShare $share) use ($user) {
+ return $share->getPermissions() > 0 && $share->getShareOwner() !== $user->getUID() && $share->getSharedBy() !== $user->getUID();
});
$superShares = $this->buildSuperShares($shares, $user);
+ $otherMounts = $this->mountManager->getAll();
$mounts = [];
$view = new View('/' . $user->getUID() . '/files');
$ownerViews = [];
$sharingDisabledForUser = $this->shareManager->sharingDisabledForUser($user->getUID());
/** @var CappedMemoryCache<bool> $folderExistCache */
$foldersExistCache = new CappedMemoryCache();
+
+ $validShareCache = $this->cacheFactory->createLocal('share-valid-mountpoint-max');
+ $maxValidatedShare = $validShareCache->get($user->getUID()) ?? 0;
+ $newMaxValidatedShare = $maxValidatedShare;
+
foreach ($superShares as $share) {
try {
- /** @var \OCP\Share\IShare $parentShare */
+ /** @var IShare $parentShare */
$parentShare = $share[0];
- if ($parentShare->getStatus() !== IShare::STATUS_ACCEPTED &&
- ($parentShare->getShareType() === IShare::TYPE_GROUP ||
- $parentShare->getShareType() === IShare::TYPE_USERGROUP ||
- $parentShare->getShareType() === IShare::TYPE_USER)) {
+ if ($parentShare->getStatus() !== IShare::STATUS_ACCEPTED
+ && ($parentShare->getShareType() === IShare::TYPE_GROUP
+ || $parentShare->getShareType() === IShare::TYPE_USERGROUP
+ || $parentShare->getShareType() === IShare::TYPE_USER)) {
continue;
}
@@ -79,9 +90,10 @@ class MountProvider implements IMountProvider {
if (!isset($ownerViews[$owner])) {
$ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files');
}
+ $shareId = (int)$parentShare->getId();
$mount = new SharedMount(
'\OCA\Files_Sharing\SharedStorage',
- $mounts,
+ array_merge($mounts, $otherMounts),
[
'user' => $user->getUID(),
// parent share
@@ -96,9 +108,11 @@ class MountProvider implements IMountProvider {
$foldersExistCache,
$this->eventDispatcher,
$user,
- $this->cacheFactory->createLocal('share-valid-mountpoint')
+ ($shareId <= $maxValidatedShare),
);
+ $newMaxValidatedShare = max($shareId, $newMaxValidatedShare);
+
$event = new ShareMountedEvent($mount);
$this->eventDispatcher->dispatchTyped($event);
@@ -117,6 +131,8 @@ class MountProvider implements IMountProvider {
}
}
+ $validShareCache->set($user->getUID(), $newMaxValidatedShare, 24 * 60 * 60);
+
// array_filter removes the null values from the array
return array_values(array_filter($mounts));
}
@@ -124,9 +140,9 @@ class MountProvider implements IMountProvider {
/**
* Groups shares by path (nodeId) and target path
*
- * @param \OCP\Share\IShare[] $shares
- * @return \OCP\Share\IShare[][] array of grouped shares, each element in the
- * array is a group which itself is an array of shares
+ * @param IShare[] $shares
+ * @return IShare[][] array of grouped shares, each element in the
+ * array is a group which itself is an array of shares
*/
private function groupShares(array $shares) {
$tmp = [];
@@ -161,16 +177,16 @@ class MountProvider implements IMountProvider {
* grouped shares. The most permissive permissions are used based on the permissions
* of all shares within the group.
*
- * @param \OCP\Share\IShare[] $allShares
- * @param \OCP\IUser $user user
+ * @param IShare[] $allShares
+ * @param IUser $user user
* @return array Tuple of [superShare, groupedShares]
*/
- private function buildSuperShares(array $allShares, \OCP\IUser $user) {
+ private function buildSuperShares(array $allShares, IUser $user) {
$result = [];
$groupedShares = $this->groupShares($allShares);
- /** @var \OCP\Share\IShare[] $shares */
+ /** @var IShare[] $shares */
foreach ($groupedShares as $shares) {
if (count($shares) === 0) {
continue;
@@ -215,7 +231,7 @@ class MountProvider implements IMountProvider {
continue;
}
// update supershare attributes with subshare attribute
- $superAttributes->setAttribute($attribute['scope'], $attribute['key'], $attribute['enabled']);
+ $superAttributes->setAttribute($attribute['scope'], $attribute['key'], $attribute['value']);
}
}