mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
No duplicate calendars if shared with user and group and the user is part of the group
This commit is contained in:
parent
9106595608
commit
18c35bf812
2 changed files with 34 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in a new issue