Skip to content

Commit b1a28af

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

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

apps/files_sharing/lib/Listener/SharesUpdatedListener.php

Lines changed: 20 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,9 @@ 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) {
5657
foreach ($this->shareManager->getUsersForShare($event->getShare()) as $user) {
57-
$this->updateForUser($user);
58+
$this->updateForShare($user, $event->getShare());
5859
}
5960
}
6061
}
@@ -80,4 +81,21 @@ private function updateForUser(IUser $user): void {
8081
}
8182
}
8283
}
84+
85+
private function updateForShare(IUser $user, IShare $share): void {
86+
if (isset($this->updatedUsers[$user->getUID()])) {
87+
return;
88+
}
89+
$this->updatedUsers[$user->getUID()] = true;
90+
91+
$cachedMounts = $this->userMountCache->getMountsForUser($user);
92+
$mountPoints = array_map(fn (ICachedMountInfo $mount) => $mount->getMountPoint(), $cachedMounts);
93+
$mountsByPath = array_combine($mountPoints, $cachedMounts);
94+
95+
$mountPoint = '/' . $user->getUID() . '/files/' . trim($share->getTarget(), '/') . '/';
96+
$mountKey = $share->getNodeId() . '::' . $mountPoint;
97+
if (!isset($cachedMounts[$mountKey])) {
98+
$this->shareTargetValidator->verifyMountPoint($user, $share, $mountsByPath, []);
99+
}
100+
}
83101
}

0 commit comments

Comments
 (0)