Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ public function transferBoardOwnership(int $boardId, string $newOwner, bool $cha
$this->cardMapper->remapCardOwner($boardId, $previousOwner, $newOwner);
}
$this->connection->commit();
$this->dispatchUserShareAccessUpdated([$newOwner, $previousOwner]);
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
'Ownership of board %s was transferred from "%s" to "%s"',
[
Expand Down Expand Up @@ -769,6 +770,21 @@ public function transferOwnership(string $owner, string $newOwner, bool $changeC
}
}

/**
* Notify files_sharing that the Deck attachments the given users can access have changed
* (otherwise they are mounted under the raw {DECK_PLACEHOLDER} target)
*
* @param list<string> $userIds
*/
private function dispatchUserShareAccessUpdated(array $userIds): void {
if (!class_exists(UserShareAccessUpdatedEvent::class)) {
return;
}
foreach (array_unique($userIds) as $userId) {
$this->eventDispatcher->dispatchTyped(new UserShareAccessUpdatedEvent(new LazyUser($userId, $this->userManager)));
}
}

/**
* @throws DoesNotExistException
* @throws NoPermissionException
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/Service/BoardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use OCA\Deck\NoPermissionException;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\Validators\BoardServiceValidator;
use OCA\Files_Sharing\Event\UserShareAccessUpdatedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
Expand Down Expand Up @@ -777,4 +778,27 @@ public function testTransferBoardOwnershipLogsCriticalAction(): void {
$this->assertSame('Ownership of board %s was transferred from "%s" to "%s"', $auditEvents[0]->getLogMessage());
$this->assertSame(['boardId' => 7, 'previousOwner' => 'admin', 'newOwner' => 'newowner', 'changeContent' => true], $auditEvents[0]->getParameters());
}

public function testTransferBoardOwnershipUpdatesShareAccessOfBothOwners(): void {
if (!class_exists(UserShareAccessUpdatedEvent::class)) {
$this->markTestSkipped('files_sharing is not available');
}
$board = new Board();
$board->setId(7);
$board->setOwner('admin');
$this->boardMapper->method('find')->willReturn($board);
$updatedUsers = [];
$this->eventDispatcher->method('dispatchTyped')
->willReturnCallback(function (Event $event) use (&$updatedUsers): void {
if ($event instanceof UserShareAccessUpdatedEvent) {
foreach ($event->getUsers() as $user) {
$updatedUsers[] = $user->getUID();
}
}
});

$this->service->transferBoardOwnership(7, 'newowner', true);

$this->assertSame(['newowner', 'admin'], $updatedUsers);
}
}