mirror of
https://github.com/nextcloud/server.git
synced 2026-07-13 11:51:34 -04:00
fix: only update share for the user who moved the share
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
05d9fe3916
commit
23547109f1
4 changed files with 21 additions and 7 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue