mirror of
https://github.com/nextcloud/server.git
synced 2026-03-29 13:53:55 -04:00
fix: only validate mounts for new share
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
d718d68e26
commit
aa9697cdef
2 changed files with 33 additions and 9 deletions
|
|
@ -8,6 +8,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Files_Sharing\Listener;
|
||||
|
||||
use OC\Files\FileInfo;
|
||||
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
|
||||
use OCA\Files_Sharing\MountProvider;
|
||||
use OCA\Files_Sharing\ShareTargetValidator;
|
||||
|
|
@ -23,6 +24,7 @@ use OCP\Share\Events\BeforeShareDeletedEvent;
|
|||
use OCP\Share\Events\ShareCreatedEvent;
|
||||
use OCP\Share\Events\ShareTransferredEvent;
|
||||
use OCP\Share\IManager;
|
||||
use OCP\Share\IShare;
|
||||
|
||||
/**
|
||||
* Listen to various events that can change what shares a user has access to
|
||||
|
|
@ -49,12 +51,15 @@ class SharesUpdatedListener implements IEventListener {
|
|||
if ($event instanceof UserAddedEvent || $event instanceof UserRemovedEvent) {
|
||||
$this->updateForUser($event->getUser(), true);
|
||||
}
|
||||
if (
|
||||
$event instanceof ShareCreatedEvent
|
||||
|| $event instanceof ShareTransferredEvent
|
||||
) {
|
||||
foreach ($this->shareManager->getUsersForShare($event->getShare()) as $user) {
|
||||
$this->updateForUser($user, true);
|
||||
if ($event instanceof ShareCreatedEvent || $event instanceof ShareTransferredEvent) {
|
||||
$share = $event->getShare();
|
||||
$shareTarget = $share->getTarget();
|
||||
foreach ($this->shareManager->getUsersForShare($share) as $user) {
|
||||
if ($share->getSharedBy() !== $user->getUID()) {
|
||||
$this->updateForShare($user, $share);
|
||||
// Share target validation might have changed the target, restore it for the next user
|
||||
$share->setTarget($shareTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($event instanceof BeforeShareDeletedEvent) {
|
||||
|
|
@ -97,4 +102,19 @@ class SharesUpdatedListener implements IEventListener {
|
|||
|
||||
unset($this->inUpdate[$user->getUID()]);
|
||||
}
|
||||
|
||||
private function updateForShare(IUser $user, IShare $share): void {
|
||||
$cachedMounts = $this->userMountCache->getMountsForUser($user);
|
||||
$mountPoints = array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts);
|
||||
$mountsByPath = array_combine($mountPoints, $cachedMounts);
|
||||
|
||||
$target = $this->shareTargetValidator->verifyMountPoint($user, $share, $mountsByPath, [$share]);
|
||||
$mountPoint = '/' . $user->getUID() . '/files/' . trim($target, '/') . '/';
|
||||
|
||||
$fileInfo = $share->getNode();
|
||||
if (!$fileInfo instanceof FileInfo) {
|
||||
throw new \Exception("share node is the wrong fileinfo");
|
||||
}
|
||||
$this->userMountCache->addMount($user, $mountPoint, $fileInfo->getData(), MountProvider::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
namespace OC\Files;
|
||||
|
||||
use OC\Files\Cache\CacheEntry;
|
||||
use OC\Files\Mount\HomeMountPoint;
|
||||
use OCA\Files_Sharing\External\Mount;
|
||||
use OCA\Files_Sharing\ISharedMountPoint;
|
||||
use OCP\Files\Cache\ICacheEntry;
|
||||
use OCP\Files\Mount\IMountPoint;
|
||||
|
|
@ -223,8 +223,12 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
|
|||
return $this->data['type'];
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
public function getData(): ICacheEntry {
|
||||
if ($this->data instanceof ICacheEntry) {
|
||||
return $this->data;
|
||||
} else {
|
||||
return new CacheEntry($this->data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue