Skip to content
Merged
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
5 changes: 4 additions & 1 deletion apps/dav/lib/CalDAV/Activity/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,10 @@ public function onMovedCalendarObject(array $sourceCalendarData, array $targetCa
->setType($object['type'] === 'event' ? 'calendar_event' : 'calendar_todo')
->setAuthor($currentUser);

$users = $this->getUsersForShares(array_intersect($sourceShares, $targetShares));
$users = array_intersect(
$this->getUsersForShares($sourceShares),
$this->getUsersForShares($targetShares),
);
$users[] = $targetOwner;

// Users for share can return the owner itself if the calendar is published
Expand Down
70 changes: 70 additions & 0 deletions apps/dav/tests/unit/CalDAV/Activity/BackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,76 @@ public function testGetUsersForShares(array $shares, array $groups, array $expec
$this->assertEquals($expected, $users);
}

public static function dataOnMovedCalendarObject(): array {
return [
'no sharees' => [[], [], ['owner']],
'no common sharees' => [['user1'], ['user2'], ['owner']],
'common sharees' => [['user1', 'user2'], ['user2', 'user3'], ['user2', 'owner']],
'owner among sharees' => [['owner', 'user1'], ['owner', 'user1'], ['owner', 'user1']],
];
}

#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataOnMovedCalendarObject')]
public function testOnMovedCalendarObject(array $sourceUsers, array $targetUsers, array $expectedUsers): void {
$backend = $this->getBackend(['getUsersForShares']);

$sourceShares = [
['{http://owncloud.org/ns}principal' => 'principals/users/user1'],
['{http://owncloud.org/ns}principal' => 'principals/groups/group1'],
];
$targetShares = [
['{http://owncloud.org/ns}principal' => 'principals/users/user2'],
];
$backend->expects($this->exactly(2))
->method('getUsersForShares')
->willReturnMap([
[$sourceShares, $sourceUsers],
[$targetShares, $targetUsers],
]);

$this->userSession->method('getUser')
->willReturn(null);
$this->appManager->method('isEnabledForUser')
->willReturn(false);

$event = $this->createMock(IEvent::class);
$this->activityManager->expects($this->once())
->method('generateEvent')
->willReturn($event);
$event->method('setApp')->willReturnSelf();
$event->method('setObject')->willReturnSelf();
$event->method('setType')->willReturnSelf();
$event->method('setAuthor')->willReturnSelf();
$event->method('getAuthor')->willReturn('owner');
$event->method('setSubject')->willReturnSelf();

$affectedUsers = [];
$event->expects($this->exactly(count($expectedUsers)))
->method('setAffectedUser')
->willReturnCallback(function (string $user) use (&$affectedUsers, $event) {
$affectedUsers[] = $user;
return $event;
});
$this->activityManager->expects($this->exactly(count($expectedUsers)))
->method('publish')
->with($event);

$backend->onMovedCalendarObject(
['id' => 1, 'uri' => 'source', 'principaluri' => 'principals/users/owner', '{DAV:}displayname' => 'Source'],
['id' => 2, 'uri' => 'target', 'principaluri' => 'principals/users/owner', '{DAV:}displayname' => 'Target'],
$sourceShares,
$targetShares,
[
'uri' => 'event.ics',
'calendardata' => "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nUID:event-uid\r\nSUMMARY:Event\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
],
);

sort($affectedUsers);
sort($expectedUsers);
$this->assertEquals($expectedUsers, $affectedUsers);
}

/**
* @param string[] $users
* @return IUser[]&MockObject[]
Expand Down
Loading