fix: only update share for the user who moved the share

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2026-04-17 14:05:53 +02:00
parent 05d9fe3916
commit 23547109f1
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
4 changed files with 21 additions and 7 deletions

View file

@ -104,11 +104,10 @@ class SharesUpdatedListener implements IEventListener {
}
if ($event instanceof ShareMovedEvent) {
$share = $event->getShare();
foreach ($this->shareManager->getUsersForShare($share) as $user) {
$this->markOrRun($user, function () use ($user, $share) {
$this->shareUpdater->updateForMovedShare($user, $share);
});
}
$user = $event->getUser();
$this->markOrRun($user, function () use ($user, $share) {
$this->shareUpdater->updateForMovedShare($user, $share);
});
}
if ($event instanceof BeforeShareDeletedEvent) {
$share = $event->getShare();

View file

@ -1177,13 +1177,16 @@ class Manager implements IManager {
if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) {
throw new \InvalidArgumentException($this->l->t('Invalid share recipient'));
}
$recipient = $this->userManager->get($recipientId);
if (!$recipient) {
throw new \InvalidArgumentException($this->l->t('Unknown share recipient'));
}
if ($share->getShareType() === IShare::TYPE_GROUP) {
$sharedWith = $this->groupManager->get($share->getSharedWith());
if (is_null($sharedWith)) {
throw new \InvalidArgumentException($this->l->t('Group "%s" does not exist', [$share->getSharedWith()]));
}
$recipient = $this->userManager->get($recipientId);
if (!$sharedWith->inGroup($recipient)) {
throw new \InvalidArgumentException($this->l->t('Invalid share recipient'));
}
@ -1194,7 +1197,7 @@ class Manager implements IManager {
$result = $provider->move($share, $recipientId);
$this->dispatchEvent(new ShareMovedEvent($share), 'share moved');
$this->dispatchEvent(new ShareMovedEvent($share, $recipient), 'share moved');
return $result;
}

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace OCP\Share\Events;
use OCP\EventDispatcher\Event;
use OCP\IUser;
use OCP\Share\IShare;
/**
@ -20,6 +21,7 @@ class ShareMovedEvent extends Event {
*/
public function __construct(
private readonly IShare $share,
private readonly IUser $user,
) {
parent::__construct();
}
@ -30,4 +32,11 @@ class ShareMovedEvent extends Event {
public function getShare(): IShare {
return $this->share;
}
/**
* @since 33.0.0
*/
public function getUser(): IUser {
return $this->user;
}
}

View file

@ -4665,6 +4665,9 @@ class ManagerTest extends \Test\TestCase {
$share->setShareType(IShare::TYPE_USER)
->setId('42')
->setProviderId('foo');
$this->userManager->method('get')
->with('recipient')
->willReturn($this->createMock(IUser::class));
$share->setSharedWith('recipient');