The namespace now fully handles the ownership information. Extended base query to...
authorGunnar Wrobel <p@rdus.de>
Sat, 8 Jan 2011 13:23:02 +0000 (14:23 +0100)
committerGunnar Wrobel <p@rdus.de>
Sat, 8 Jan 2011 13:23:02 +0000 (14:23 +0100)
21 files changed:
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Pear.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Rcube.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Factory.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Namespace/Config.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Namespace/Element.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Namespace/Element/Other.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Namespace/Element/Personal.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Namespace/Element/Shared.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Namespace/Element/SharedWithPrefix.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Namespace/Fixed.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/List/Query/Base.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/PermissionTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/CclientTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/MockTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/FactoryTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Folder/NamespaceTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/List/Query/BaseTest.php

index b0d15db..ebddb5c 100644 (file)
@@ -166,10 +166,12 @@ implements Horde_Kolab_Storage_Driver
         if ($this->_namespace === null) {
             if (isset($this->_params['namespaces'])) {
                 $this->_namespace = $this->_factory->createNamespace(
-                    'config', $this->_params['namespaces']
+                    'config', $this->getAuth(), $this->_params['namespaces']
                 );
             } else {
-                $this->_namespace = $this->_factory->createNamespace('fixed');
+                $this->_namespace = $this->_factory->createNamespace(
+                    'fixed', $this->getAuth()
+                );
             }
         }
         return $this->_namespace;
index e3d4a89..45b2bfb 100644 (file)
@@ -422,7 +422,7 @@ extends Horde_Kolab_Storage_Driver_Base
                 }
                 $c[] = $namespace;
             }
-            $this->_namespace = $this->getFactory()->createNamespace('imap', $c);
+            $this->_namespace = $this->getFactory()->createNamespace('imap', $this->getAuth(), $c);
         }
         return parent::getNamespace();
     }
index f03d59a..b4127ab 100644 (file)
@@ -430,6 +430,7 @@ extends Horde_Kolab_Storage_Driver_Base
                 }
             }
             return new Horde_Kolab_Storage_Folder_Namespace_Imap(
+                $this->getAuth(),
                 $namespaces,
                 $this->getParam('namespaces', array())
             );
index 2b9d27f..2c0b1a5 100644 (file)
@@ -436,12 +436,13 @@ extends Horde_Kolab_Storage_Driver_Base
                         $namespace['type'] = 'shared';
                         break;
                     }
-                    $namespace['delimiter'] = $namespace['delimter'];
+                    $namespace['delimiter'] = $namespace['delimiter'];
                     $namespaces[] = $namespace;
                 }
             }
             return new Horde_Kolab_Storage_Driver_Namespace_Imap(
                 $namespaces,
+                $this->getAuth(),
                 $this->getParam('namespaces', array())
             );
         }
index e5c22f3..53a9306 100644 (file)
@@ -192,11 +192,12 @@ class Horde_Kolab_Storage_Factory
      * Create a namespace handler.
      *
      * @param string $type   The namespace type.
+     * @param string $user   The current user.
      * @param array  $params The parameters for the namespace. See 
      *
      * @return Horde_Kolab_Storage_Folder_Namespace The namespace handler.
      */
-    public function createNamespace($type, array $params = array())
+    public function createNamespace($type, $user, array $params = array())
     {
         $class = 'Horde_Kolab_Storage_Folder_Namespace_' . ucfirst($type);
         if (!class_exists($class)) {
@@ -209,7 +210,7 @@ class Horde_Kolab_Storage_Factory
                 )
             );
         }
-        return new $class($params);
+        return new $class($user, $params);
     }
 
     /**
index 2d147a3..8ab9caa 100644 (file)
@@ -32,19 +32,22 @@ extends  Horde_Kolab_Storage_Folder_Namespace
 {
     /**
      * Constructor.
+     *
+     * @param string $user          The current user.
+     * @param array  $configuration The namespace configuration.
      */
-    public function __construct(array $configuration)
+    public function __construct($user, array $configuration)
     {
         $namespace = array();
         foreach ($configuration as $element) {
             if ($element['type'] == Horde_Kolab_Storage_Folder_Namespace::SHARED
                 && isset($element['prefix'])) {
                 $namespace_element = new Horde_Kolab_Storage_Folder_Namespace_Element_SharedWithPrefix(
-                    $element['name'], $element['delimiter'], $element['prefix']
+                    $element['name'], $element['delimiter'], $user, $element['prefix']
                 );
             } else {
                 $class = 'Horde_Kolab_Storage_Folder_Namespace_Element_' . ucfirst($element['type']);
-                $namespace_element = new $class($element['name'], $element['delimiter']);
+                $namespace_element = new $class($element['name'], $element['delimiter'], $user);
             }
             $namespaces[] = $namespace_element;
         }
index 67790f0..d7403df 100644 (file)
@@ -42,18 +42,27 @@ abstract class Horde_Kolab_Storage_Folder_Namespace_Element
     protected $_delimiter;
 
     /**
+     * The current user.
+     *
+     * @var string
+     */
+    protected $_user;
+
+    /**
      * Constructor.
      *
      * @param string $name      The prefix identifying this namespace.
      * @param string $delimiter The delimiter used for this namespace.
+     * @param string $user      The current user.
      */
-    public function __construct($name, $delimiter)
+    public function __construct($name, $delimiter, $user)
     {
         if (substr($name, -1) == $delimiter) {
             $name = substr($name, 0, -1);
         }
         $this->_name = $name;
         $this->_delimiter = $delimiter;
+        $this->_user = $user;
     }
 
     /**
index 00258e8..007457f 100644 (file)
@@ -55,9 +55,14 @@ extends Horde_Kolab_Storage_Folder_Namespace_Element
             $domain = strstr(array_pop($path), '@');
             if (!empty($domain)) {
                 $user .= $domain;
+            } else {
+                $domain = strstr($this->_user, '@');
+                if (!empty($domain)) {
+                    $user .= $domain;
+                }
             }
         }
-        return Horde_Kolab_Storage_Folder_Namespace::OTHER . ':' . $user;
+        return $user;
     }
 
     /**
index 5c3156d..7b97217 100644 (file)
@@ -49,6 +49,6 @@ extends Horde_Kolab_Storage_Folder_Namespace_Element
      */
     public function getOwner($name)
     {
-        return Horde_Kolab_Storage_Folder_Namespace::PERSONAL;
+        return $this->_user;
     }
 }
\ No newline at end of file
index feda5a0..f1dff77 100644 (file)
@@ -49,6 +49,6 @@ extends Horde_Kolab_Storage_Folder_Namespace_Element
      */
     public function getOwner($name)
     {
-        return Horde_Kolab_Storage_Folder_Namespace::SHARED;
+        return 'anonymous';
     }
 }
\ No newline at end of file
index 70c9a58..cd52cc1 100644 (file)
@@ -42,11 +42,12 @@ extends Horde_Kolab_Storage_Folder_Namespace_Element_Shared
      *
      * @param string $name      The prefix identifying this namespace.
      * @param string $delimiter The delimiter used for this namespace.
-     * @param string $prefix The prefix to hide.
+     * @param string $user      The current user.
+     * @param string $prefix    The prefix to hide.
      */
-    public function __construct($name, $delimiter, $prefix)
+    public function __construct($name, $delimiter, $user, $prefix)
     {
-        parent::__construct($name, $delimiter);
+        parent::__construct($name, $delimiter, $user);
         $this->_prefix = $prefix;
     }
 
index 338ba74..6db0156 100644 (file)
@@ -33,13 +33,13 @@ extends  Horde_Kolab_Storage_Folder_Namespace
     /**
      * Constructor.
      */
-    public function __construct()
+    public function __construct($user)
     {
         parent::__construct(
             array(
-                new Horde_Kolab_Storage_Folder_Namespace_Element_Personal('INBOX/', '/'),
-                new Horde_Kolab_Storage_Folder_Namespace_Element_Other('user/', '/'),
-                new Horde_Kolab_Storage_Folder_Namespace_Element_SharedWithPrefix('', '/', 'shared.')
+                new Horde_Kolab_Storage_Folder_Namespace_Element_Personal('INBOX/', '/', $user),
+                new Horde_Kolab_Storage_Folder_Namespace_Element_Other('user/', '/', $user),
+                new Horde_Kolab_Storage_Folder_Namespace_Element_SharedWithPrefix('', '/', $user, 'shared.')
             )
         );
     }
index d3d3346..d12b470 100644 (file)
@@ -54,6 +54,14 @@ extends Horde_Kolab_Storage_Query
     public function listByType($type);
 
     /**
+     * Get the folder owners.
+     *
+     * @return array The folder owners with the folder names as key and the
+     *               owner as values.
+     */
+//    public function listOwners();
+
+    /**
      * Get the default folder for a certain type.
      *
      * @param string $type The type of the share/folder.
index 7aff095..45c11b6 100644 (file)
@@ -107,6 +107,22 @@ implements Horde_Kolab_Storage_List_Query
     }
 
     /**
+     * Get the folder owners.
+     *
+     * @return array The folder owners with the folder names as key and the
+     *               owner as values.
+     */
+    public function listOwners()
+    {
+        $result = array();
+        $namespace = $this->_list->getNamespace();
+        foreach ($this->_list->listFolders() as $folder) {
+            $result[$folder] = $namespace->getOwner($folder);
+        }
+        return $result;
+    }
+
+    /**
      * Synchronize the query data with the information from the backend.
      *
      * @return NULL
index 3237441..63b27ac 100644 (file)
@@ -125,6 +125,7 @@ class Horde_Kolab_Storage_PermissionTest extends PHPUnit_Framework_TestCase
             ->will(
                 $this->returnValue(
                     new Horde_Kolab_Storage_Folder_Namespace_Imap(
+                        'test',
                         array(
                             array(
                                 'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
@@ -257,6 +258,7 @@ class Horde_Kolab_Storage_PermissionTest extends PHPUnit_Framework_TestCase
             ->will(
                 $this->returnValue(
                     new Horde_Kolab_Storage_Folder_Namespace_Imap(
+                        'test',
                         array(
                             array(
                                 'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
index 2596f1a..9121b69 100644 (file)
@@ -188,6 +188,85 @@ extends PHPUnit_Framework_TestCase
         );
     }
 
+    protected function getNamespaceAccount()
+    {
+        return array(
+            'username' => 'test@example.com',
+            'data' => array(
+                'user/test' => null,
+                'user/test/a' => null,
+                'user/test/Calendar' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'event.default',
+                    )
+                ),
+                'user/test/Contacts' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'contact.default',
+                    )
+                ),
+                'user/test/Notes' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'note.default',
+                    )
+                ),
+                'user/test/Tasks' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'task.default',
+                    )
+                ),
+                'user/example/Notes' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'note.default',
+                    )
+                ),
+                'user/example/Calendar' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'event.default',
+                    )
+                ),
+                'user/someone/Calendars/Events' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'event.default',
+                    )
+                ),
+                'user/someone/Calendars/Party' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'event',
+                    )
+                ),
+                'shared.Calendars/All' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'event',
+                    )
+                ),
+                'shared.Calendars/Others' => array(
+                    'annotations' => array(
+                        '/shared/vendor/kolab/folder-type' => 'event',
+                    )
+                ),
+            )
+        );
+    }
+
+    protected function getNamespaceMock($factory = null)
+    {
+        $factory = $this->completeFactory($factory);
+        return new Horde_Kolab_Storage_Driver_Mock(
+            $factory,
+            $this->getNamespaceAccount()
+        );
+    }
+
+    protected function getNamespaceList($factory = null)
+    {
+        $factory = $this->completeFactory($factory);
+        return new Horde_Kolab_Storage_List_Base(
+            $this->getNamespaceMock($factory),
+            $factory
+        );
+    }
+
     protected function getCachedQueryForList($bare_list, $factory)
     {
         $list_cache = $this->getMockListCache();
index 1834061..cba7bcc 100644 (file)
@@ -49,7 +49,7 @@ extends PHPUnit_Framework_TestCase
     public function testGetNamespaceReturnsExpectedNamespaces()
     {
         $driver = new Horde_Kolab_Storage_Driver_Cclient(
-            new Horde_Kolab_Storage_Factory(), array()
+            new Horde_Kolab_Storage_Factory(), array('username' => 'test')
         );
         $namespaces = array();
         foreach ($driver->getNamespace() as $namespace) {
index 962e88b..9516e49 100644 (file)
@@ -128,7 +128,7 @@ extends Horde_Kolab_Storage_TestCase
     public function testGetNamespaceReturnsExpectedNamespaces()
     {
         $driver = new Horde_Kolab_Storage_Driver_Mock(
-            new Horde_Kolab_Storage_Factory(), array()
+            new Horde_Kolab_Storage_Factory(), array('username' => 'test')
         );
         $namespaces = array();
         foreach ($driver->getNamespace() as $namespace) {
index 25a6588..01e0eba 100644 (file)
@@ -93,7 +93,7 @@ extends Horde_Kolab_Storage_TestCase
     {
         $factory = new Horde_Kolab_Storage_Factory();
         $factory->createNamespace(
-            'undefined'
+            'undefined', 'test'
         );
     }
 
@@ -103,7 +103,7 @@ extends Horde_Kolab_Storage_TestCase
         $this->assertInstanceOf(
             'Horde_Kolab_Storage_Folder_Namespace_Fixed',
             $factory->createNamespace(
-                'fixed'
+                'fixed', 'test'
             )
         );
     }
index c14278c..a5ccf4c 100644 (file)
@@ -84,9 +84,6 @@ extends Horde_Kolab_Storage_TestCase
     public function testTitleForNewFolders()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $this->_connection->expects($this->any())
-                ->method('getAuth')
-                ->will($this->returnValue('test'));
             $folder = $this->_getFolder(null, $namespace);
             $folder->setTitle('test');
             $this->assertEquals('test', $folder->getTitle());
@@ -96,9 +93,6 @@ extends Horde_Kolab_Storage_TestCase
     public function testOwnerForPersonalNS()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $this->_connection->expects($this->any())
-                ->method('getAuth')
-                ->will($this->returnValue('test'));
             $folder = $this->_getFolder('INBOX', $namespace);
             $this->assertEquals('test', $folder->getOwner());
         }
@@ -107,9 +101,6 @@ extends Horde_Kolab_Storage_TestCase
     public function testOwnerInPersonalNS()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $this->_connection->expects($this->any())
-                ->method('getAuth')
-                ->will($this->returnValue('test'));
             $folder = $this->_getFolder('INBOX/mine', $namespace);
             $this->assertEquals('test', $folder->getOwner());
         }
@@ -142,9 +133,6 @@ extends Horde_Kolab_Storage_TestCase
     public function testOwnerForNewFolders()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $this->_connection->expects($this->any())
-                ->method('getAuth')
-                ->will($this->returnValue('test'));
             $folder = $this->_getFolder(null, $namespace);
             $folder->setTitle('test');
             $this->assertEquals('test', $folder->getOwner());
@@ -153,10 +141,7 @@ extends Horde_Kolab_Storage_TestCase
 
     public function testOwnerDomain()
     {
-        foreach ($this->_getNamespaces() as $namespace) {
-            $this->_connection->expects($this->any())
-                ->method('getAuth')
-                ->will($this->returnValue('test@example.com'));
+        foreach ($this->_getNamespaces('test@example.com') as $namespace) {
             $folder = $this->_getFolder('user/test/mine', $namespace);
             $this->assertEquals('test@example.com', $folder->getOwner());
         }
@@ -260,11 +245,12 @@ extends Horde_Kolab_Storage_TestCase
         return $folder;
     }
 
-    private function _getNamespaces()
+    private function _getNamespaces($user = 'test')
     {
         return array(
-            new Horde_Kolab_Storage_Folder_Namespace_Fixed(),
+            new Horde_Kolab_Storage_Folder_Namespace_Fixed($user),
             new Horde_Kolab_Storage_Folder_Namespace_Config(
+                $user,
                 array(
                     array(
                         'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
@@ -286,6 +272,7 @@ extends Horde_Kolab_Storage_TestCase
                 )
             ),
             new Horde_Kolab_Storage_Folder_Namespace_Imap(
+                $user,
                 array(
                     array(
                         'name'      => 'INBOX/',
index a70d7db..21c76fc 100644 (file)
@@ -86,4 +86,54 @@ extends Horde_Kolab_Storage_TestCase
             $this->assertInstanceOf('Horde_Kolab_Storage_Folder_Type', $type);
         };
     }
+
+    public function testListOwnersReturn()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+        $this->assertType(
+            'array',
+            $query->listOwners()
+        );
+    }
+
+    public function testListOwnerList()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+        $this->assertEquals(
+            array(
+                'INBOX' => 'test@example.com',
+                'INBOX/Calendar' => 'test@example.com',
+                'INBOX/Contacts' => 'test@example.com',
+                'INBOX/Notes' => 'test@example.com',
+                'INBOX/Tasks' => 'test@example.com',
+                'INBOX/a' => 'test@example.com',
+            ),
+            $query->listOwners()
+        );
+    }
+
+    public function testListOwnerNamespace()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $query = $factory->createListQuery('Base', $this->getNamespaceList($factory));
+        $this->assertEquals(
+            array(
+                'INBOX' => 'test@example.com',
+                'INBOX/Calendar' => 'test@example.com',
+                'INBOX/Contacts' => 'test@example.com',
+                'INBOX/Notes' => 'test@example.com',
+                'INBOX/Tasks' => 'test@example.com',
+                'INBOX/a' => 'test@example.com',
+                'shared.Calendars/All' => 'anonymous',
+                'shared.Calendars/Others' => 'anonymous',
+                'user/example/Calendar' => 'example@example.com',
+                'user/example/Notes' => 'example@example.com',
+                'user/someone/Calendars/Events' => 'someone@example.com',
+                'user/someone/Calendars/Party' => 'someone@example.com',
+            ),
+            $query->listOwners()
+        );
+    }
 }