Skip to content

Commit 4851386

Browse files
committed
fix: only validate mounts for new share
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 18d5ded commit 4851386

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

apps/files_sharing/lib/Listener/SharesUpdatedListener.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OCP\Share\Events\BeforeShareDeletedEvent;
2424
use OCP\Share\Events\ShareCreatedEvent;
2525
use OCP\Share\IManager;
26+
use OCP\Share\IShare;
2627

2728
/**
2829
* Listen to various events that can change what shares a user has access to
@@ -52,9 +53,15 @@ public function handle(Event $event): void {
5253
if ($event instanceof UserAddedEvent || $event instanceof UserRemovedEvent) {
5354
$this->updateForUser($event->getUser());
5455
}
55-
if ($event instanceof ShareCreatedEvent || $event instanceof BeforeShareDeletedEvent) {
56-
foreach ($this->shareManager->getUsersForShare($event->getShare()) as $user) {
57-
$this->updateForUser($user);
56+
if ($event instanceof ShareCreatedEvent) {
57+
$share = $event->getShare();
58+
$shareTarget = $share->getTarget();
59+
foreach ($this->shareManager->getUsersForShare($share) as $user) {
60+
if ($share->getSharedBy() !== $user->getUID()) {
61+
$this->updateForShare($user, $share);
62+
// Share target validation might have changed the target, restore it for the next user
63+
$share->setTarget($shareTarget);
64+
}
5865
}
5966
}
6067
}
@@ -80,4 +87,21 @@ private function updateForUser(IUser $user): void {
8087
}
8188
}
8289
}
90+
91+
private function updateForShare(IUser $user, IShare $share): void {
92+
if (isset($this->updatedUsers[$user->getUID()])) {
93+
return;
94+
}
95+
$this->updatedUsers[$user->getUID()] = true;
96+
97+
$cachedMounts = $this->userMountCache->getMountsForUser($user);
98+
$mountPoints = array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts);
99+
$mountsByPath = array_combine($mountPoints, $cachedMounts);
100+
101+
$mountPoint = '/' . $user->getUID() . '/files/' . trim($share->getTarget(), '/') . '/';
102+
$mountKey = $share->getNodeId() . '::' . $mountPoint;
103+
if (!isset($cachedMounts[$mountKey])) {
104+
$this->shareTargetValidator->verifyMountPoint($user, $share, $mountsByPath, [$share]);
105+
}
106+
}
83107
}

0 commit comments

Comments
 (0)