diff --git a/apps/files_sharing/lib/Listener/SharesUpdatedListener.php b/apps/files_sharing/lib/Listener/SharesUpdatedListener.php index a84159ce722..36c81ff9a9f 100644 --- a/apps/files_sharing/lib/Listener/SharesUpdatedListener.php +++ b/apps/files_sharing/lib/Listener/SharesUpdatedListener.php @@ -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(); diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 025800842e8..edff92583eb 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -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; } diff --git a/lib/public/Share/Events/ShareMovedEvent.php b/lib/public/Share/Events/ShareMovedEvent.php index 36c020fc0c4..3c9fc71f193 100644 --- a/lib/public/Share/Events/ShareMovedEvent.php +++ b/lib/public/Share/Events/ShareMovedEvent.php @@ -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; + } } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index cdbb36ac78d..81216aaecd1 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -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');