diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-11 17:29:01 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-18 22:14:30 +0100 |
commit | 8b8edc1f5dbe27cbeaf9935aa175037fdf6d0c1c (patch) | |
tree | 0fca2a5dd6c9f53a7c7f4d4b7c172ea79481ccd3 | |
parent | d7729a8ff6b16aa41f789ef2ca76da27648300fd (diff) | |
download | nextcloud-server-8b8edc1f5dbe27cbeaf9935aa175037fdf6d0c1c.tar.gz nextcloud-server-8b8edc1f5dbe27cbeaf9935aa175037fdf6d0c1c.zip |
Show group shared addressbooks
-rw-r--r-- | apps/dav/command/createaddressbook.php | 14 | ||||
-rw-r--r-- | apps/dav/command/syncsystemaddressbook.php | 10 | ||||
-rw-r--r-- | apps/dav/lib/carddav/carddavbackend.php | 7 | ||||
-rw-r--r-- | apps/dav/lib/connector/sabre/principal.php | 31 | ||||
-rw-r--r-- | apps/dav/lib/rootcollection.php | 3 | ||||
-rw-r--r-- | apps/dav/tests/unit/connector/sabre/principal.php | 10 |
6 files changed, 41 insertions, 34 deletions
diff --git a/apps/dav/command/createaddressbook.php b/apps/dav/command/createaddressbook.php index 0e396074704..201101d17f4 100644 --- a/apps/dav/command/createaddressbook.php +++ b/apps/dav/command/createaddressbook.php @@ -25,6 +25,7 @@ use OCA\DAV\CardDAV\CardDavBackend; use OCA\DAV\Connector\Sabre\Principal; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IGroupManager; use OCP\ILogger; use OCP\IUserManager; use Symfony\Component\Console\Command\Command; @@ -40,12 +41,12 @@ class CreateAddressBook extends Command { /** @var \OCP\IDBConnection */ protected $dbConnection; - /** @var IConfig */ - private $config; - /** @var ILogger */ private $logger; + /** @var IGroupManager $groupManager */ + private $groupManager; + /** * @param IUserManager $userManager * @param IDBConnection $dbConnection @@ -53,14 +54,14 @@ class CreateAddressBook extends Command { * @param ILogger $logger */ function __construct(IUserManager $userManager, + IGroupManager $groupManager, IDBConnection $dbConnection, - IConfig $config, ILogger $logger ) { parent::__construct(); $this->userManager = $userManager; + $this->groupManager = $groupManager; $this->dbConnection = $dbConnection; - $this->config = $config; $this->logger = $logger; } @@ -82,7 +83,8 @@ class CreateAddressBook extends Command { throw new \InvalidArgumentException("User <$user> in unknown."); } $principalBackend = new Principal( - $this->userManager + $this->userManager, + $this->groupManager ); $name = $input->getArgument('name'); diff --git a/apps/dav/command/syncsystemaddressbook.php b/apps/dav/command/syncsystemaddressbook.php index c7401107480..50f570ec93e 100644 --- a/apps/dav/command/syncsystemaddressbook.php +++ b/apps/dav/command/syncsystemaddressbook.php @@ -20,18 +20,8 @@ */ namespace OCA\DAV\Command; -use OCA\DAV\CardDAV\CardDavBackend; -use OCA\DAV\CardDAV\Converter; use OCA\DAV\CardDAV\SyncService; -use OCA\DAV\Connector\Sabre\Principal; -use OCP\IConfig; -use OCP\IDBConnection; -use OCP\IUser; use OCP\IUserManager; -use Sabre\CardDAV\Plugin; -use Sabre\VObject\Component\VCard; -use Sabre\VObject\Property\Text; -use Sabre\VObject\Reader; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputArgument; diff --git a/apps/dav/lib/carddav/carddavbackend.php b/apps/dav/lib/carddav/carddavbackend.php index 7deda07497f..e8a5a776646 100644 --- a/apps/dav/lib/carddav/carddavbackend.php +++ b/apps/dav/lib/carddav/carddavbackend.php @@ -105,17 +105,20 @@ class CardDavBackend implements BackendInterface, SyncSupport { $result->closeCursor(); // query for shared calendars + $principals = $this->principalBackend->getGroupMembership($principalUri); + $principals[]= $principalUri; + $query = $this->db->getQueryBuilder(); $query2 = $this->db->getQueryBuilder(); $query2->select(['resourceid']) ->from('dav_shares') - ->where($query2->expr()->eq('principaluri', $query2->createParameter('principaluri'))) + ->where($query2->expr()->in('principaluri', $query2->createParameter('principaluri'))) ->andWhere($query2->expr()->eq('type', $query2->createParameter('type'))); $result = $query->select(['id', 'uri', 'displayname', 'principaluri', 'description', 'synctoken']) ->from('addressbooks') ->where($query->expr()->in('id', $query->createFunction($query2->getSQL()))) ->setParameter('type', 'addressbook') - ->setParameter('principaluri', $principalUri) + ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) ->execute(); while($row = $result->fetch()) { diff --git a/apps/dav/lib/connector/sabre/principal.php b/apps/dav/lib/connector/sabre/principal.php index ece799c7019..583deb3a175 100644 --- a/apps/dav/lib/connector/sabre/principal.php +++ b/apps/dav/lib/connector/sabre/principal.php @@ -29,9 +29,10 @@ namespace OCA\DAV\Connector\Sabre; +use OCP\IGroup; +use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; -use OCP\IConfig; use Sabre\DAV\Exception; use \Sabre\DAV\PropPatch; use Sabre\DAVACL\PrincipalBackend\BackendInterface; @@ -42,11 +43,15 @@ class Principal implements BackendInterface { /** @var IUserManager */ private $userManager; + /** @var IGroupManager */ + private $groupManager; + /** * @param IUserManager $userManager */ - public function __construct(IUserManager $userManager) { + public function __construct(IUserManager $userManager, IGroupManager $groupManager) { $this->userManager = $userManager; + $this->groupManager = $groupManager; } /** @@ -127,24 +132,24 @@ class Principal implements BackendInterface { public function getGroupMembership($principal) { list($prefix, $name) = URLUtil::splitPath($principal); - $group_membership = array(); if ($prefix === 'principals/users') { $principal = $this->getPrincipalByPath($principal); if (!$principal) { throw new Exception('Principal not found'); } - // TODO: for now the user principal has only its own groups - return array( - 'principals/users/'.$name.'/calendar-proxy-read', - 'principals/users/'.$name.'/calendar-proxy-write', - // The addressbook groups are not supported in Sabre, - // see http://groups.google.com/group/sabredav-discuss/browse_thread/thread/ef2fa9759d55f8c#msg_5720afc11602e753 - //'principals/'.$name.'/addressbook-proxy-read', - //'principals/'.$name.'/addressbook-proxy-write', - ); + $user = $this->userManager->get($name); + $groups = $this->groupManager->getUserGroups($user); + $groups = array_map(function($group) { + /** @var IGroup $group */ + return 'principals/groups/' . $group->getGID(); + }, $groups); + + $groups[]= 'principals/users/'.$name.'/calendar-proxy-read'; + $groups[]= 'principals/users/'.$name.'/calendar-proxy-write'; + return $groups; } - return $group_membership; + return []; } /** diff --git a/apps/dav/lib/rootcollection.php b/apps/dav/lib/rootcollection.php index 8e0e0c6b86f..0afde97a9e7 100644 --- a/apps/dav/lib/rootcollection.php +++ b/apps/dav/lib/rootcollection.php @@ -37,7 +37,8 @@ class RootCollection extends SimpleCollection { $config = \OC::$server->getConfig(); $db = \OC::$server->getDatabaseConnection(); $userPrincipalBackend = new Principal( - \OC::$server->getUserManager() + \OC::$server->getUserManager(), + \OC::$server->getGroupManager() ); $groupPrincipalBackend = new GroupPrincipalBackend( \OC::$server->getGroupManager() diff --git a/apps/dav/tests/unit/connector/sabre/principal.php b/apps/dav/tests/unit/connector/sabre/principal.php index e0b459495b6..c98a7e5699c 100644 --- a/apps/dav/tests/unit/connector/sabre/principal.php +++ b/apps/dav/tests/unit/connector/sabre/principal.php @@ -23,21 +23,27 @@ namespace OCA\DAV\Tests\Unit\Connector\Sabre; +use OCP\IGroupManager; use \Sabre\DAV\PropPatch; use OCP\IUserManager; -use OCP\IConfig; class Principal extends \Test\TestCase { /** @var IUserManager */ private $userManager; /** @var \OCA\DAV\Connector\Sabre\Principal */ private $connector; + /** @var IGroupManager */ + private $groupManager; public function setUp() { $this->userManager = $this->getMockBuilder('\OCP\IUserManager') ->disableOriginalConstructor()->getMock(); + $this->groupManager = $this->getMockBuilder('\OCP\IGroupManager') + ->disableOriginalConstructor()->getMock(); - $this->connector = new \OCA\DAV\Connector\Sabre\Principal($this->userManager); + $this->connector = new \OCA\DAV\Connector\Sabre\Principal( + $this->userManager, + $this->groupManager); parent::setUp(); } |