Skip to content

Commit

Permalink
No duplicate calendars if shared with user and group and the user is …
Browse files Browse the repository at this point in the history
…part of the group
  • Loading branch information
DeepDiver1975 committed Jan 28, 2016
1 parent 3f88c20 commit e3ef67b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
7 changes: 3 additions & 4 deletions apps/dav/lib/caldav/caldavbackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function getCalendarsForUser($principalUri) {
$calendar[$xmlName] = $row[$dbName];
}

$calendars[] = $calendar;
$calendars[$calendar['id']] = $calendar;

This comment has been minimized.

Copy link
@georgehrke

georgehrke Jan 28, 2016

Contributor

I didn't test it, but I don't think this code takes different permissions into consideration.

What if a user gives read-write access to another user, but only read-access to a group, the other user is a member of.
Will the user the calendar is shared with end up with a read-only or a read-write calendar?

This comment has been minimized.

Copy link
@DeepDiver1975

DeepDiver1975 Jan 29, 2016

Author Member

You are right ... will take care about that.

}

$stmt->closeCursor();
Expand Down Expand Up @@ -223,12 +223,11 @@ function getCalendarsForUser($principalUri) {
$calendar[$xmlName] = $row[$dbName];
}

$calendars[]= $calendar;
$calendars[$calendar['id']] = $calendar;
}
$result->closeCursor();


return $calendars;
return array_values($calendars);
}

/**
Expand Down
33 changes: 31 additions & 2 deletions apps/dav/tests/unit/caldav/caldavbackendtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -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);
Expand Down Expand Up @@ -102,6 +108,29 @@ public function testCalendarOperations() {
$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();
Expand Down

0 comments on commit e3ef67b

Please sign in to comment.