summaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-28 17:16:11 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-02-03 17:18:22 +0100
commit18c35bf812b1f5db55fb74006f13237c0cb2fe3f (patch)
tree3555b2fd4c6ebd2cb1e760a54f4c5db95ff52c6d /apps/dav
parent91065956080b02407625cd78796064e45a6d0236 (diff)
downloadnextcloud-server-18c35bf812b1f5db55fb74006f13237c0cb2fe3f.tar.gz
nextcloud-server-18c35bf812b1f5db55fb74006f13237c0cb2fe3f.zip
No duplicate calendars if shared with user and group and the user is part of the group
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/caldav/caldavbackend.php7
-rw-r--r--apps/dav/tests/unit/caldav/caldavbackendtest.php33
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();