diff --git a/apps/dav/lib/CalDAV/Activity/Backend.php b/apps/dav/lib/CalDAV/Activity/Backend.php index f0c49e6e28c9f..7790751435849 100644 --- a/apps/dav/lib/CalDAV/Activity/Backend.php +++ b/apps/dav/lib/CalDAV/Activity/Backend.php @@ -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 diff --git a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php index 037aa19f9171a..fc9f8220effe2 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php @@ -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[]