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

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php2
-rw-r--r--apps/files_sharing/lib/External/Manager.php3
-rw-r--r--apps/files_sharing/lib/Migration/Version24000Date20220404142216.php56
-rw-r--r--apps/files_sharing/lib/MountProvider.php4
-rw-r--r--apps/files_sharing/lib/SharedMount.php42
-rw-r--r--apps/files_sharing/lib/SharedStorage.php41
6 files changed, 116 insertions, 32 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index a29f8f6a2b2..069cba42bb6 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -1130,7 +1130,7 @@ class ShareAPIController extends OCSController {
if (!$this->hasPermission($newPermissions, Constants::PERMISSION_READ) && (
$this->hasPermission($newPermissions, Constants::PERMISSION_UPDATE) || $this->hasPermission($newPermissions, Constants::PERMISSION_DELETE)
)) {
- throw new OCSBadRequestException($this->l->t('Share must have READ permission if UPDATE or DELETE permission is set.'));
+ throw new OCSBadRequestException($this->l->t('Share must have READ permission if UPDATE or DELETE permission is set'));
}
}
diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php
index a8510321a5a..b9ed4acd57f 100644
--- a/apps/files_sharing/lib/External/Manager.php
+++ b/apps/files_sharing/lib/External/Manager.php
@@ -374,6 +374,7 @@ class Manager {
$this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept');
$event = new FederatedShareAddedEvent($share['remote']);
$this->eventDispatcher->dispatchTyped($event);
+ $this->eventDispatcher->dispatchTyped(new Files\Events\InvalidateMountCacheEvent($this->userManager->get($this->uid)));
$result = true;
}
}
@@ -596,6 +597,8 @@ class Manager {
');
$result = (bool)$query->execute([$target, $targetHash, $sourceHash, $this->uid]);
+ $this->eventDispatcher->dispatchTyped(new Files\Events\InvalidateMountCacheEvent($this->userManager->get($this->uid)));
+
return $result;
}
diff --git a/apps/files_sharing/lib/Migration/Version24000Date20220404142216.php b/apps/files_sharing/lib/Migration/Version24000Date20220404142216.php
new file mode 100644
index 00000000000..05176ebdae9
--- /dev/null
+++ b/apps/files_sharing/lib/Migration/Version24000Date20220404142216.php
@@ -0,0 +1,56 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2022 Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_Sharing\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\IOutput;
+use OCP\Migration\SimpleMigrationStep;
+
+/**
+ * Auto-generated migration step: Please modify to your needs!
+ */
+class Version24000Date20220404142216 extends SimpleMigrationStep {
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $table = $schema->getTable('share_external');
+ $column = $table->getColumn('name');
+ if ($column->getLength() < 4000) {
+ $column->setLength(4000);
+ return $schema;
+ }
+ return null;
+ }
+}
diff --git a/apps/files_sharing/lib/MountProvider.php b/apps/files_sharing/lib/MountProvider.php
index 102e5d96559..27edf5074e1 100644
--- a/apps/files_sharing/lib/MountProvider.php
+++ b/apps/files_sharing/lib/MountProvider.php
@@ -134,7 +134,9 @@ class MountProvider implements IMountProvider {
],
$loader,
$view,
- $foldersExistCache
+ $foldersExistCache,
+ $this->eventDispatcher,
+ $user
);
$event = new ShareMountedEvent($mount);
diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php
index c8f5d0f64ae..60361e25fd0 100644
--- a/apps/files_sharing/lib/SharedMount.php
+++ b/apps/files_sharing/lib/SharedMount.php
@@ -34,7 +34,9 @@ use OC\Files\Mount\MountPoint;
use OC\Files\Mount\MoveableMount;
use OC\Files\View;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Events\InvalidateMountCacheEvent;
use OCP\Files\Storage\IStorageFactory;
+use OCP\IUser;
use OCP\Share\Events\VerifyMountPointEvent;
/**
@@ -51,10 +53,7 @@ class SharedMount extends MountPoint implements MoveableMount {
*/
private $recipientView;
- /**
- * @var string
- */
- private $user;
+ private IUser $user;
/** @var \OCP\Share\IShare */
private $superShare;
@@ -62,22 +61,27 @@ class SharedMount extends MountPoint implements MoveableMount {
/** @var \OCP\Share\IShare[] */
private $groupedShares;
- /**
- * @param string $storage
- * @param SharedMount[] $mountpoints
- * @param array $arguments
- * @param IStorageFactory $loader
- * @param View $recipientView
- */
- public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) {
- $this->user = $arguments['user'];
+ private IEventDispatcher $eventDispatcher;
+
+ public function __construct(
+ $storage,
+ array $mountpoints,
+ $arguments,
+ IStorageFactory $loader,
+ View $recipientView,
+ CappedMemoryCache $folderExistCache,
+ IEventDispatcher $eventDispatcher,
+ IUser $user
+ ) {
+ $this->user = $user;
$this->recipientView = $recipientView;
+ $this->eventDispatcher = $eventDispatcher;
$this->superShare = $arguments['superShare'];
$this->groupedShares = $arguments['groupedShares'];
$newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache);
- $absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
+ $absMountPoint = '/' . $user->getUID() . '/files' . $newMountPoint;
parent::__construct($storage, $absMountPoint, $arguments, $loader, null, null, MountProvider::class);
}
@@ -93,9 +97,7 @@ class SharedMount extends MountPoint implements MoveableMount {
$parent = dirname($share->getTarget());
$event = new VerifyMountPointEvent($share, $this->recipientView, $parent);
- /** @var IEventDispatcher $dispatcher */
- $dispatcher = \OC::$server->query(IEventDispatcher::class);
- $dispatcher->dispatchTyped($event);
+ $this->eventDispatcher->dispatchTyped($event);
$parent = $event->getParent();
if ($folderExistCache->hasKey($parent)) {
@@ -105,7 +107,7 @@ class SharedMount extends MountPoint implements MoveableMount {
$folderExistCache->set($parent, $parentExists);
}
if (!$parentExists) {
- $parent = Helper::getShareFolder($this->recipientView, $this->user);
+ $parent = Helper::getShareFolder($this->recipientView, $this->user->getUID());
}
$newMountPoint = $this->generateUniqueTarget(
@@ -133,8 +135,10 @@ class SharedMount extends MountPoint implements MoveableMount {
foreach ($this->groupedShares as $tmpShare) {
$tmpShare->setTarget($newPath);
- \OC::$server->getShareManager()->moveShare($tmpShare, $this->user);
+ \OC::$server->getShareManager()->moveShare($tmpShare, $this->user->getUID());
}
+
+ $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent($this->user));
}
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php
index 3ded20eb495..6a342f0bdbf 100644
--- a/apps/files_sharing/lib/SharedStorage.php
+++ b/apps/files_sharing/lib/SharedStorage.php
@@ -35,13 +35,15 @@ namespace OCA\Files_Sharing;
use OC\Files\Cache\FailedCache;
use OC\Files\Cache\NullWatcher;
use OC\Files\Cache\Watcher;
-use OC\Files\Filesystem;
+use OCP\Files\Folder;
+use OCP\Files\Node;
use OC\Files\Storage\FailedStorage;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OC\User\NoUserException;
use OCA\Files_External\Config\ExternalMountPoint;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
+use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage;
@@ -88,6 +90,11 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
/** @var boolean */
private $sharingDisabledForUser;
+ /** @var ?Folder $ownerUserFolder */
+ private $ownerUserFolder = null;
+
+ private string $sourcePath = '';
+
public function __construct($arguments) {
$this->ownerView = $arguments['ownerView'];
$this->logger = \OC::$server->getLogger();
@@ -129,14 +136,26 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
}
$this->initialized = true;
try {
- Filesystem::initMountPoints($this->superShare->getShareOwner());
- $storageId = $this->superShare->getNodeCacheEntry() ? $this->superShare->getNodeCacheEntry()->getStorageId() : null;
- $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId(), $storageId);
- [$this->nonMaskedStorage, $this->rootPath] = $this->ownerView->resolvePath($sourcePath);
- $this->storage = new PermissionsMask([
- 'storage' => $this->nonMaskedStorage,
- 'mask' => $this->superShare->getPermissions(),
- ]);
+ /** @var IRootFolder $rootFolder */
+ $rootFolder = \OC::$server->get(IRootFolder::class);
+ $this->ownerUserFolder = $rootFolder->getUserFolder($this->superShare->getShareOwner());
+ $sourceId = $this->superShare->getNodeId();
+ $ownerNodes = $this->ownerUserFolder->getById($sourceId);
+ /** @var Node|false $ownerNode */
+ $ownerNode = current($ownerNodes);
+ if (!$ownerNode) {
+ $this->storage = new FailedStorage(['exception' => new NotFoundException("File by id $sourceId not found")]);
+ $this->cache = new FailedCache();
+ $this->rootPath = '';
+ } else {
+ $this->nonMaskedStorage = $ownerNode->getStorage();
+ $this->sourcePath = $ownerNode->getPath();
+ $this->rootPath = $ownerNode->getInternalPath();
+ $this->storage = new PermissionsMask([
+ 'storage' => $this->nonMaskedStorage,
+ 'mask' => $this->superShare->getPermissions(),
+ ]);
+ }
} catch (NotFoundException $e) {
// original file not accessible or deleted, set FailedStorage
$this->storage = new FailedStorage(['exception' => $e]);
@@ -444,7 +463,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
$targetStorage->acquireLock($targetInternalPath, $type, $provider);
// lock the parent folders of the owner when locking the share as recipient
if ($path === '') {
- $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
+ $sourcePath = $this->ownerUserFolder->getRelativePath($this->sourcePath);
$this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
}
}
@@ -460,7 +479,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedSto
$targetStorage->releaseLock($targetInternalPath, $type, $provider);
// unlock the parent folders of the owner when unlocking the share as recipient
if ($path === '') {
- $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId());
+ $sourcePath = $this->ownerUserFolder->getRelativePath($this->sourcePath);
$this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true);
}
}