From 18c35bf812b1f5db55fb74006f13237c0cb2fe3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Thu, 28 Jan 2016 17:16:11 +0100 Subject: [PATCH] No duplicate calendars if shared with user and group and the user is part of the group --- apps/dav/lib/caldav/caldavbackend.php | 7 ++-- .../tests/unit/caldav/caldavbackendtest.php | 33 +++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/apps/dav/lib/caldav/caldavbackend.php b/apps/dav/lib/caldav/caldavbackend.php index 48fc1fe3b08..1bd1000a731 100644 --- a/apps/dav/lib/caldav/caldavbackend.php +++ b/apps/dav/lib/caldav/caldavbackend.php @@ -172,7 +172,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $calendar[$xmlName] = $row[$dbName]; } - $calendars[] = $calendar; + $calendars[$calendar['id']] = $calendar; } $stmt->closeCursor(); @@ -223,12 +223,11 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription $calendar[$xmlName] = $row[$dbName]; } - $calendars[]= $calendar; + $calendars[$calendar['id']] = $calendar; } $result->closeCursor(); - - return $calendars; + return array_values($calendars); } /** diff --git a/apps/dav/tests/unit/caldav/caldavbackendtest.php b/apps/dav/tests/unit/caldav/caldavbackendtest.php index a4869f18289..30148211a43 100644 --- a/apps/dav/tests/unit/caldav/caldavbackendtest.php +++ b/apps/dav/tests/unit/caldav/caldavbackendtest.php @@ -23,6 +23,7 @@ namespace Tests\Connector\Sabre; use DateTime; use DateTimeZone; use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\CalDAV\Calendar; use OCA\DAV\Connector\Sabre\Principal; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; use Sabre\DAV\PropPatch; @@ -44,19 +45,24 @@ class CalDavBackendTest extends TestCase { /** @var Principal | \PHPUnit_Framework_MockObject_MockObject */ private $principal; - const UNIT_TEST_USER = 'caldav-unit-test'; + const UNIT_TEST_USER = 'principals/users/caldav-unit-test'; + const UNIT_TEST_USER1 = 'principals/users/caldav-unit-test1'; + const UNIT_TEST_GROUP = 'principals/groups/caldav-unit-test-group'; public function setUp() { parent::setUp(); $this->principal = $this->getMockBuilder('OCA\DAV\Connector\Sabre\Principal') ->disableOriginalConstructor() - ->setMethods(['getPrincipalByPath']) + ->setMethods(['getPrincipalByPath', 'getGroupMembership']) ->getMock(); $this->principal->method('getPrincipalByPath') ->willReturn([ 'uri' => 'principals/best-friend' ]); + $this->principal->method('getGroupMembership') + ->withAnyParameters() + ->willReturn([self::UNIT_TEST_GROUP]); $db = \OC::$server->getDatabaseConnection(); $this->backend = new CalDavBackend($db, $this->principal); @@ -102,6 +108,29 @@ class CalDavBackendTest extends TestCase { $this->assertEquals(0, count($books)); } + public function testCalendarSharing() { + + $this->createTestCalendar(); + $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); + $this->assertEquals(1, count($books)); + $calendar = new Calendar($this->backend, $books[0]); + $this->backend->updateShares($calendar, [ + [ + 'href' => 'principal:' . self::UNIT_TEST_USER1, + ], + [ + 'href' => 'principal:' . self::UNIT_TEST_GROUP, + ] + ], []); + $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1); + $this->assertEquals(1, count($books)); + + // delete the address book + $this->backend->deleteCalendar($books[0]['id']); + $books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER); + $this->assertEquals(0, count($books)); + } + public function testCalendarObjectsOperations() { $calendarId = $this->createTestCalendar(); -- 2.39.5