]> source.dussan.org Git - nextcloud-server.git/commitdiff
Show group shared addressbooks
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 11 Jan 2016 16:29:01 +0000 (17:29 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 18 Jan 2016 21:14:30 +0000 (22:14 +0100)
apps/dav/command/createaddressbook.php
apps/dav/command/syncsystemaddressbook.php
apps/dav/lib/carddav/carddavbackend.php
apps/dav/lib/connector/sabre/principal.php
apps/dav/lib/rootcollection.php
apps/dav/tests/unit/connector/sabre/principal.php

index 0e396074704a558306dbf2a52ab225e935b60547..201101d17f4e8c4a4c4756754d3c4c38f7e7c5c2 100644 (file)
@@ -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');
index c7401107480cfa9fc95966f5797d04c814f80051..50f570ec93ee63760663b21d9763519d5c67204b 100644 (file)
  */
 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;
index 7deda07497f12402b084cb541ca7817aacec1c61..e8a5a77664611f4e57eac950e44e96fad45b3704 100644 (file)
@@ -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()) {
index ece799c701996d9c85d10fb5d9983b31715ca9ec..583deb3a175beaf977cb984d4ce79eda97a1fca2 100644 (file)
 
 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 [];
        }
 
        /**
index 8e0e0c6b86f7ad2303e9eb5dd8c3fbfea235dbe3..0afde97a9e7d5be53aa8206edee1f9a83e7fc090 100644 (file)
@@ -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()
index e0b459495b6b890fce32c22763014947f4c72995..c98a7e5699cb72cdbc5ceb1ab5ca1cdfacf77f54 100644 (file)
 
 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();
        }