From 52f4acf23d9e388fdc6348858c4572e291bbc56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 16 Mar 2016 15:54:47 +0100 Subject: [PATCH] Explicitly add the current principal to the acl in case of group sharing --- apps/dav/appinfo/application.php | 16 +++++-- apps/dav/appinfo/register_command.php | 2 +- apps/dav/appinfo/v1/caldav.php | 6 ++- apps/dav/appinfo/v1/carddav.php | 6 +-- apps/dav/command/createcalendar.php | 4 +- apps/dav/lib/caldav/caldavbackend.php | 37 ++++++++++------ apps/dav/lib/caldav/calendar.php | 4 +- apps/dav/lib/carddav/addressbook.php | 4 +- apps/dav/lib/carddav/carddavbackend.php | 31 ++++++++----- apps/dav/lib/dav/sharing/backend.php | 43 +++++++++++++++---- apps/dav/lib/dav/sharing/ishareable.php | 2 +- apps/dav/lib/rootcollection.php | 7 +-- .../tests/unit/caldav/caldavbackendtest.php | 10 ++++- .../tests/unit/carddav/carddavbackendtest.php | 32 ++++++++------ 14 files changed, 138 insertions(+), 66 deletions(-) diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php index d06daf97f5..6e86f422d4 100644 --- a/apps/dav/appinfo/application.php +++ b/apps/dav/appinfo/application.php @@ -27,6 +27,7 @@ use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\CardDAV\ContactsManager; use OCA\DAV\CardDAV\SyncJob; use OCA\DAV\CardDAV\SyncService; +use OCA\DAV\DAV\GroupPrincipalBackend; use OCA\DAV\HookManager; use OCA\Dav\Migration\AddressBookAdapter; use OCA\Dav\Migration\CalendarAdapter; @@ -83,7 +84,8 @@ class Application extends App { $c->getServer()->getUserManager(), $c->getServer()->getGroupManager() ); - return new CardDavBackend($db, $principal, $dispatcher); + $groupPrincipal = new GroupPrincipalBackend($c->getServer()->getGroupManager()); + return new CardDavBackend($db, $principal, $groupPrincipal, $dispatcher); }); $container->registerService('CalDavBackend', function($c) { @@ -93,7 +95,8 @@ class Application extends App { $c->getServer()->getUserManager(), $c->getServer()->getGroupManager() ); - return new CalDavBackend($db, $principal); + $groupPrincipal = new GroupPrincipalBackend($c->getServer()->getGroupManager()); + return new CalDavBackend($db, $principal, $groupPrincipal); }); $container->registerService('MigrateAddressbooks', function($c) { @@ -217,7 +220,7 @@ class Application extends App { $migration = $this->getContainer()->query('BirthdayService'); $userManager = $this->getContainer()->getServer()->getUserManager(); - $userManager->callForAllUsers(function($user) use($migration) { + $userManager->callForAllUsers(function ($user) use ($migration) { /** @var IUser $user */ $migration->syncUser($user->getUID()); }); @@ -225,4 +228,11 @@ class Application extends App { $this->getContainer()->getServer()->getLogger()->logException($ex); } } + + /** + * @return CardDavBackend + */ + public function getCardDavBackend() { + return $this->getContainer()->query('CardDavBackend'); + } } diff --git a/apps/dav/appinfo/register_command.php b/apps/dav/appinfo/register_command.php index 570848f0b2..45b43d6f2d 100644 --- a/apps/dav/appinfo/register_command.php +++ b/apps/dav/appinfo/register_command.php @@ -34,7 +34,7 @@ $app = new Application(); /** @var Symfony\Component\Console\Application $application */ $application->add(new CreateCalendar($userManager, $groupManager, $dbConnection)); -$application->add(new CreateAddressBook($userManager, $app->getContainer()->query('CardDavBackend'))); +$application->add(new CreateAddressBook($userManager, $app->getCardDavBackend())); $application->add(new SyncSystemAddressBook($app->getSyncService())); $application->add(new SyncBirthdayCalendar($userManager, $app->getContainer()->query('BirthdayService'))); $application->add(new MigrateAddressbooks($userManager, $app->getContainer()->query('MigrateAddressbooks'))); diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index f2c886e0fd..3e1a7ce625 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -23,11 +23,12 @@ // Backends use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\CalDAV\CalendarRoot; use OCA\DAV\Connector\Sabre\Auth; use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin; use OCA\DAV\Connector\Sabre\MaintenancePlugin; use OCA\DAV\Connector\Sabre\Principal; -use Sabre\CalDAV\CalendarRoot; +use OCA\DAV\DAV\GroupPrincipalBackend; $authBackend = new Auth( \OC::$server->getSession(), @@ -41,7 +42,8 @@ $principalBackend = new Principal( 'principals/' ); $db = \OC::$server->getDatabaseConnection(); -$calDavBackend = new CalDavBackend($db, $principalBackend); +$groupPrincipal = new GroupPrincipalBackend(\OC::$server->getGroupManager()); +$calDavBackend = new CalDavBackend($db, $principalBackend, $groupPrincipal); // Root nodes $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index 44abcbaa19..ac6ffea250 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -42,14 +42,14 @@ $principalBackend = new Principal( 'principals/' ); $db = \OC::$server->getDatabaseConnection(); -$cardDavBackend = new CardDavBackend($db, $principalBackend); +$app = new \OCA\Dav\AppInfo\Application(); // Root nodes $principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend); $principalCollection->disableListing = true; // Disable listing -$addressBookRoot = new AddressBookRoot($principalBackend, $cardDavBackend); -$addressBookRoot->disableListing = true; // Disable listing +$addressBookRoot = new AddressBookRoot($principalBackend, $app->getCardDavBackend()); +$addressBookRoot->disableListing = false; // Disable listing $nodes = array( $principalCollection, diff --git a/apps/dav/command/createcalendar.php b/apps/dav/command/createcalendar.php index d7f82dd0e5..a1a15513a0 100644 --- a/apps/dav/command/createcalendar.php +++ b/apps/dav/command/createcalendar.php @@ -22,6 +22,7 @@ namespace OCA\DAV\Command; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\Connector\Sabre\Principal; +use OCA\DAV\DAV\GroupPrincipalBackend; use OCP\IDBConnection; use OCP\IGroupManager; use OCP\IUserManager; @@ -73,9 +74,10 @@ class CreateCalendar extends Command { $this->userManager, $this->groupManager ); + $groupPrincipal = new GroupPrincipalBackend($this->groupManager); $name = $input->getArgument('name'); - $caldav = new CalDavBackend($this->dbConnection, $principalBackend); + $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $groupPrincipal); $caldav->createCalendar("principals/users/$user", $name, []); } } diff --git a/apps/dav/lib/caldav/caldavbackend.php b/apps/dav/lib/caldav/caldavbackend.php index bb50100d9a..a188d652ee 100644 --- a/apps/dav/lib/caldav/caldavbackend.php +++ b/apps/dav/lib/caldav/caldavbackend.php @@ -22,6 +22,7 @@ namespace OCA\DAV\CalDAV; +use OCA\DAV\DAV\GroupPrincipalBackend; use OCA\DAV\DAV\Sharing\IShareable; use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\DAV\Connector\Sabre\Principal; @@ -35,7 +36,9 @@ use Sabre\CalDAV\Plugin; use Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; use Sabre\DAV; +use Sabre\DAV\Exception\BadRequest; use Sabre\DAV\Exception\Forbidden; +use Sabre\DAV\PropPatch; use Sabre\HTTP\URLUtil; use Sabre\VObject\DateTimeParser; use Sabre\VObject\Reader; @@ -104,12 +107,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * CalDavBackend constructor. * * @param IDBConnection $db - * @param Principal $principalBackend + * @param $userPrincipalBackend + * @param GroupPrincipalBackend $groupPrincipalBackend */ - public function __construct(IDBConnection $db, Principal $principalBackend) { + public function __construct(IDBConnection $db, $userPrincipalBackend, GroupPrincipalBackend $groupPrincipalBackend) { $this->db = $db; - $this->principalBackend = $principalBackend; - $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); + $this->principalBackend = $userPrincipalBackend; + $this->sharingBackend = new Backend($this->db, $userPrincipalBackend, $groupPrincipalBackend, 'calendar'); } /** @@ -340,6 +344,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param string $calendarUri * @param array $properties * @return int + * @throws DAV\Exception */ function createCalendar($principalUri, $calendarUri, array $properties) { $values = [ @@ -391,10 +396,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * * Read the PropPatch documentation for more info and examples. * - * @param \Sabre\DAV\PropPatch $propPatch - * @return void + * @param int $calendarId + * @param PropPatch $propPatch */ - function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch) { + function updateCalendar($calendarId, PropPatch $propPatch) { $supportedProperties = array_keys($this->propertyMap); $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; @@ -1034,6 +1039,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @param string $uri * @param array $properties * @return mixed + * @throws Forbidden */ function createSubscription($principalUri, $uri, array $properties) { @@ -1082,10 +1088,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * Read the PropPatch documentation for more info and examples. * * @param mixed $subscriptionId - * @param \Sabre\DAV\PropPatch $propPatch + * @param PropPatch $propPatch * @return void */ - function updateSubscription($subscriptionId, DAV\PropPatch $propPatch) { + function updateSubscription($subscriptionId, PropPatch $propPatch) { $supportedProperties = array_keys($this->subscriptionPropertyMap); $supportedProperties[] = '{http://calendarserver.org/ns/}source'; @@ -1275,6 +1281,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * * @param string $calendarData * @return array + * @throws BadRequest */ protected function getDenormalizedData($calendarData) { @@ -1292,7 +1299,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } } if (!$componentType) { - throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); + throw new BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); } if ($componentType === 'VEVENT' && $component->DTSTART) { $firstOccurence = $component->DTSTART->getDateTime()->getTimeStamp(); @@ -1359,19 +1366,21 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription /** * @param int $resourceId + * @param string $currentPrincipal * @return array */ - public function getShares($resourceId) { - return $this->sharingBackend->getShares($resourceId); + public function getShares($resourceId, $currentPrincipal) { + return $this->sharingBackend->getShares($resourceId, $currentPrincipal); } /** * @param int $resourceId * @param array $acl + * @param string $currentPrincipal * @return array */ - public function applyShareAcl($resourceId, $acl) { - return $this->sharingBackend->applyShareAcl($resourceId, $acl); + public function applyShareAcl($resourceId, $acl, $currentPrincipal) { + return $this->sharingBackend->applyShareAcl($resourceId, $acl, $currentPrincipal); } private function convertPrincipal($principalUri, $toV2) { diff --git a/apps/dav/lib/caldav/calendar.php b/apps/dav/lib/caldav/calendar.php index 1e87f9b433..bc2646eb60 100644 --- a/apps/dav/lib/caldav/calendar.php +++ b/apps/dav/lib/caldav/calendar.php @@ -75,7 +75,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { function getShares() { /** @var CalDavBackend $calDavBackend */ $calDavBackend = $this->caldavBackend; - return $calDavBackend->getShares($this->getResourceId()); + return $calDavBackend->getShares($this->getResourceId(), parent::getOwner()); } /** @@ -90,7 +90,7 @@ class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { /** @var CalDavBackend $calDavBackend */ $calDavBackend = $this->caldavBackend; - return $calDavBackend->applyShareAcl($this->getResourceId(), $acl); + return $calDavBackend->applyShareAcl($this->getResourceId(), $acl, parent::getOwner()); } function getChildACL() { diff --git a/apps/dav/lib/carddav/addressbook.php b/apps/dav/lib/carddav/addressbook.php index bb9d13b981..70456afbd0 100644 --- a/apps/dav/lib/carddav/addressbook.php +++ b/apps/dav/lib/carddav/addressbook.php @@ -66,7 +66,7 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { function getShares() { /** @var CardDavBackend $carddavBackend */ $carddavBackend = $this->carddavBackend; - return $carddavBackend->getShares($this->getResourceId()); + return $carddavBackend->getShares($this->getResourceId(), $this->getOwner()); } function getACL() { @@ -113,7 +113,7 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { /** @var CardDavBackend $carddavBackend */ $carddavBackend = $this->carddavBackend; - return $carddavBackend->applyShareAcl($this->getResourceId(), $acl); + return $carddavBackend->applyShareAcl($this->getResourceId(), $acl, parent::getOwner()); } function getChild($name) { diff --git a/apps/dav/lib/carddav/carddavbackend.php b/apps/dav/lib/carddav/carddavbackend.php index bfb6ea82ad..89154c39d3 100644 --- a/apps/dav/lib/carddav/carddavbackend.php +++ b/apps/dav/lib/carddav/carddavbackend.php @@ -25,6 +25,7 @@ namespace OCA\DAV\CardDAV; use OCA\DAV\Connector\Sabre\Principal; +use OCA\DAV\DAV\GroupPrincipalBackend; use OCP\DB\QueryBuilder\IQueryBuilder; use OCA\DAV\DAV\Sharing\Backend; use OCA\DAV\DAV\Sharing\IShareable; @@ -34,6 +35,7 @@ use Sabre\CardDAV\Backend\BackendInterface; use Sabre\CardDAV\Backend\SyncSupport; use Sabre\CardDAV\Plugin; use Sabre\DAV\Exception\BadRequest; +use Sabre\DAV\PropPatch; use Sabre\HTTP\URLUtil; use Sabre\VObject\Component\VCard; use Sabre\VObject\Reader; @@ -73,16 +75,18 @@ class CardDavBackend implements BackendInterface, SyncSupport { * CardDavBackend constructor. * * @param IDBConnection $db - * @param Principal $principalBackend + * @param Principal $userPrincipalBackend + * @param GroupPrincipalBackend $groupPrincipalBackend * @param EventDispatcherInterface $dispatcher */ public function __construct(IDBConnection $db, - Principal $principalBackend, + Principal $userPrincipalBackend, + GroupPrincipalBackend $groupPrincipalBackend, EventDispatcherInterface $dispatcher = null) { $this->db = $db; - $this->principalBackend = $principalBackend; + $this->principalBackend = $userPrincipalBackend; $this->dispatcher = $dispatcher; - $this->sharingBackend = new Backend($this->db, $principalBackend, 'addressbook'); + $this->sharingBackend = new Backend($this->db, $userPrincipalBackend, $groupPrincipalBackend, 'addressbook'); } /** @@ -164,6 +168,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { /** * @param int $addressBookId + * @return array|null */ public function getAddressBookById($addressBookId) { $query = $this->db->getQueryBuilder(); @@ -190,7 +195,8 @@ class CardDavBackend implements BackendInterface, SyncSupport { } /** - * @param $addressBookUri + * @param string $principal + * @param string $addressBookUri * @return array|null */ public function getAddressBooksByUri($principal, $addressBookUri) { @@ -232,10 +238,10 @@ class CardDavBackend implements BackendInterface, SyncSupport { * Read the PropPatch documentation for more info and examples. * * @param string $addressBookId - * @param \Sabre\DAV\PropPatch $propPatch + * @param PropPatch $propPatch * @return void */ - function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { + function updateAddressBook($addressBookId, PropPatch $propPatch) { $supportedProperties = [ '{DAV:}displayname', '{' . Plugin::NS_CARDDAV . '}addressbook-description', @@ -870,10 +876,12 @@ class CardDavBackend implements BackendInterface, SyncSupport { * * readOnly - boolean * * summary - Optional, a description for the share * + * @param $addressBookId + * @param string $currentPrincipal * @return array */ - public function getShares($addressBookId) { - return $this->sharingBackend->getShares($addressBookId); + public function getShares($addressBookId, $currentPrincipal) { + return $this->sharingBackend->getShares($addressBookId, $currentPrincipal); } /** @@ -971,10 +979,11 @@ class CardDavBackend implements BackendInterface, SyncSupport { * For shared address books the sharee is set in the ACL of the address book * @param $addressBookId * @param $acl + * @param string $currentPrincipal * @return array */ - public function applyShareAcl($addressBookId, $acl) { - return $this->sharingBackend->applyShareAcl($addressBookId, $acl); + public function applyShareAcl($addressBookId, $acl, $currentPrincipal) { + return $this->sharingBackend->applyShareAcl($addressBookId, $acl, $currentPrincipal); } private function convertPrincipal($principalUri, $toV2) { diff --git a/apps/dav/lib/dav/sharing/backend.php b/apps/dav/lib/dav/sharing/backend.php index ffc4193e34..9ef1a07ebc 100644 --- a/apps/dav/lib/dav/sharing/backend.php +++ b/apps/dav/lib/dav/sharing/backend.php @@ -23,6 +23,7 @@ namespace OCA\DAV\DAV\Sharing; use OCA\DAV\Connector\Sabre\Principal; +use OCA\DAV\DAV\GroupPrincipalBackend; use OCP\IDBConnection; class Backend { @@ -30,7 +31,9 @@ class Backend { /** @var IDBConnection */ private $db; /** @var Principal */ - private $principalBackend; + private $userPrincipalBackend; + /** @var GroupPrincipalBackend */ + private $groupPrincipalBackend; /** @var string */ private $resourceType; @@ -40,12 +43,14 @@ class Backend { /** * @param IDBConnection $db - * @param Principal $principalBackend + * @param Principal $userPrincipalBackend + * @param GroupPrincipalBackend $groupPrincipalBackend * @param string $resourceType */ - public function __construct(IDBConnection $db, Principal $principalBackend, $resourceType) { + public function __construct(IDBConnection $db, Principal $userPrincipalBackend, GroupPrincipalBackend $groupPrincipalBackend, $resourceType) { $this->db = $db; - $this->principalBackend = $principalBackend; + $this->userPrincipalBackend = $userPrincipalBackend; + $this->groupPrincipalBackend = $groupPrincipalBackend; $this->resourceType = $resourceType; } @@ -143,9 +148,10 @@ class Backend { * * summary - Optional, a description for the share * * @param int $resourceId + * @param string $currentPrincipal * @return array */ - public function getShares($resourceId) { + public function getShares($resourceId, $currentPrincipal) { $query = $this->db->getQueryBuilder(); $result = $query->select(['principaluri', 'access']) ->from('dav_shares') @@ -155,13 +161,31 @@ class Backend { $shares = []; while($row = $result->fetch()) { - $p = $this->principalBackend->getPrincipalByPath($row['principaluri']); + $p = $this->userPrincipalBackend->getPrincipalByPath($row['principaluri']); + if (is_null($p)) { + $p = $this->groupPrincipalBackend->getPrincipalByPath($row['principaluri']); + if (is_null($p)) { + continue; + } + // also add the current user if it is member of the group + $groups = $this->userPrincipalBackend->getGroupMembership($currentPrincipal); + if (in_array($row['principaluri'], $groups)) { + $ownerPrincipal = $this->userPrincipalBackend->getPrincipalByPath($currentPrincipal); + $shares[]= [ + 'href' => "principal:$currentPrincipal", + 'commonName' => isset($ownerPrincipal['{DAV:}displayname']) ? $ownerPrincipal['{DAV:}displayname'] : '', + 'status' => 1, + 'readOnly' => ($row['access'] == self::ACCESS_READ), + '{http://owncloud.org/ns}principal' => $currentPrincipal + ]; + } + } $shares[]= [ 'href' => "principal:${row['principaluri']}", 'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '', 'status' => 1, 'readOnly' => ($row['access'] == self::ACCESS_READ), - '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}principal' => $row['principaluri'] + '{http://owncloud.org/ns}principal' => $row['principaluri'] ]; } @@ -173,11 +197,12 @@ class Backend { * * @param int $resourceId * @param array $acl + * @param string $currentPrincipal * @return array */ - public function applyShareAcl($resourceId, $acl) { + public function applyShareAcl($resourceId, $acl, $currentPrincipal) { - $shares = $this->getShares($resourceId); + $shares = $this->getShares($resourceId, $currentPrincipal); foreach ($shares as $share) { $acl[] = [ 'privilege' => '{DAV:}read', diff --git a/apps/dav/lib/dav/sharing/ishareable.php b/apps/dav/lib/dav/sharing/ishareable.php index f6b6bfa886..b0f3307335 100644 --- a/apps/dav/lib/dav/sharing/ishareable.php +++ b/apps/dav/lib/dav/sharing/ishareable.php @@ -71,4 +71,4 @@ interface IShareable extends INode { */ public function getOwner(); -} \ No newline at end of file +} diff --git a/apps/dav/lib/rootcollection.php b/apps/dav/lib/rootcollection.php index ea796c0917..fd1a1558ef 100644 --- a/apps/dav/lib/rootcollection.php +++ b/apps/dav/lib/rootcollection.php @@ -57,7 +57,7 @@ class RootCollection extends SimpleCollection { $systemPrincipals->disableListing = $disableListing; $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); $filesCollection->disableListing = $disableListing; - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend); + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $groupPrincipalBackend); $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); $calendarRoot->disableListing = $disableListing; @@ -80,12 +80,13 @@ class RootCollection extends SimpleCollection { \OC::$server->getRootFolder(), \OC::$server->getLogger() ); + $groupPrincipal = new GroupPrincipalBackend(\OC::$server->getGroupManager()); - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher); + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $groupPrincipal, $dispatcher); $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); $usersAddressBookRoot->disableListing = $disableListing; - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher); + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $groupPrincipal, $dispatcher); $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); $systemAddressBookRoot->disableListing = $disableListing; diff --git a/apps/dav/tests/unit/caldav/caldavbackendtest.php b/apps/dav/tests/unit/caldav/caldavbackendtest.php index 87a700a473..db89661227 100644 --- a/apps/dav/tests/unit/caldav/caldavbackendtest.php +++ b/apps/dav/tests/unit/caldav/caldavbackendtest.php @@ -25,6 +25,7 @@ use DateTimeZone; use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\Calendar; use OCA\DAV\Connector\Sabre\Principal; +use OCA\DAV\DAV\GroupPrincipalBackend; use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet; use Sabre\DAV\PropPatch; use Sabre\DAV\Xml\Property\Href; @@ -46,6 +47,9 @@ class CalDavBackendTest extends TestCase { /** @var Principal | \PHPUnit_Framework_MockObject_MockObject */ private $principal; + /** @var GroupPrincipalBackend | \PHPUnit_Framework_MockObject_MockObject */ + private $groupPrincipal; + 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'; @@ -64,9 +68,13 @@ class CalDavBackendTest extends TestCase { $this->principal->expects($this->any())->method('getGroupMembership') ->withAnyParameters() ->willReturn([self::UNIT_TEST_GROUP]); + $this->groupPrincipal = $this->getMockBuilder('OCA\DAV\DAV\GroupPrincipalBackend') + ->disableOriginalConstructor() + ->setMethods(['getPrincipalByPath', 'getGroupMembership']) + ->getMock(); $db = \OC::$server->getDatabaseConnection(); - $this->backend = new CalDavBackend($db, $this->principal); + $this->backend = new CalDavBackend($db, $this->principal, $this->groupPrincipal); $this->tearDown(); } diff --git a/apps/dav/tests/unit/carddav/carddavbackendtest.php b/apps/dav/tests/unit/carddav/carddavbackendtest.php index 1ee09260c8..38b8a81b2b 100644 --- a/apps/dav/tests/unit/carddav/carddavbackendtest.php +++ b/apps/dav/tests/unit/carddav/carddavbackendtest.php @@ -27,6 +27,7 @@ use InvalidArgumentException; use OCA\DAV\CardDAV\AddressBook; use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\Connector\Sabre\Principal; +use OCA\DAV\DAV\GroupPrincipalBackend; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; use Sabre\DAV\PropPatch; @@ -58,6 +59,9 @@ class CardDavBackendTest extends TestCase { /** @var string */ private $dbCardsPropertiesTable = 'cards_properties'; + /** @var GroupPrincipalBackend */ + private $groupPrincipal; + const UNIT_TEST_USER = 'principals/users/carddav-unit-test'; const UNIT_TEST_USER1 = 'principals/users/carddav-unit-test1'; const UNIT_TEST_GROUP = 'principals/groups/carddav-unit-test-group'; @@ -69,17 +73,21 @@ class CardDavBackendTest extends TestCase { ->disableOriginalConstructor() ->setMethods(['getPrincipalByPath', 'getGroupMembership']) ->getMock(); - $this->principal->method('getPrincipalByPath') + $this->principal->expects($this->any())->method('getPrincipalByPath') ->willReturn([ 'uri' => 'principals/best-friend' ]); - $this->principal->method('getGroupMembership') + $this->principal->expects($this->any())->method('getGroupMembership') ->withAnyParameters() ->willReturn([self::UNIT_TEST_GROUP]); + $this->groupPrincipal = $this->getMockBuilder('OCA\DAV\DAV\GroupPrincipalBackend') + ->disableOriginalConstructor() + ->setMethods(['getPrincipalByPath', 'getGroupMembership']) + ->getMock(); $this->db = \OC::$server->getDatabaseConnection(); - $this->backend = new CardDavBackend($this->db, $this->principal, null); + $this->backend = new CardDavBackend($this->db, $this->principal, $this->groupPrincipal, null); // start every test with a empty cards_properties and cards table $query = $this->db->getQueryBuilder(); @@ -157,7 +165,7 @@ class CardDavBackendTest extends TestCase { /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */ $backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') - ->setConstructorArgs([$this->db, $this->principal, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null]) ->setMethods(['updateProperties', 'purgeProperties'])->getMock(); // create a new address book @@ -203,7 +211,7 @@ class CardDavBackendTest extends TestCase { public function testMultiCard() { $this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') - ->setConstructorArgs([$this->db, $this->principal, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -248,9 +256,8 @@ class CardDavBackendTest extends TestCase { } public function testDeleteWithoutCard() { - $this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') - ->setConstructorArgs([$this->db, $this->principal, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null]) ->setMethods([ 'getCardId', 'addChange', @@ -289,9 +296,8 @@ class CardDavBackendTest extends TestCase { } public function testSyncSupport() { - $this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') - ->setConstructorArgs([$this->db, $this->principal, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null]) ->setMethods(['updateProperties'])->getMock(); // create a new address book @@ -321,13 +327,13 @@ class CardDavBackendTest extends TestCase { $exampleBook = new AddressBook($this->backend, $books[0]); $this->backend->updateShares($exampleBook, [['href' => 'principal:principals/best-friend']], []); - $shares = $this->backend->getShares($exampleBook->getResourceId()); + $shares = $this->backend->getShares($exampleBook->getResourceId(), null); $this->assertEquals(1, count($shares)); // adding the same sharee again has no effect $this->backend->updateShares($exampleBook, [['href' => 'principal:principals/best-friend']], []); - $shares = $this->backend->getShares($exampleBook->getResourceId()); + $shares = $this->backend->getShares($exampleBook->getResourceId(), null); $this->assertEquals(1, count($shares)); $books = $this->backend->getAddressBooksForUser('principals/best-friend'); @@ -335,7 +341,7 @@ class CardDavBackendTest extends TestCase { $this->backend->updateShares($exampleBook, [], ['principal:principals/best-friend']); - $shares = $this->backend->getShares($exampleBook->getResourceId()); + $shares = $this->backend->getShares($exampleBook->getResourceId(), null); $this->assertEquals(0, count($shares)); $books = $this->backend->getAddressBooksForUser('principals/best-friend'); @@ -349,7 +355,7 @@ class CardDavBackendTest extends TestCase { $cardId = 2; $backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend') - ->setConstructorArgs([$this->db, $this->principal, null]) + ->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null]) ->setMethods(['getCardId'])->getMock(); $backend->expects($this->any())->method('getCardId')->willReturn($cardId);