Skip to content

Commit 054c5c0

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

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

apps/files_sharing/lib/Listener/SharesUpdatedListener.php

Lines changed: 24 additions & 2 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,13 @@ 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+
if ($event instanceof ShareCreatedEvent) {
57+
$share = $event->getShare();
58+
$shareTarget = $share->getTarget();
5659
foreach ($this->shareManager->getUsersForShare($event->getShare()) as $user) {
57-
$this->updateForUser($user);
60+
$this->updateForShare($user, $share);
61+
// Share target validation might have changed the target, restore it for the next user
62+
$share->setTarget($shareTarget);
5863
}
5964
}
6065
}
@@ -80,4 +85,21 @@ private function updateForUser(IUser $user): void {
8085
}
8186
}
8287
}
88+
89+
private function updateForShare(IUser $user, IShare $share): void {
90+
if (isset($this->updatedUsers[$user->getUID()])) {
91+
return;
92+
}
93+
$this->updatedUsers[$user->getUID()] = true;
94+
95+
$cachedMounts = $this->userMountCache->getMountsForUser($user);
96+
$mountPoints = array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts);
97+
$mountsByPath = array_combine($mountPoints, $cachedMounts);
98+
99+
$mountPoint = '/' . $user->getUID() . '/files/' . trim($share->getTarget(), '/') . '/';
100+
$mountKey = $share->getNodeId() . '::' . $mountPoint;
101+
if (!isset($cachedMounts[$mountKey])) {
102+
$this->shareTargetValidator->verifyMountPoint($user, $share, $mountsByPath, [$share]);
103+
}
104+
}
83105
}

0 commit comments

Comments
 (0)