]> source.dussan.org Git - nextcloud-server.git/commitdiff
No duplicate calendars if shared with user and group and the user is part of the...
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 28 Jan 2016 16:16:11 +0000 (17:16 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Wed, 3 Feb 2016 16:18:22 +0000 (17:18 +0100)
apps/dav/lib/caldav/caldavbackend.php
apps/dav/tests/unit/caldav/caldavbackendtest.php

index 48fc1fe3b080166626a41d2abaf4f94573c10cae..1bd1000a731cf570ac71c753f3e4beb10f4924d2 100644 (file)
@@ -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);
        }
 
        /**
index a4869f182894e2e5b70fb450a502d30aeda862bd..30148211a430fda350de6da20409430afdcd6726 100644 (file)
@@ -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();