Refactor the permission handling in Kolab_Storage.
authorGunnar Wrobel <p@rdus.de>
Thu, 8 Apr 2010 17:45:54 +0000 (19:45 +0200)
committerGunnar Wrobel <p@rdus.de>
Thu, 8 Apr 2010 17:45:54 +0000 (19:45 +0200)
29 files changed:
framework/Core/lib/Horde/Core/Factory/KolabStorage.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Decorator/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anonymous.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anyone.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Creator.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Group.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/User.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/AclIterator.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Creator.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Default.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Group.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Guest.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/User.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/ElementIterator.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Namespace/Imap.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Permission.php [deleted file]
framework/Kolab_Storage/package.xml
framework/Kolab_Storage/test/Horde/Kolab/Storage/AclTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Autoload.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/NamespaceTest.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/PermissionTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/PermsTest.php [deleted file]

index cdacf29..e7bb3bc 100644 (file)
@@ -93,6 +93,7 @@ class Horde_Core_Factory_KolabStorage
         if (empty($mail)) {
             return false;
         }
+
         $params = array(
             'hostspec' => $session->getImapServer(),
             'username' => Horde_Auth::getAuth(),
@@ -102,8 +103,12 @@ class Horde_Core_Factory_KolabStorage
 
         $imap = Horde_Imap_Client::factory('socket', $params);
 
+        //@todo: The Group package needs to be converted to H4
+        require_once 'Horde/Group.php';
+
         $master = new Horde_Kolab_Storage_Driver_Imap(
-            $imap
+            $imap,
+            Group::singleton()
         );
 
         return new Horde_Kolab_Storage(
index 6d48802..75d8cf6 100644 (file)
 abstract class Horde_Kolab_Storage_Driver
 {
     /**
+     * Return the id of the user currently authenticated.
+     *
+     * @return string The id of the user that opened the connection.
+     */
+    abstract public function getAuth();
+
+    /**
+     * Does the given folder exist?
+     *
+     * @param string $folder The folder to check.
+     *
+     * @return boolean True in case the folder exists, false otherwise.
+     */
+    abstract public function exists($folder);
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    abstract public function getAcl(Horde_Kolab_Storage_Folder $folder);
+
+    /**
+     * Set the access rights for a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
+     *
+     * @return NULL
+     */
+    abstract public function setAcl($folder, $user, $acl);
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    abstract public function deleteAcl($folder, $user);
+
+    /**
      * Retrieve the namespace information for this connection.
      *
      * @return Horde_Kolab_Storage_Namespace The initialized namespace handler.
      */
     abstract public function getNamespace();
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    abstract public function getGroupHandler();
+
 }
\ No newline at end of file
index e774b4a..2edaf30 100644 (file)
@@ -35,14 +35,33 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
     private $_imap;
 
     /**
+     * The group handler for this connection.
+     *
+     * @var Horde_Group
+     */
+    private $_groups;
+
+    /**
      * Constructor.
      *
      * @param array  $params Connection parameters.
      */
     public function __construct(
-        Horde_Imap_Client_Base $imap
+        Horde_Imap_Client_Base $imap,
+        Group $groups
     ) {
-        $this->_imap = $imap;
+        $this->_imap   = $imap;
+        $this->_groups = $groups;
+    }
+
+    /**
+     * Return the id of the user currently authenticated.
+     *
+     * @return string The id of the user that opened the IMAP connection.
+     */
+    public function getAuth()
+    {
+        return $this->_imap->getParam('username');
     }
 
     /**
@@ -257,44 +276,97 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
     }
 
     /**
-     * Retrieve the access rights from a folder
+     * Retrieve the access rights for a folder.
      *
-     * @param string $folder  The folder to retrieve the ACLs from.
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
      *
-     * @return mixed An array of rights if successfull, a PEAR error
-     * otherwise.
+     * @return An array of rights.
      */
-    function getACL($folder)
+    public function getAcl(Horde_Kolab_Storage_Folder $folder)
     {
-        if (!$this->_imap->queryCapability('ACL')) {
-            $acl = array();
-            $acl[Horde_Auth::getAuth()] = 'lrid';
-            return $acl;
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            if ($folder->getOwner() == $this->getAuth()) {
+                try {
+                    return $this->_getAcl($folder->getName());
+                } catch (Exception $e) {
+                    return array($this->getAuth() => $this->_getMyAcl($folder->getName()));
+                }
+            } else {
+                $acl = $this->_getMyAcl($folder->getName());
+                if (strpos($acl, 'a')) {
+                    try {
+                        return $this->_getAcl($folder->getName());
+                    } catch (Exception $e) {
+                    }
+                }
+                return array($this->getAuth() => $acl);
+            }
+        } else {
+            return array($this->getAuth() => 'lrid');
         }
+    }
 
-        try {
-            return $this->_imap->getACL($folder);
-        } catch (Exception $e) {
-            try {
-                return array(Horde_Auth::getAuth() => str_split($this->_imap->getMyACLRights($folder)));
-            } catch (Exception $e) {
-                return array(Horde_Auth::getAuth() => str_split('lrid'));
-            }
-        }            
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getAcl($folder)
+    {
+        $acl = $this->_imap->getACL($folder);
+        $result = array();
+        foreach ($acl as $user => $rights) {
+            $result[$user] = join('', $rights);
+        }
+        return $result;
+    }
+    
+    /**
+     * Retrieve the access rights on a folder for the current user.
+     *
+     * @param string $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    private function _getMyAcl($folder)
+    {
+        return $this->_imap->getMyACLRights($folder);
     }
 
     /**
-     * Set the access rights for a folder
+     * Set the access rights for a folder.
      *
-     * @param string $folder  The folder to retrieve the ACLs from.
-     * @param string $user    The user to set the ACLs for
-     * @param string $acl     The ACLs
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
      *
-     * @return mixed True if successfull, a PEAR error otherwise.
+     * @return NULL
      */
-    function setACL($folder, $user, $acl)
+    public function setAcl($folder, $user, $acl)
     {
-        return $this->_imap->setACL($folder, $user, array('rights' => $acl));
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('rights' => $acl));
+        }
+    }
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    public function deleteAcl($folder, $user)
+    {
+        //@todo: Separate driver class
+        if ($this->_imap->queryCapability('ACL') === true) {
+            $this->_imap->setACL($folder, $user, array('remove' => true));
+        }
     }
 
     /**
@@ -350,4 +422,15 @@ class Horde_Kolab_Storage_Driver_Imap extends Horde_Kolab_Storage_Driver
         }
         return new Horde_Kolab_Storage_Namespace_Fixed();
     }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+        return $this->_groups;
+    }
+
 }
\ No newline at end of file
index 7b7ecf3..b8a0361 100644 (file)
 interface Horde_Kolab_Storage_Folder
 {
     /**
+     * Retrieve the driver for this folder.
+     *
+     * @return Horde_Kolab_Storage_Driver The folder driver.
+     */
+    public function getDriver();
+
+    /**
+     * Get the permissions for this folder.
+     *
+     * @return Horde_Kolab_Storage_Folder_Permission The permission handler.
+     */
+    public function getPermission();
+
+    /**
+     * Sets the permissions on this folder.
+     *
+     * @param Horde_Kolab_Storage_Folder_Permission $perms  Permission object.
+     * @param boolean                               $update Save the updated
+     *                                                      information?
+     *
+     * @return NULL
+     */
+    public function setPermission(
+        Horde_Kolab_Storage_Folder_Permission $perms,
+        $update = true
+    );
+
+    /**
      * Saves the folder.
      *
      * @param array $attributes An array of folder attributes. You can
@@ -90,11 +118,11 @@ interface Horde_Kolab_Storage_Folder
                                &$old_object = null);
 
     /**
-     * Return the IMAP ACL of this folder.
+     * Return the ACL of this folder.
      *
-     * @return array An array with IMAP ACL.
+     * @return array An array with ACL.
      */
-    public function getACL();
+    public function getAcl();
 
     /**
      * Set the ACL of this folder.
@@ -104,7 +132,7 @@ interface Horde_Kolab_Storage_Folder
      *
      * @return NULL
      */
-    public function setACL($user, $acl);
+    public function setAcl($user, $acl);
 
     /**
      * Delete the ACL for a user on this folder.
@@ -113,6 +141,6 @@ interface Horde_Kolab_Storage_Folder
      *
      * @return NULL
      */
-    public function deleteACL($user);
+    public function deleteAcl($user);
 
 }
index 4bab4ac..0fdae63 100644 (file)
@@ -61,11 +61,11 @@ implements Horde_Kolab_Storage_Folder
     var $new_name;
 
     /**
-     * The connection specific for this folder.
+     * The driver for this folder.
      *
      * @var Horde_Kolab_Storage_Driver
      */
-    private $_connection;
+    private $_driver;
 
     /**
      * The handler for the list of Kolab folders.
@@ -197,7 +197,7 @@ implements Horde_Kolab_Storage_Folder
     {
         $properties = get_object_vars($this);
         unset($properties['_storage']);
-        unset($properties['_connection']);
+        unset($properties['_driver']);
         $properties = array_keys($properties);
         return $properties;
     }
@@ -207,17 +207,64 @@ implements Horde_Kolab_Storage_Folder
      *
      * @param Horde_Kolab_Storage        $storage    The handler for the list of
      *                                               folders.
-     * @param Horde_Kolab_Storage_Driver $connection The storage connection.
+     * @param Horde_Kolab_Storage_Driver $driver The storage driver.
      */
     function restore(
         Horde_Kolab_Storage &$storage,
-        Horde_Kolab_Storage_Driver &$connection
+        Horde_Kolab_Storage_Driver &$driver
     ) {
-        $this->_storage    = $storage;
-        $this->_connection = $connection;
+        $this->_storage = $storage;
+        $this->_driver  = $driver;
     }
 
     /**
+     * Retrieve the driver for this folder.
+     *
+     * @return Horde_Kolab_Storage_Driver The folder driver.
+     */
+    public function getDriver()
+    {
+        return $this->_driver;
+    }
+
+    /**
+     * Get the permissions for this folder.
+     *
+     * @return Horde_Kolab_Storage_Folder_Permission The permission handler.
+     */
+    public function getPermission()
+    {
+        if ($this->_perms === null) {
+            $this->_perms = new Horde_Kolab_Storage_Folder_Permission(
+                $this->getName(),
+                $this,
+                $this->_driver->getGroupHandler()
+            );
+        }
+        return $this->_perms;
+    }
+
+    /**
+     * Sets the permissions on this folder.
+     *
+     * @param Horde_Kolab_Storage_Folder_Permission $perms  Permission object.
+     * @param boolean                               $update Save the updated
+     *                                                      information?
+     *
+     * @return NULL
+     */
+    public function setPermission(
+        Horde_Kolab_Storage_Folder_Permission $perms,
+        $update = true
+    ) {
+        $this->_perms = $perms;
+        if ($update) {
+            $this->save();
+        }
+    }
+
+
+    /**
      * Return the name of the folder.
      *
      * @return string The name of the folder.
@@ -227,7 +274,7 @@ implements Horde_Kolab_Storage_Folder
         if (isset($this->name)) {
             return $this->name;
         }
-        if (!isset($this->name) && isset($this->new_name)) {
+        if (isset($this->new_name)) {
             return $this->new_name;
         }
     }
@@ -240,7 +287,7 @@ implements Horde_Kolab_Storage_Folder
      */
     function setName($name)
     {
-        $this->new_name = $this->_connection->getNamespace()->setName($name);
+        $this->new_name = $this->_driver->getNamespace()->setName($name);
     }
 
     /**
@@ -301,14 +348,14 @@ implements Horde_Kolab_Storage_Folder
                 $this->_default = false;
             }
 
-            $result = $this->_connection->exists($this->new_name);
+            $result = $this->_driver->exists($this->new_name);
             if ($result) {
                 throw new Horde_Kolab_Storage_Exception(sprintf("Unable to add %s: destination folder already exists",
                                                                 $this->new_name),
                                                         Horde_Kolab_Storage_Exception::FOLDER_EXISTS);
             }
 
-            $this->_connection->create($this->new_name);
+            $this->_driver->create($this->new_name);
 
             $this->name = $this->new_name;
             $this->new_name = null;
@@ -339,13 +386,13 @@ implements Horde_Kolab_Storage_Folder
             if (isset($this->new_name)
                 && $this->new_name != $this->name) {
                 /** The folder needs to be renamed */
-                $result = $this->_connection->exists($this->new_name);
+                $result = $this->_driver->exists($this->new_name);
                 if ($result) {
                     throw new Horde_Kolab_Storage_Exception(sprintf(_("Unable to rename %s to %s: destination folder already exists"),
                                                                     $name, $new_name));
                 }
 
-                $result = $this->_connection->rename($this->name, $this->new_name);
+                $result = $this->_driver->rename($this->name, $this->new_name);
                 $this->_storage->removeFromCache($this);
 
                 $this->name     = $this->new_name;
@@ -415,6 +462,7 @@ implements Horde_Kolab_Storage_Folder
         /** Now save the folder permissions */
         if (isset($this->_perms)) {
             $this->_perms->save();
+            $this->_perms = null;
         }
 
         $this->_storage->addToCache($this);
@@ -429,7 +477,7 @@ implements Horde_Kolab_Storage_Folder
      */
     function delete()
     {
-        $this->_connection->delete($this->name);
+        $this->_driver->delete($this->name);
         $this->_storage->removeFromCache($this);
         return true;
     }
@@ -442,14 +490,14 @@ implements Horde_Kolab_Storage_Folder
     public function getOwner()
     {
         if (!isset($this->_owner)) {
-            $owner = $this->_connection->getNamespace()->getOwner($this->getName());
+            $owner = $this->_driver->getNamespace()->getOwner($this->getName());
             /**
              * @todo: Reconsider if this handling should really be done here
              * rather than in a module nearer to the applications.
              */
             switch ($owner) {
             case Horde_Kolab_Storage_Namespace::PERSONAL:
-                $this->_owner = Horde_Auth::getAuth();
+                $this->_owner = $this->_driver->getAuth();
                 break;
             case Horde_Kolab_Storage_Namespace::SHARED:
                 $this->_owner = 'anonymous';
@@ -457,7 +505,7 @@ implements Horde_Kolab_Storage_Folder
             default:
                 list($prefix, $user) = explode(':', $owner, 2);
                 if (strpos($user, '@') === false) {
-                    $domain = strstr(Horde_Auth::getAuth(), '@');
+                    $domain = strstr($this->_driver->getAuth(), '@');
                     if (!empty($domain)) {
                         $user .= $domain;
                     }
@@ -481,10 +529,10 @@ implements Horde_Kolab_Storage_Folder
     public function getSubpath($name = null)
     {
         if (!empty($name)) {
-            return $this->_connection->getNamespace()->getSubpath($name);
+            return $this->_driver->getNamespace()->getSubpath($name);
         }
         if (!isset($this->_subpath)) {
-            $this->_subpath = $this->_connection->getNamespace()->getSubpath($this->getName());
+            $this->_subpath = $this->_driver->getNamespace()->getSubpath($this->getName());
         }
         return $this->_subpath;
     }
@@ -497,7 +545,7 @@ implements Horde_Kolab_Storage_Folder
     public function getTitle()
     {
         if (!isset($this->_title)) {
-            $this->_title = $this->_connection->getNamespace()->getTitle($this->getName());
+            $this->_title = $this->_driver->getNamespace()->getTitle($this->getName());
         }
         return $this->_title;
     }
@@ -608,8 +656,11 @@ implements Horde_Kolab_Storage_Folder
      */
     function exists()
     {
+        if ($this->name === null) {
+            return false;
+        }
         try {
-            return $this->_connection->exists($this->name);
+            return $this->_driver->exists($this->name);
         } catch (Horde_Imap_Client_Exception $e) {
             return false;
         }
@@ -623,7 +674,7 @@ implements Horde_Kolab_Storage_Folder
     function accessible()
     {
         try {
-            return $this->_connection->select($this->name);
+            return $this->_driver->select($this->name);
         } catch (Horde_Imap_Client_Exception $e) {
             return false;
         }
@@ -678,8 +729,8 @@ implements Horde_Kolab_Storage_Folder
     public function deleteMessage($id, $trigger = true)
     {
         // Select folder
-        $this->_connection->deleteMessages($this->name, $id);
-        $this->_connection->expunge($this->name);
+        $this->_driver->deleteMessages($this->name, $id);
+        $this->_driver->expunge($this->name);
     }
 
     /**
@@ -692,9 +743,9 @@ implements Horde_Kolab_Storage_Folder
      */
     public function moveMessage($id, $folder)
     {
-        $this->_connection->select($this->name);
-        $this->_connection->moveMessage($this->name, $id, $folder);
-        $this->_connection->expunge($this->name);
+        $this->_driver->select($this->name);
+        $this->_driver->moveMessage($this->name, $id, $folder);
+        $this->_driver->expunge($this->name);
     }
 
     /**
@@ -753,7 +804,7 @@ implements Horde_Kolab_Storage_Folder
                         &$old_object = null)
     {
         // Select folder
-        $this->_connection->select($this->name);
+        $this->_driver->select($this->name);
 
         $new_headers = new Horde_Mime_Headers();
         $new_headers->setEOL("\r\n");
@@ -776,7 +827,7 @@ implements Horde_Kolab_Storage_Folder
 
         if ($id != null) {
             /** Update an existing kolab object */
-            if (!in_array($id, $this->_connection->getUids($this->name))) {
+            if (!in_array($id, $this->_driver->getUids($this->name))) {
                 return PEAR::raiseError(sprintf(_("The message with ID %s does not exist. This probably means that the Kolab object has been modified by somebody else while you were editing it. Your edits have been lost."),
                                                 $id));
             }
@@ -903,21 +954,21 @@ implements Horde_Kolab_Storage_Folder
 
         // delete old email?
         if ($id != null) {
-            $this->_connection->deleteMessages($this->name, $id);
+            $this->_driver->deleteMessages($this->name, $id);
         }
 
         // store new email
         try {
-            $result = $this->_connection->appendMessage($this->name, $msg);
+            $result = $this->_driver->appendMessage($this->name, $msg);
         } catch (Horde_Kolab_Storage_Exception $e) {
             if ($id != null) {
-                $this->_connection->undeleteMessages($id);
+                $this->_driver->undeleteMessages($id);
             }
         }
 
         // remove deleted object
         if ($id != null) {
-            $this->_connection->expunge($this->name);
+            $this->_driver->expunge($this->name);
         }
     }
 
@@ -938,13 +989,13 @@ implements Horde_Kolab_Storage_Folder
     function parseMessage($id, $mime_type, $parse_headers = true,
                           $formats = array('XML'))
     {
-        $raw_headers = $this->_connection->getMessageHeader($this->name, $id);
+        $raw_headers = $this->_driver->getMessageHeader($this->name, $id);
         if (is_a($raw_headers, 'PEAR_Error')) {
             return PEAR::raiseError(sprintf(_("Failed retrieving the message with ID %s. Original error: %s."),
                                             $id, $raw_headers->getMessage()));
         }
 
-        $body = $this->_connection->getMessageBody($this->name, $id);
+        $body = $this->_driver->getMessageBody($this->name, $id);
         if (is_a($body, 'PEAR_Error')) {
             return PEAR::raiseError(sprintf(_("Failed retrieving the message with ID %s. Original error: %s."),
                                             $id, $body->getMessage()));
@@ -1023,96 +1074,24 @@ implements Horde_Kolab_Storage_Folder
     function getStatus()
     {
         // Select the folder to update uidnext
-        $this->_connection->select($this->name);
+        $this->_driver->select($this->name);
 
-        $status = $this->_connection->status($this->name);
-        $uids   = $this->_connection->getUids($this->name);
+        $status = $this->_driver->status($this->name);
+        $uids   = $this->_driver->getUids($this->name);
         return array($status['uidvalidity'], $status['uidnext'], $uids);
     }
 
     /**
-     * Checks to see if a user has a given permission.
-     *
-     * @param string $userid       The userid of the user.
-     * @param integer $permission  A Horde_Perms::* constant to test for.
-     * @param string $creator      The creator of the shared object.
-     *
-     * @return boolean|PEAR_Error  Whether or not $userid has $permission.
-     */
-    function hasPermission($userid, $permission, $creator = null)
-    {
-        if ($userid == $this->getOwner()) {
-            return true;
-        }
-
-        $perm = &$this->getPermission();
-        if (is_a($perm, 'PEAR_Error')) {
-            return $perm;
-        }
-        return $perm->hasPermission($userid, $permission, $creator);
-    }
-
-    /**
-     * Returns the permissions from this storage object.
-     *
-     * @return Horde_Permission_Kolab  The permissions on the share.
-     */
-    function &getPermission()
-    {
-        if (!isset($this->_perms)) {
-            if ($this->exists()) {
-                // The permissions are unknown but the folder exists
-                // -> discover permissions
-                $perms = null;
-            } else {
-                $perms = array(
-                    'users' => array(
-                        Horde_Auth::getAuth() => Horde_Perms::ALL
-                    )
-                );
-            }
-            $this->_perms = new Horde_Kolab_Storage_Permission($this, $perms);
-        }
-        return $this->_perms;
-    }
-
-    /**
-     * Sets the permissions on the share.
-     *
-     * @param Horde_Permission_Kolab $perms Permission object to store on the
-     *                                     object.
-     * @param boolean $update              Save the updated information?
-     *
-     * @return boolean|PEAR_Error  True on success.
-     */
-    function setPermission(&$perms, $update = true)
-    {
-        if (!is_a($perms, 'Horde_Perms_Permission')) {
-            return PEAR::raiseError('The permissions for this share must be specified as an instance of the Horde_Perms_Permission class!');
-        }
-
-        if (!is_a($perms, 'Horde_Kolab_Storage_Permission')) {
-            $this->_perms = new Horde_Kolab_Storage_Permission($this, $perms->data);
-        } else {
-            $this->_perms = $perms;
-            $this->_perms->setFolder($this);
-        }
-
-        if ($update) {
-            return $this->save();
-        }
-
-        return true;
-    }
-
-    /**
      * Return the ACL of this folder.
      *
      * @return array An array with ACL.
      */
-    public function getACL()
+    public function getAcl()
     {
-        return $this->_connection->getACL($this->name);
+        if (!$this->exists()) {
+            array($this->getDriver()->getAuth() => 'lrid');
+        }
+        return $this->getDriver()->getAcl($this);
     }
 
     /**
@@ -1123,14 +1102,11 @@ implements Horde_Kolab_Storage_Folder
      *
      * @return NULL
      */
-    public function setACL($user, $acl)
+    public function setAcl($user, $acl)
     {
-        $this->_connection->setACL($this->name, $user, $acl);
-
-        if (!empty($this->_perms)) {
-            /** Refresh the cache after changing the permissions */
-            $this->_perms->getPerm();
-        }
+        $this->getDriver()->setAcl(
+            $this->getName(), $user, $acl
+        );
     }
 
     /**
@@ -1140,18 +1116,13 @@ implements Horde_Kolab_Storage_Folder
      *
      * @return NULL
      */
-    public function deleteACL($user)
+    public function deleteAcl($user)
     {
-        global $conf;
-
-        if (!empty($conf['kolab']['imap']['no_acl'])) {
-            return true;
-        }
-
-        $this->_connection->deleteACL($this->name, $user);
+        $this->getDriver()->deleteAcl(
+            $this->getName(), $user
+        );
     }
 
-
     /**
      * Get annotation values on IMAP server that do not support
      * METADATA.
@@ -1176,7 +1147,7 @@ implements Horde_Kolab_Storage_Folder
         global $conf;
 
         if (empty($conf['kolab']['imap']['no_annotations'])) {
-            return $this->_connection->getAnnotation($key, $this->name);
+            return $this->_driver->getAnnotation($key, $this->name);
         }
 
         if (!isset($this->_annotation_data)) {
@@ -1206,7 +1177,7 @@ implements Horde_Kolab_Storage_Folder
     function _setAnnotation($key, $value)
     {
         if (empty($conf['kolab']['imap']['no_annotations'])) {
-            return $this->_connection->setAnnotation($key, $value, $this->name);
+            return $this->_driver->setAnnotation($key, $value, $this->name);
         }
 
         if (!isset($this->_annotation_data)) {
index 11640f4..eb35e39 100644 (file)
@@ -44,6 +44,42 @@ implements Horde_Kolab_Storage_Folder
     }
 
     /**
+     * Retrieve the driver for this folder.
+     *
+     * @return Horde_Kolab_Storage_Driver The folder driver.
+     */
+    public function getDriver()
+    {
+        return $this->_folder->getDriver();
+    }
+
+    /**
+     * Get the permissions for this folder.
+     *
+     * @return Horde_Kolab_Storage_Folder_Permission The permission handler.
+     */
+    public function getPermission()
+    {
+        return $this->_folder->getPermission();
+    }
+
+    /**
+     * Sets the permissions on this folder.
+     *
+     * @param Horde_Kolab_Storage_Folder_Permission $perms  Permission object.
+     * @param boolean                               $update Save the updated
+     *                                                      information?
+     *
+     * @return NULL
+     */
+    public function setPermission(
+        Horde_Kolab_Storage_Folder_Permission $perms,
+        $update = true
+    ) {
+        $this->_folder->setPermission($perms, $update);
+    }
+
+    /**
      * Saves the folder.
      *
      * @param array $attributes An array of folder attributes. You can
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission.php
new file mode 100644 (file)
index 0000000..c0d76b1
--- /dev/null
@@ -0,0 +1,125 @@
+<?php
+/**
+ * Maps folder permissions into the Horde_Permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps folder permissions into the Horde_Permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission
+extends Horde_Perms_Permission
+{
+    /**
+     * The Kolab Folder these permissions belong to.
+     *
+     * @var Horde_Kolab_Storage_Folder
+     */
+    private $_folder;
+
+    /**
+     * The Horde_Group:: handler.
+     *
+     * @var Horde_Group
+     */
+    private $_groups;
+
+    /**
+     * A cache for the folder acl settings. The cache holds the permissions
+     * in horde compatible format, not in the IMAP permission format.
+     *
+     * @var string
+     */
+    public $data;
+
+    /**
+     * Constructor.
+     *
+     * @param string                     $name   The name of the folder.
+     * @param Horde_Kolab_Storage_Folder $acl    The folder these permissions
+     *                                           belong to.
+     * @param Horde_Group                $groups The group handler.
+     */
+    public function __construct(
+        $name,
+        Horde_Kolab_Storage_Folder $folder,
+        Group $groups
+    ) {
+        parent::__construct(__CLASS__ . '::' . $name);
+        $this->_folder = $folder;
+        $this->_groups = $groups;
+        $this->data    = $this->getCurrentPermissions();
+    }
+
+    /**
+     * Gets the current permission of the folder and stores the values in the
+     * cache.
+     *
+     * @return NULL
+     */
+    public function getCurrentPermissions()
+    {
+        $data = array();
+        $acl = new Horde_Kolab_Storage_Folder_Permission_AclIterator(
+            $this->_folder->getAcl(),
+            $this->_groups,
+            $this->_folder->getOwner()
+        );
+        foreach ($acl as $element) {
+            $element->toHorde($data);
+        }
+        return $data;
+    }
+
+    /**
+     * Saves the current permission values from the cache to the IMAP folder.
+     *
+     * @return NULL
+     */
+    public function save()
+    {
+        /**
+         * @todo: If somebody else accessed the folder before us, we will
+         * overwrite the change here.
+         */
+        $current = $this->getCurrentPermissions();
+
+        $elements = new Horde_Kolab_Storage_Folder_Permission_ElementIterator(
+            $this->data, $this->_groups, $this->_folder->getOwner()
+        );
+        foreach ($elements as $element) {
+            $this->_folder->setAcl($element->getId(), $element->fromHorde());
+            $element->unsetInCurrent($current);
+        }
+
+        // Delete ACLs that have been removed
+        $elements = new Horde_Kolab_Storage_Folder_Permission_ElementIterator(
+            $current, $this->_groups, $this->_folder->getOwner()
+        );
+        foreach ($elements as $element) {
+            $this->_folder->deleteAcl($element->getId());
+        }
+
+        // Load the permission from the folder again
+        $this->data = $this->getCurrentPermissions();
+    }
+
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl.php
new file mode 100644 (file)
index 0000000..2146d9d
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Maps a single Kolab_Storage ACL element to the Horde permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Kolab_Storage ACL element to the Horde permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+abstract class Horde_Kolab_Storage_Folder_Permission_Acl
+{
+    /**
+     * The ACL.
+     *
+     * @var string
+     */
+    private $_acl;
+
+    /**
+     * Constructor.
+     *
+     * @param string $acl The folder ACL element as provided by the driver.
+     */
+    public function __construct($acl)
+    {
+        $this->_acl = $acl;
+    }
+
+    /**
+     * Convert the Acl string to a Horde_Perms:: mask and store it in the
+     * provided data array.
+     *
+     * @param array &$data The horde permission data.
+     *
+     * @return NULL
+     */
+    abstract public function toHorde(array &$data);
+
+    /**
+     * Convert the Acl string to a Horde_Perms:: mask.
+     *
+     * @return int The permission mask
+     */
+    protected function convertAclToMask()
+    {
+        $result = 0;
+        if (strpos($this->_acl, 'l') !== false) {
+            $result |= Horde_Perms::SHOW;
+        }
+        if (strpos($this->_acl, 'r') !== false) {
+            $result |= Horde_Perms::READ;
+        }
+        if (strpos($this->_acl, 'i') !== false) {
+            $result |= Horde_Perms::EDIT;
+        }
+        if (strpos($this->_acl, 'd') !== false) {
+            $result |= Horde_Perms::DELETE;
+        }
+        return $result;
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anonymous.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anonymous.php
new file mode 100644 (file)
index 0000000..ca503d7
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Maps a single Kolab_Storage anonymous ACL element to the Horde permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Kolab_Storage anonymous ACL element to the Horde permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Acl_Anonymous
+extends Horde_Kolab_Storage_Folder_Permission_Acl
+{
+    /**
+     * Convert the Acl string to a Horde_Perms:: mask and store it in the
+     * provided data array.
+     *
+     * @param array &$data The horde permission data.
+     *
+     * @return NULL
+     */
+    public function toHorde(array &$data)
+    {
+        $data['guest'] = $this->convertAclToMask();
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anyone.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anyone.php
new file mode 100644 (file)
index 0000000..9ea1e49
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Maps a single Kolab_Storage known user ACL element to the Horde permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Kolab_Storage known user ACL element to the Horde permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Acl_Anyone
+extends Horde_Kolab_Storage_Folder_Permission_Acl
+{
+    /**
+     * Convert the Acl string to a Horde_Perms:: mask and store it in the
+     * provided data array.
+     *
+     * @param array &$data The horde permission data.
+     *
+     * @return NULL
+     */
+    public function toHorde(array &$data)
+    {
+        $data['default'] = $this->convertAclToMask();
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Creator.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Creator.php
new file mode 100644 (file)
index 0000000..6ff6c1d
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Maps a single Kolab_Storage creator ACL element to the Horde permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Kolab_Storage creator ACL element to the Horde permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Acl_Creator
+extends Horde_Kolab_Storage_Folder_Permission_Acl
+{
+    /**
+     * Convert the Acl string to a Horde_Perms:: mask and store it in the
+     * provided data array.
+     *
+     * @param array &$data The horde permission data.
+     *
+     * @return NULL
+     */
+    public function toHorde(array &$data)
+    {
+        $data['creator'] = $this->convertAclToMask();
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Group.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/Group.php
new file mode 100644 (file)
index 0000000..e13c90f
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Maps a single Kolab_Storage group ACL element to the Horde permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Kolab_Storage group ACL element to the Horde permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Acl_Group
+extends Horde_Kolab_Storage_Folder_Permission_Acl
+{
+    /**
+     * The group id.
+     *
+     * @var string
+     */
+    private $_id;
+
+    /**
+     * The group handler.
+     *
+     * @var Group
+     */
+    private $_groups;
+
+    /**
+     * Constructor.
+     *
+     * @param string $acl    The folder ACL element as provided by the driver.
+     * @param string $id     The group id.
+     * @param Group  $groups The horde group handler.
+     */
+    public function __construct($acl, $id, Group $groups)
+    {
+        $this->_id     = $id;
+        $this->_groups = $groups;
+        parent::__construct($acl);
+    }
+
+    /**
+     * Convert the Acl string to a Horde_Perms:: mask and store it in the
+     * provided data array.
+     *
+     * @param array &$data The horde permission data.
+     *
+     * @return NULL
+     */
+    public function toHorde(array &$data)
+    {
+        $data['groups'][$this->_groups->getGroupId($this->_id)] = $this->convertAclToMask();
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/User.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Acl/User.php
new file mode 100644 (file)
index 0000000..d436b3e
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Maps a single Kolab_Storage user ACL element to the Horde permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Kolab_Storage user ACL element to the Horde permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Acl_User
+extends Horde_Kolab_Storage_Folder_Permission_Acl
+{
+    /**
+     * The group id.
+     *
+     * @var string
+     */
+    private $_id;
+
+    /**
+     * Constructor.
+     *
+     * @param string $acl    The folder ACL element as provided by the driver.
+     * @param string $id     The group id.
+     */
+    public function __construct($acl, $id)
+    {
+        $this->_id = $id;
+        parent::__construct($acl);
+    }
+
+    /**
+     * Convert the Acl string to a Horde_Perms:: mask and store it in the
+     * provided data array.
+     *
+     * @param array &$data The horde permission data.
+     *
+     * @return NULL
+     */
+    public function toHorde(array &$data)
+    {
+        $data['users'][$this->_id] = $this->convertAclToMask();
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/AclIterator.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/AclIterator.php
new file mode 100644 (file)
index 0000000..8f1c778
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Maps Kolab_Storage ACL to the Horde permission system.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps Kolab_Storage ACL to the Horde permission system.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_AclIterator
+implements Iterator
+{
+    /**
+     * The ACL elements.
+     *
+     * @var array
+     */
+    private $_acl = array();
+
+    /**
+     * Constructor.
+     *
+     * @param array       $acl     The folder ACL as provided by the driver.
+     * @param Horde_Group $groups  The group handler.
+     * @param string      $creator The ID of the folder creator.
+     */
+    public function __construct(array $acl, Group $groups, $creator)
+    {
+        foreach ($acl as $user => $rights) {
+            if ($user == $creator) {
+                $this->_acl[] = new Horde_Kolab_Storage_Folder_Permission_Acl_Creator(
+                    $rights
+                );
+            } else if (substr($user, 0, 6) == 'group:') {
+                $this->_acl[] = new Horde_Kolab_Storage_Folder_Permission_Acl_Group(
+                    $rights, substr($user, 6), $groups
+                );
+            } else if ($user == 'anyone' || $user == 'anonymous'){
+                $class = 'Horde_Kolab_Storage_Folder_Permission_Acl_' . ucfirst($user);
+                $this->_acl[] = new $class(
+                    $rights
+                );
+            } else {
+                $this->_acl[] = new Horde_Kolab_Storage_Folder_Permission_Acl_User(
+                    $rights, $user
+                );
+            }
+        }
+    }
+
+    public function rewind()
+    {
+        return reset($this->_acl);
+    }
+
+    public function current()
+    {
+        return current($this->_acl);
+    }
+
+    public function key()
+    {
+        return key($this->_acl);
+    }
+
+    public function next()
+    {
+        return next($this->_acl);
+    }
+
+    public function valid()
+    {
+        return key($this->_acl) !== null;
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element.php
new file mode 100644 (file)
index 0000000..d3ad637
--- /dev/null
@@ -0,0 +1,99 @@
+<?php
+/**
+ * Maps a single Horde permission element to a Kolab_Storage ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Horde permission element to a Kolab_Storage ACL.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+abstract class Horde_Kolab_Storage_Folder_Permission_Element
+{
+    /**
+     * The permission.
+     *
+     * @var int
+     */
+    private $_permission;
+
+    /**
+     * Constructor.
+     *
+     * @param int $permission The folder permission as provided by Horde.
+     */
+    public function __construct($permission)
+    {
+        $this->_permission = $permission;
+    }
+
+    /**
+     * Convert the Horde_Perms:: mask to a Acl string.
+     *
+     * @return string The ACL string.
+     */
+    public function fromHorde()
+    {
+        return $this->convertMaskToAcl();
+    }
+
+    /**
+     * Get the Kolab_Storage ACL id for this permission.
+     *
+     * @return string The ACL string.
+     */
+    abstract public function getId();
+
+    /**
+     * Unset the element in the provided permission array.
+     *
+     * @param array &$current The current permission array.
+     *
+     * @return NULL
+     */
+    public function unsetInCurrent(&$current)
+    {
+        unset($current[$this->getId()]);
+    }
+
+    /**
+     * Convert the a Horde_Perms:: mask to a Acl string.
+     *
+     * @return string The ACL
+     */
+    protected function convertMaskToAcl()
+    {
+        $result = '';
+        if ($this->_permission & Horde_Perms::SHOW) {
+            $result .= 'l';
+        }
+        if ($this->_permission & Horde_Perms::READ) {
+            $result .= 'r';
+        }
+        if ($this->_permission & Horde_Perms::EDIT) {
+            $result .= 'iswc';
+        }
+        if ($this->_permission & Horde_Perms::DELETE) {
+            $result .= 'd';
+        }
+
+        return $result;
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Creator.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Creator.php
new file mode 100644 (file)
index 0000000..00f0421
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Maps a single Horde creator permission element to a Kolab_Storage ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Horde creator permission element to a Kolab_Storage ACL.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Element_Creator
+extends Horde_Kolab_Storage_Folder_Permission_Element
+{
+    /**
+     * The creator id.
+     *
+     * @var string
+     */
+    private $_creator;
+
+    /**
+     * Constructor.
+     *
+     * @param int    $permission The folder permission as provided by Horde.
+     * @param string $creator    The folder owner.
+     */
+    public function __construct($permission, $creator)
+    {
+        $this->_creator = $creator;
+        parent::__construct($permission);
+    }
+
+    /**
+     * Convert the Horde_Perms:: mask to a Acl string.
+     *
+     * @return string The ACL string.
+     */
+    public function fromHorde()
+    {
+        return 'a' . $this->convertMaskToAcl();
+    }
+
+    /**
+     * Get the Kolab_Storage ACL id for this permission.
+     *
+     * @return string The ACL string.
+     */
+    public function getId()
+    {
+        return $this->_creator;
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Default.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Default.php
new file mode 100644 (file)
index 0000000..e51f5cc
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Maps a single Horde default permission element to a Kolab_Storage ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Horde default permission element to a Kolab_Storage ACL.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Element_Default
+extends Horde_Kolab_Storage_Folder_Permission_Element
+{
+    /**
+     * Get the Kolab_Storage ACL id for this permission.
+     *
+     * @return string The ACL string.
+     */
+    public function getId()
+    {
+        return 'anyone';
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Group.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Group.php
new file mode 100644 (file)
index 0000000..2bd5030
--- /dev/null
@@ -0,0 +1,80 @@
+<?php
+/**
+ * Maps a single Horde group permission element to a Kolab_Storage ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Horde group permission element to a Kolab_Storage ACL.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Element_Group
+extends Horde_Kolab_Storage_Folder_Permission_Element
+{
+    /**
+     * The Horde group id.
+     *
+     * @var string
+     */
+    private $_horde_id;
+
+    /**
+     * The Kolab group id.
+     *
+     * @var string
+     */
+    private $_kolab_id;
+
+    /**
+     * Constructor.
+     *
+     * @param int    $permission The folder permission as provided by Horde.
+     * @param string $id         The group id.
+     * @param Group  $groups     The horde group handler.
+     */
+    public function __construct($permission, $id, Group $groups)
+    {
+        $this->_horde_id = $id;
+        $this->_kolab_id = 'group:' . $groups->getGroupName($id);
+        parent::__construct($permission);
+    }
+
+    /**
+     * Get the Kolab_Storage ACL id for this permission.
+     *
+     * @return string The ACL string.
+     */
+    public function getId()
+    {
+        return $this->_kolab_id;
+    }
+
+    /**
+     * Unset the element in the provided permission array.
+     *
+     * @param array &$current The current permission array.
+     *
+     * @return NULL
+     */
+    public function unsetInCurrent(&$current)
+    {
+        unset($current['groups'][$this->_horde_id]);
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Guest.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/Guest.php
new file mode 100644 (file)
index 0000000..8fb8fe3
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Maps a single Horde guest permission element to a Kolab_Storage ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Horde guest permission element to a Kolab_Storage ACL.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Element_Guest
+extends Horde_Kolab_Storage_Folder_Permission_Element
+{
+    /**
+     * Get the Kolab_Storage ACL id for this permission.
+     *
+     * @return string The ACL string.
+     */
+    public function getId()
+    {
+        return 'anonymous';
+    }
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/User.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/Element/User.php
new file mode 100644 (file)
index 0000000..3dbca78
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Maps a single Horde user permission element to a Kolab_Storage ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps a single Horde user permission element to a Kolab_Storage ACL.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_Element_User
+extends Horde_Kolab_Storage_Folder_Permission_Element
+{
+    /**
+     * The group id.
+     *
+     * @var string
+     */
+    private $_id;
+
+    /**
+     * Constructor.
+     *
+     * @param int    $permission The folder permission as provided by Horde.
+     * @param string $id         The user id.
+     */
+    public function __construct($permission, $id)
+    {
+        $this->_id = $id;
+        parent::__construct($permission);
+    }
+
+    /**
+     * Get the Kolab_Storage ACL id for this permission.
+     *
+     * @return string The ACL string.
+     */
+    public function getId()
+    {
+        return $this->_id;
+    }
+
+    /**
+     * Unset the element in the provided permission array.
+     *
+     * @param array &$current The current permission array.
+     *
+     * @return NULL
+     */
+    public function unsetInCurrent(&$current)
+    {
+        unset($current['users'][$this->getId()]);
+    }
+
+}
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/ElementIterator.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Folder/Permission/ElementIterator.php
new file mode 100644 (file)
index 0000000..807cdff
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Maps Horde permission elements into Kolab_Storage ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Maps Horde permission elements into Kolab_Storage ACL.
+ *
+ * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Folder_Permission_ElementIterator
+implements Iterator
+{
+    /**
+     * The Horde permission elements.
+     *
+     * @var array
+     */
+    private $_elements = array();
+
+    /**
+     * Constructor.
+     *
+     * @param array       $permissions The folder permissions as provided by Horde.
+     * @param Horde_Group $groups      The group handler.
+     * @param string      $creator     The ID of the folder creator.
+     */
+    public function __construct(array $permissions, Group $groups, $creator)
+    {
+        foreach ($permissions as $user => $user_perms) {
+            if ($user == 'default') {
+                $this->_elements[] = new Horde_Kolab_Storage_Folder_Permission_Element_Default(
+                    $user_perms
+                );
+            } else if ($user == 'guest') {
+                $this->_elements[] = new Horde_Kolab_Storage_Folder_Permission_Element_Guest(
+                    $user_perms
+                );
+            } else if ($user == 'creator') {
+                $this->_elements[] = new Horde_Kolab_Storage_Folder_Permission_Element_Creator(
+                    $user_perms, $creator
+                );
+            } else if ($user == 'groups') {
+                foreach ($user_perms as $user_entry => $perms) {
+                    $this->_elements[] = new Horde_Kolab_Storage_Folder_Permission_Element_Group(
+                        $perms, $user_entry, $groups
+                    );
+                }
+            } else if ($user == 'users') {
+                foreach ($user_perms as $user_entry => $perms) {
+                    $this->_elements[] = new Horde_Kolab_Storage_Folder_Permission_Element_User(
+                        $perms, $user_entry
+                    );
+                }
+            }
+        }
+    }
+
+    public function rewind()
+    {
+        return reset($this->_elements);
+    }
+
+    public function current()
+    {
+        return current($this->_elements);
+    }
+
+    public function key()
+    {
+        return key($this->_elements);
+    }
+
+    public function next()
+    {
+        return next($this->_elements);
+    }
+
+    public function valid()
+    {
+        return key($this->_elements) !== null;
+    }
+}
index 1748227..b9f41ae 100644 (file)
@@ -35,7 +35,7 @@ extends  Horde_Kolab_Storage_Namespace_Config
     /**
      * Constructor.
      */
-    public function __construct(array $namespaces, array $configuration)
+    public function __construct(array $namespaces, array $configuration = array())
     {
         $c = array();
         foreach ($namespaces as $namespace) {
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Permission.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Permission.php
deleted file mode 100644 (file)
index 2fc3b75..0000000
+++ /dev/null
@@ -1,402 +0,0 @@
-<?php
-/**
- * Maps IMAP permissions into the Horde_Permission system.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package  Kolab_Storage
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Storage
- */
-
-/**
- * The Autoloader allows us to omit "require/include" statements.
- */
-require_once 'Horde/Autoloader.php';
-
-/**
- * Packages that aren't autoloadable yet
- */
-require_once 'Horde/Group.php';
-
-/**
- * The Horde_Kolab_Storage_Permission provides a bridge between Horde Permission
- * handling and the IMAP permission system used on the Kolab server.
- *
- * Copyright 2006-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_Storage
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Storage
- */
-class Horde_Kolab_Storage_Permission extends Horde_Perms_Permission
-{
-    /**
-     * The folder name.
-     *
-     * @var string
-     */
-    protected $_folder;
-
-    /**
-     * A cache for the folder acl settings. The cache holds the permissions
-     * in horde compatible format, not in the IMAP permission format.
-     *
-     * @var string
-     */
-    public $data;
-
-    /**
-     * A cache for the raw IMAP folder acl settings.
-     *
-     * @var string
-     */
-    protected $acl;
-
-    /**
-     * Constructor.
-     *
-     * @param Horde_Kolab_Storage_Folder $folder The Kolab Folder these
-     *                                           permissions belong to.
-     * @param array                      $perms  A set of initial
-     *                                           permissions.
-     */
-    public function __construct($folder, $perms = null)
-    {
-        $this->setFolder($folder);
-        if (!isset($perms)) {
-            $result = $this->getPerm();
-            if ($result instanceOf PEAR_Error) {
-                Horde::logMessage(sprintf("Failed parsing permission information. Error was: %s", $result->getMessage()), 'INFO');
-            } else {
-                $perms = $result;
-            }
-        }
-        $this->data = $perms;
-
-    }
-
-    /**
-     * Returns the properties that need to be serialized.
-     *
-     * @return array  List of serializable properties.
-     */
-    public function __sleep()
-    {
-        $properties = get_object_vars($this);
-        unset($properties['_folder']);
-        $properties = array_keys($properties);
-        return $properties;
-    }
-
-    /**
-     * Sets the folder object for this permission object.
-     *
-     * @param Horde_Kolab_Storage_Folder $folder Kolab Folder object.
-     */
-    public function setFolder(Horde_Kolab_Storage_Folder $folder)
-    {
-        $this->_folder = $folder;
-    }
-
-    /**
-     * Gets one of the attributes of the object, or null if it isn't defined.
-     *
-     * @param string $attribute  The attribute to get.
-     *
-     * @return mixed  The value of the attribute, or null.
-     */
-    public function get($attribute)
-    {
-        // This object only handles permissions. So only return these
-        switch ($attribute) {
-        case 'perm':
-            return $this->data;
-        case 'type':
-            return 'matrix';
-        default:
-            // User requested something other than permissions: return null
-            return null;
-        }
-    }
-
-    /**
-     * Gets the current permission of the folder and stores the values in the
-     * cache.
-     *
-     * @return array|PEAR_Error  The data array representing the permissions.
-     */
-    public function getPerm()
-    {
-        try {
-            $acl = $this->_folder->getACL();
-        } catch (Horde_Kolab_Storage_Exception $e) {
-            Horde::logMessage($acl, 'INFO');
-            return array();
-        }
-        if (empty($acl)) {
-            return array();
-        }
-        $this->acl = &$acl;
-
-        // Loop through the returned users
-        $data = array();
-        foreach ($acl as $user => $r) {
-            // Convert the user rights to horde format
-            $result = 0;
-            $rights = join('', $r);
-            for ($i = 0, $j = strlen($rights); $i < $j; $i++) {
-                switch ($rights[$i]) {
-                case 'l':
-                    $result |= Horde_Perms::SHOW;
-                    break;
-                case 'r':
-                    $result |= Horde_Perms::READ;
-                    break;
-                case 'i':
-                    $result |= Horde_Perms::EDIT;
-                    break;
-                case 'd':
-                    $result |= Horde_Perms::DELETE;
-                    break;
-                }
-            }
-
-            // Check for special users
-            $name = '';
-            switch ($user) {
-            case 'anyone':
-                $name = 'default';
-                break;
-            case 'anonymous':
-                $name = 'guest';
-                break;
-            }
-
-            // Did we have a special user?
-            if ($name) {
-                // Store the converted acl in the cache
-                $data[$name] = $result;
-                continue;
-            }
-
-            // Is it a group?
-            if (substr($user, 0, 6) == 'group:') {
-                if (!isset($groups)) {
-                    $groups = Group::singleton();
-                }
-                $group_id = $groups->getGroupId(substr($user, 6));
-                if ($group_id instanceOf PEAR_Error) {
-                    // Store the converted acl in the cache
-                    $data['groups'][$group_id] = $result;
-                }
-
-                continue;
-            }
-
-            // Standard user
-            // Store the converted acl in the cache
-            $data['users'][$user] = $result;
-        }
-
-        return $data;
-    }
-
-    /**
-     * Saves the current permission values from the cache to the IMAP folder.
-     *
-     * @return boolean|PEAR_Error True on success, false if there is
-     *                            nothing to save.
-     */
-    public function save()
-    {
-        if (!isset($this->data)) {
-            return false;
-        }
-
-        // FIXME: If somebody else accessed the folder before us, we will overwrite
-        //        the change here.
-        $current = $this->getPerm();
-
-        foreach ($this->data as $user => $user_perms) {
-            if (is_array($user_perms)) {
-                foreach ($user_perms as $userentry => $perms) {
-                    if ($user == 'groups') {
-                        if (!isset($groups)) {
-                            $groups = Group::singleton();
-                        }
-                        // Convert group id back to name
-                        $group_name = $groups->getGroupName($userentry);
-                        $name = 'group:' . $group_name;
-                    } else if ($user == 'users') {
-                        $name = $userentry;
-                    } else {
-                        continue;
-                    }
-                    $this->savePermission($name, $perms);
-                    unset($current[$user][$userentry]);
-                }
-            } else {
-                if ($user == 'default') {
-                    $name = 'anyone';
-                } else if ($user == 'guest') {
-                    $name = 'anonymous';
-                } else {
-                    continue;
-                }
-                $this->savePermission($name, $user_perms);
-                unset($current[$user]);
-            }
-        }
-
-        // Delete ACLs that have been removed
-        foreach ($current as $user => $user_perms) {
-            if (is_array($user_perms)) {
-                foreach ($user_perms as $userentry => $perms) {
-                    if ($user == 'groups') {
-                        if (!isset($groups)) {
-                            $groups = Group::singleton();
-                        }
-                        // Convert group id back to name
-                        $group_name = $groups->getGroupName($userentry);
-                        $name = 'group:' . $group_name;
-                    } else {
-                        $name = $userentry;
-                    }
-
-                    $this->_folder->deleteACL($name);
-                }
-            } else {
-                if ($user == 'default') {
-                    $name = 'anyone';
-                } else if ($user == 'guest') {
-                    $name = 'anonymous';
-                } else {
-                    continue;
-                }
-                $this->_folder->deleteACL($name);
-            }
-        }
-
-        // Load the permission from the folder again
-        $this->data = $this->getPerm();
-
-        return true;
-    }
-
-    /**
-     * Saves the specified permission values for the given user on the
-     * IMAP folder.
-     *
-     * @return boolean|PEAR_Error  True on success.
-     */
-    public function savePermission($user, $perms)
-    {
-        // Convert the horde permission style to IMAP permissions
-        $result = $user == $this->_folder->getOwner() ? 'a' : '';
-        if ($perms & Horde_Perms::SHOW) {
-            $result .= 'l';
-        }
-        if ($perms & Horde_Perms::READ) {
-            $result .= 'r';
-        }
-        if ($perms & Horde_Perms::EDIT) {
-            $result .= 'iswc';
-        }
-        if ($perms & Horde_Perms::DELETE) {
-            $result .= 'd';
-        }
-
-        return $this->_folder->setACL($user, $result);
-    }
-
-    /**
-     * Finds out what rights the given user has to this object.
-     *
-     * @param string $user The user to check for. Defaults to the current
-     * user.
-     * @param string $creator The user who created the object.
-     *
-     * @return mixed A bitmask of permissions, a permission value, or
-     *               an array of permission values the user has,
-     *               depending on the permission type and whether the
-     *               permission value is ambiguous. False if there is
-     *               no such permsission.
-     */
-    public function getPermissions($user = null, $creator = null)
-    {
-        if ($user === null) {
-            $user = Auth::getAuth();
-        }
-        // If $creator was specified, check creator permissions.
-        if ($creator !== null) {
-            // If the user is the creator see if there are creator
-            // permissions.
-            if (strlen($user) && $user === $creator &&
-                ($perms = $this->getCreatorPermissions()) !== null) {
-                return $perms;
-            }
-        }
-
-        // Check user-level permissions.
-        $userperms = $this->getUserPermissions();
-        if (isset($userperms[$user])) {
-            return $userperms[$user];
-        }
-
-        // If no user permissions are found, try group permissions.
-        $groupperms = $this->getGroupPermissions();
-        if (!empty($groupperms)) {
-            $groups = Group::singleton();
-
-            $composite_perm = null;
-            foreach ($this->data['groups'] as $group => $perm) {
-                $result = $groups->userIsInGroup($user, $group);
-                if (is_a($result, 'PEAR_Error')) {
-                    return $result;
-                }
-
-                if ($result) {
-                    if ($composite_perm === null) {
-                        $composite_perm = 0;
-                    }
-                    $composite_perm |= $perm;
-                }
-            }
-
-            if ($composite_perm !== null) {
-                return $composite_perm;
-            }
-        }
-
-        // If there are default permissions, return them.
-        if (($perms = $this->getDefaultPermissions()) !== null) {
-            return $perms;
-        }
-
-        // Otherwise, deny all permissions to the object.
-        return false;
-    }
-
-    /**
-     * Finds out if the user has the specified rights to the given object.
-     *
-     * @param string $user    The user to check for.
-     * @param integer $perm   The permission level that needs to be checked
-     *                        for.
-     * @param string $creator The creator of the shared object.
-     *
-     * @return boolean True if the user has the specified permissions.
-     */
-    public function hasPermission($user, $perm, $creator = null)
-    {
-        return ($this->getPermissions($user, $creator) & $perm);
-    }
-}
index 86297d7..e154aaa 100644 (file)
@@ -31,8 +31,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-03-11</date>
- <time>20:56:19</time>
+ <date>2010-04-07</date>
+ <time>19:47:51</time>
  <version>
   <release>0.4.0</release>
   <api>0.1.0</api>
        <dir name="Driver">
         <file name="Imap.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Storage/Driver -->
-       <file name="Cache.php" role="php" />
-       <file name="Data.php" role="php" />
-       <file name="Driver.php" role="php" />
-       <file name="Exception.php" role="php" />
-       <file name="Folder.php" role="php" />
        <dir name="Folder">
-        <file name="Base.php" role="php" />
         <dir name="Decorator">
          <file name="Base.php" role="php" />
          <file name="Trigger.php" role="php" />
         </dir> <!-- /lib/Horde/Kolab/Storage/Folder/Decorator -->
+        <dir name="Permission">
+         <dir name="Acl">
+          <file name="Anonymous.php" role="php" />
+          <file name="Anyone.php" role="php" />
+          <file name="Creator.php" role="php" />
+          <file name="Group.php" role="php" />
+          <file name="User.php" role="php" />
+         </dir> <!-- /lib/Horde/Kolab/Storage/Folder/Permission/Acl -->
+         <dir name="Element">
+          <file name="Creator.php" role="php" />
+          <file name="Default.php" role="php" />
+          <file name="Group.php" role="php" />
+          <file name="Guest.php" role="php" />
+          <file name="User.php" role="php" />
+         </dir> <!-- /lib/Horde/Kolab/Storage/Folder/Permission/Element -->
+         <file name="Acl.php" role="php" />
+         <file name="AclIterator.php" role="php" />
+         <file name="Element.php" role="php" />
+         <file name="ElementIterator.php" role="php" />
+        </dir> <!-- /lib/Horde/Kolab/Storage/Folder/Permission -->
+        <file name="Base.php" role="php" />
+        <file name="Permission.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Storage/Folder -->
-       <file name="Namespace.php" role="php" />
        <dir name="Namespace">
-        <file name="Config.php" role="php" />
-        <file name="Element.php" role="php" />
         <dir name="Element">
          <file name="Other.php" role="php" />
          <file name="Personal.php" role="php" />
          <file name="Shared.php" role="php" />
          <file name="SharedWithPrefix.php" role="php" />
-        </dir> <!-- /lib/Horde/Kolab/Storage/Element -->
+        </dir> <!-- /lib/Horde/Kolab/Storage/Namespace/Element -->
+        <file name="Config.php" role="php" />
+        <file name="Element.php" role="php" />
         <file name="Fixed.php" role="php" />
         <file name="Imap.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Storage/Namespace -->
-       <file name="Permission.php" role="php" />
+       <file name="Cache.php" role="php" />
+       <file name="Data.php" role="php" />
+       <file name="Driver.php" role="php" />
+       <file name="Exception.php" role="php" />
+       <file name="Folder.php" role="php" />
+       <file name="Namespace.php" role="php" />
       </dir> <!-- /lib/Horde/Kolab/Storage -->
       <file name="Storage.php" role="php" />
      </dir> <!-- /lib/Horde/Kolab -->
     <dir name="Horde">
      <dir name="Kolab">
       <dir name="Storage">
+       <file name="AclTest.php" role="test" />
        <file name="AllTests.php" role="test" />
        <file name="AttachmentTest.php" role="test" />
        <file name="Autoload.php" role="test" />
        <file name="CacheTest.php" role="test" />
        <file name="DataTest.php" role="test" />
        <file name="FolderTest.php" role="test" />
-       <file name="PermsTest.php" role="test" />
+       <file name="NamespaceTest.php" role="test" />
+       <file name="PermissionTest.php" role="test" />
        <file name="phpunit.xml" role="test" />
        <file name="Scenario.php" role="test" />
        <file name="StorageTest.php" role="test" />
      </dir> <!-- /test/Horde/Kolab -->
     </dir> <!-- /test/Horde -->
    </dir> <!-- /test -->
+   <file name="TODO" role="data" />
   </dir> <!-- / -->
  </contents>
  <dependencies>
    <install as="Horde/Kolab/Storage/Driver.php" name="lib/Horde/Kolab/Storage/Driver.php" />
    <install as="Horde/Kolab/Storage/Exception.php" name="lib/Horde/Kolab/Storage/Exception.php" />
    <install as="Horde/Kolab/Storage/Folder.php" name="lib/Horde/Kolab/Storage/Folder.php" />
+   <install as="Horde/Kolab/Storage/Namespace.php" name="lib/Horde/Kolab/Storage/Namespace.php" />
+   <install as="Horde/Kolab/Storage/Driver/Imap.php" name="lib/Horde/Kolab/Storage/Driver/Imap.php" />
    <install as="Horde/Kolab/Storage/Folder/Base.php" name="lib/Horde/Kolab/Storage/Folder/Base.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission.php" name="lib/Horde/Kolab/Storage/Folder/Permission.php" />
    <install as="Horde/Kolab/Storage/Folder/Decorator/Base.php" name="lib/Horde/Kolab/Storage/Folder/Decorator/Base.php" />
    <install as="Horde/Kolab/Storage/Folder/Decorator/Trigger.php" name="lib/Horde/Kolab/Storage/Folder/Decorator/Trigger.php" />
-   <install as="Horde/Kolab/Storage/Namespace.php" name="lib/Horde/Kolab/Storage/Namespace.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Acl.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Acl.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/AclIterator.php" name="lib/Horde/Kolab/Storage/Folder/Permission/AclIterator.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Element.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Element.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/ElementIterator.php" name="lib/Horde/Kolab/Storage/Folder/Permission/ElementIterator.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Acl/Anonymous.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anonymous.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Acl/Anyone.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Acl/Anyone.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Acl/Creator.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Acl/Creator.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Acl/Group.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Acl/Group.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Acl/User.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Acl/User.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Element/Creator.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Element/Creator.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Element/Default.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Element/Default.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Element/Group.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Element/Group.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Element/Guest.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Element/Guest.php" />
+   <install as="Horde/Kolab/Storage/Folder/Permission/Element/User.php" name="lib/Horde/Kolab/Storage/Folder/Permission/Element/User.php" />
    <install as="Horde/Kolab/Storage/Namespace/Config.php" name="lib/Horde/Kolab/Storage/Namespace/Config.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element.php" name="lib/Horde/Kolab/Storage/Namespace/Element.php" />
+   <install as="Horde/Kolab/Storage/Namespace/Fixed.php" name="lib/Horde/Kolab/Storage/Namespace/Fixed.php" />
+   <install as="Horde/Kolab/Storage/Namespace/Imap.php" name="lib/Horde/Kolab/Storage/Namespace/Imap.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element/Other.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Other.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element/Personal.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Personal.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element/Shared.php" name="lib/Horde/Kolab/Storage/Namespace/Element/Shared.php" />
    <install as="Horde/Kolab/Storage/Namespace/Element/SharedWithPrefix.php" name="lib/Horde/Kolab/Storage/Namespace/Element/SharedWithPrefix.php" />
-   <install as="Horde/Kolab/Storage/Namespace/Fixed.php" name="lib/Horde/Kolab/Storage/Namespace/Fixed.php" />
-   <install as="Horde/Kolab/Storage/Namespace/Imap.php" name="lib/Horde/Kolab/Storage/Namespace/Imap.php" />
-   <install as="Horde/Kolab/Storage/Permission.php" name="lib/Horde/Kolab/Storage/Permission.php" />
-   <install as="Horde/Kolab/Storage/Driver/Imap.php" name="lib/Horde/Kolab/Storage/Driver/Imap.php" />
+   <install as="Horde/Kolab/Storage/AclTest.php" name="test/Horde/Kolab/Storage/AclTest.php" />
    <install as="Horde/Kolab/Storage/AllTests.php" name="test/Horde/Kolab/Storage/AllTests.php" />
    <install as="Horde/Kolab/Storage/AttachmentTest.php" name="test/Horde/Kolab/Storage/AttachmentTest.php" />
    <install as="Horde/Kolab/Storage/Autoload.php" name="test/Horde/Kolab/Storage/Autoload.php" />
    <install as="Horde/Kolab/Storage/CacheTest.php" name="test/Horde/Kolab/Storage/CacheTest.php" />
    <install as="Horde/Kolab/Storage/DataTest.php" name="test/Horde/Kolab/Storage/DataTest.php" />
    <install as="Horde/Kolab/Storage/FolderTest.php" name="test/Horde/Kolab/Storage/FolderTest.php" />
-   <install as="Horde/Kolab/Storage/PermsTest.php" name="test/Horde/Kolab/Storage/PermsTest.php" />
+   <install as="Horde/Kolab/Storage/NamespaceTest.php" name="test/Horde/Kolab/Storage/NamespaceTest.php" />
+   <install as="Horde/Kolab/Storage/PermissionTest.php" name="test/Horde/Kolab/Storage/PermissionTest.php" />
    <install as="Horde/Kolab/Storage/phpunit.xml" name="test/Horde/Kolab/Storage/phpunit.xml" />
    <install as="Horde/Kolab/Storage/Scenario.php" name="test/Horde/Kolab/Storage/Scenario.php" />
    <install as="Horde/Kolab/Storage/StorageTest.php" name="test/Horde/Kolab/Storage/StorageTest.php" />
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-03-11</date>
+   <date>2010-04-07</date>
    <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
    <notes>
+* Added namespace support (Bug #6691).
+* Converted the package to Horde 4 / PHP 5.
 * Fixed list driver to prevent overwriting folder data when
   authenticating twice (relevant for testing).
 * Allow to supress triggering (relevant for testing).
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/AclTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/AclTest.php
new file mode 100644 (file)
index 0000000..109d8b2
--- /dev/null
@@ -0,0 +1,213 @@
+<?php
+/**
+ * Test the handling of ACL.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Autoload.php';
+
+/**
+ * Test the handling of ACL.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_AclTest extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->_storage = $this->getMock('Horde_Kolab_Storage', array(), array(), '', false, false);
+        $this->_imap = $this->getMock('Horde_Imap_Client_Socket', array(), array(), '', false, false);
+        $this->groups = $this->getMock('Group', array(), array(), '', false, false);
+        $this->_connection = new Horde_Kolab_Storage_Driver_Imap($this->_imap, $this->groups);
+        $this->_imap->expects($this->any())
+            ->method('getNamespaces')
+            ->will(
+                $this->returnValue(
+                    array(
+                        array(
+                            'name'      => 'INBOX/',
+                            'type'      =>  Horde_Kolab_Storage_Namespace::PERSONAL,
+                            'delimiter' => '/',
+                        ),
+                        array(
+                            'name'      => 'user/',
+                            'type'      =>  Horde_Kolab_Storage_Namespace::OTHER,
+                            'delimiter' => '/',
+                        ),
+                        array(
+                            'name'      => '',
+                            'type'      =>  Horde_Kolab_Storage_Namespace::SHARED,
+                            'delimiter' => '/',
+                        )
+                    )
+                )
+            );
+    }
+
+    public function testGetaclRetrievesFolderAcl()
+    {
+        $this->_supportAcl();
+        $this->_imap->expects($this->once())
+            ->method('listMailboxes')
+            ->will($this->returnValue(array('INBOX')));
+        $this->_imap->expects($this->once())
+            ->method('getAcl')
+            ->with('INBOX')
+            ->will($this->returnValue(array('user' => array('l', 'r', 'a'))));
+        $folder = $this->_getFolder('INBOX');
+        $this->assertEquals(array('user' => 'lra'), $folder->getAcl());
+    }
+
+    public function testGetaclRetrievesMyFolderAclOnFolderWithNoAdminRights()
+    {
+        $this->_supportAcl();
+        $this->_imap->expects($this->once())
+            ->method('listMailboxes')
+            ->will($this->returnValue(array('INBOX')));
+        $this->_imap->expects($this->once())
+            ->method('getAcl')
+            ->with('INBOX')
+            ->will($this->throwException(new Horde_Imap_Client_Exception()));
+        $this->_imap->expects($this->once())
+            ->method('getMyACLRights')
+            ->with('INBOX')
+            ->will($this->returnValue('lr'));
+        $this->_imap->expects($this->any())
+            ->method('getParam')
+            ->with('username')
+            ->will($this->returnValue('user'));
+        $folder = $this->_getFolder('INBOX');
+        $this->assertEquals(array('user' => 'lr'), $folder->getAcl());
+    }
+
+    public function testGetaclRetrievesMyFolderAclOnForeignFolderWithNoAdminRights()
+    {
+        $this->_supportAcl();
+        $this->_imap->expects($this->once())
+            ->method('listMailboxes')
+            ->will($this->returnValue(array('INBOX')));
+        $this->_imap->expects($this->once())
+            ->method('getMyACLRights')
+            ->with('user/test')
+            ->will($this->returnValue('lr'));
+        $this->_imap->expects($this->any())
+            ->method('getParam')
+            ->with('username')
+            ->will($this->returnValue('test'));
+        $folder = $this->_getFolder('user/test');
+        $this->assertEquals(array('test' => 'lr'), $folder->getAcl());
+    }
+
+    public function testGetaclRetrievesAllFolderAclOnForeignFolderWithAdminRights()
+    {
+        $this->_supportAcl();
+        $this->_imap->expects($this->once())
+            ->method('listMailboxes')
+            ->will($this->returnValue(array('INBOX')));
+        $this->_imap->expects($this->once())
+            ->method('getMyACLRights')
+            ->with('user/test')
+            ->will($this->returnValue('lra'));
+        $this->_imap->expects($this->once())
+            ->method('getAcl')
+            ->with('user/test')
+            ->will($this->returnValue(array('test' => 'lra')));
+        $this->_imap->expects($this->any())
+            ->method('getParam')
+            ->with('username')
+            ->will($this->returnValue('test'));
+        $folder = $this->_getFolder('user/test');
+        $this->assertEquals(array('test' => 'lra'), $folder->getAcl());
+    }
+
+    public function testSetacletsFolderAcl()
+    {
+        $this->_supportAcl();
+        $this->_imap->expects($this->once())
+            ->method('setAcl')
+            ->with('INBOX', 'user', array('rights' => 'lra'));
+        $folder = $this->_getFolder('INBOX');
+        $folder->setAcl('user', 'lra');
+    }
+
+    public function testDeleteaclDeletesFolderAcl()
+    {
+        $this->_supportAcl();
+        $this->_imap->expects($this->once())
+            ->method('setAcl')
+            ->with('INBOX', 'user', array('remove' => true));
+        $folder = $this->_getFolder('INBOX');
+        $folder->deleteAcl('user');
+    }
+
+    public function testGetaclRetrievesDefaultAclIfAclAreNotSupported()
+    {
+        $this->_imap->expects($this->once())
+            ->method('queryCapability')
+            ->with('ACL')
+            ->will($this->returnValue(false));
+        $this->_imap->expects($this->once())
+            ->method('listMailboxes')
+            ->will($this->returnValue(array('INBOX')));
+        $this->_imap->expects($this->any())
+            ->method('getParam')
+            ->with('username')
+            ->will($this->returnValue('user'));
+        $folder = $this->_getFolder('INBOX');
+        $this->assertEquals(array('user' => 'lrid'), $folder->getAcl());
+    }
+
+    public function testSetaclDoesNothingIfAclAreNotSupported()
+    {
+        $this->_imap->expects($this->once())
+            ->method('queryCapability')
+            ->with('ACL')
+            ->will($this->returnValue(false));
+        $folder = $this->_getFolder('INBOX');
+        $folder->setAcl('user', 'lr');
+    }
+
+    public function testDeleteaclDoesNothingIfAclAreNotSupported()
+    {
+        $this->_imap->expects($this->once())
+            ->method('queryCapability')
+            ->with('ACL')
+            ->will($this->returnValue(false));
+        $folder = $this->_getFolder('INBOX');
+        $folder->deleteAcl('user', 'lr');
+    }
+
+    private function _getFolder($name)
+    {
+        $folder = new Horde_Kolab_Storage_Folder_Base($name);
+        $folder->restore($this->_storage, $this->_connection);
+        return $folder;
+    }
+
+    private function _supportAcl()
+    {
+        $this->_imap->expects($this->any())
+            ->method('queryCapability')
+            ->with($this->logicalOr('ACL', 'NAMESPACE'))
+            ->will($this->returnValue(true));
+    }
+}
\ No newline at end of file
index 0b602f4..a3652c4 100644 (file)
@@ -46,4 +46,6 @@ if (!defined('HORE_KOLAB_STORAGE_TESTS')) {
     }
 
     Horde_Autoloader::addClassPath(HORE_KOLAB_STORAGE_TESTS);
-}
\ No newline at end of file
+}
+
+require_once 'Horde/Group.php';
index f408733..9af2982 100644 (file)
@@ -83,7 +83,9 @@ class Horde_Kolab_Storage_NamespaceTest extends PHPUnit_Framework_TestCase
     public function testFolderTitleIsAccessibleForNewFolders()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $_SESSION['horde_auth']['userId'] = 'test';
+            $this->_connection->expects($this->any())
+                ->method('getAuth')
+                ->will($this->returnValue('test'));
             $folder = $this->_getFolder(null, $namespace);
             $folder->setName('test');
             $this->assertEquals('test', $folder->getTitle());
@@ -93,7 +95,9 @@ class Horde_Kolab_Storage_NamespaceTest extends PHPUnit_Framework_TestCase
     public function testFolderOwnerIsCurrentUserIfPrefixMatchesPersonalNamespace()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $_SESSION['horde_auth']['userId'] = 'test';
+            $this->_connection->expects($this->any())
+                ->method('getAuth')
+                ->will($this->returnValue('test'));
             $folder = $this->_getFolder('INBOX', $namespace);
             $this->assertEquals('test', $folder->getOwner());
         }
@@ -102,7 +106,9 @@ class Horde_Kolab_Storage_NamespaceTest extends PHPUnit_Framework_TestCase
     public function testFolderOwnerIsCurrentUserIfPrefixContainsPersonalNamespace()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $_SESSION['horde_auth']['userId'] = 'test';
+            $this->_connection->expects($this->any())
+                ->method('getAuth')
+                ->will($this->returnValue('test'));
             $folder = $this->_getFolder('INBOX/mine', $namespace);
             $this->assertEquals('test', $folder->getOwner());
         }
@@ -135,7 +141,9 @@ class Horde_Kolab_Storage_NamespaceTest extends PHPUnit_Framework_TestCase
     public function testFolderOwnerIsAccessibleForNewFolders()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $_SESSION['horde_auth']['userId'] = 'test';
+            $this->_connection->expects($this->any())
+                ->method('getAuth')
+                ->will($this->returnValue('test'));
             $folder = $this->_getFolder(null, $namespace);
             $folder->setName('test');
             $this->assertEquals('test', $folder->getOwner());
@@ -145,7 +153,9 @@ class Horde_Kolab_Storage_NamespaceTest extends PHPUnit_Framework_TestCase
     public function testFolderOwnerHasDomainFromFolderDomain()
     {
         foreach ($this->_getNamespaces() as $namespace) {
-            $_SESSION['horde_auth']['userId'] = 'test@example.com';
+            $this->_connection->expects($this->any())
+                ->method('getAuth')
+                ->will($this->returnValue('test@example.com'));
             $folder = $this->_getFolder('user/test/mine', $namespace);
             $this->assertEquals('test@example.com', $folder->getOwner());
         }
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/PermissionTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/PermissionTest.php
new file mode 100644 (file)
index 0000000..47aec9e
--- /dev/null
@@ -0,0 +1,361 @@
+<?php
+/**
+ * Test the Kolab permission handler.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once 'Autoload.php';
+
+/**
+ * Test the Kolab permission handler.
+ *
+ * Copyright 2008-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_PermissionTest extends PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        $this->folder = $this->getMock('Horde_Kolab_Storage_Folder_Base', array(), array(), '', false, false);
+        $this->groups = $this->getMock('Group', array(), array(), '', false, false);
+        $this->perms = new Horde_Perms();
+    }
+
+    public function testConstruct()
+    {
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('test' => 'l')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertEquals('matrix', $permission->get('type'));
+    }
+
+    public function testImapListAclResultsInShowPermission()
+    {
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('test' => 'l')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertTrue((bool) $this->perms->hasPermission($permission, 'test', Horde_Perms::SHOW));
+    }
+
+    public function testImapReadAclResultsInReadPermission()
+    {
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('test' => 'r')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertTrue((bool) $this->perms->hasPermission($permission, 'test', Horde_Perms::READ));
+    }
+
+    public function testImapEditAclResultsInEditPermission()
+    {
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('test' => 'i')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertTrue((bool) $this->perms->hasPermission($permission, 'test', Horde_Perms::EDIT));
+    }
+
+    public function testImapDeleteAclResultsInDeletePermission() 
+    {
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('test' => 'd')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertTrue((bool) $this->perms->hasPermission($permission, 'test', Horde_Perms::DELETE));
+    }
+
+    public function testImapAnonymousUserMapsToGuestUsers()
+    {
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('anonymous' => 'lrid')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertEquals(Horde_Perms::ALL, $permission->getGuestPermissions());
+    }
+
+    public function testImapAnyoneUserMapsToDefaultUsers()
+    {
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('anyone' => 'lrid')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertEquals(Horde_Perms::ALL, $permission->getDefaultPermissions());
+    }
+
+    public function testImapOwnerUserMapsToCreator()
+    {
+        $storage = $this->getMock('Horde_Kolab_Storage', array(), array(), '', false, false);
+        $connection = $this->getMock('Horde_Kolab_Storage_Driver');
+        $connection->expects($this->any())
+            ->method('getNamespace')
+            ->will(
+                $this->returnValue(
+                    new Horde_Kolab_Storage_Namespace_Imap(
+                        array(
+                            array(
+                                'type' => Horde_Kolab_Storage_Namespace::PERSONAL,
+                                'name' => 'INBOX/',
+                                'delimiter' => '/',
+                                'add' => true,
+                            )
+                        )
+                    )
+                )
+            );
+        $connection->expects($this->any())
+            ->method('getAuth')
+            ->will($this->returnValue('test'));
+        $connection->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('test' => 'lrid')));
+        $folder = new Horde_Kolab_Storage_Folder_Base('INBOX/test');
+        $folder->restore($storage, $connection);
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $folder, $this->groups
+        );
+        $this->assertEquals(Horde_Perms::ALL, $permission->getCreatorPermissions());
+    }
+
+    public function testImapGroupMapsToHordeGroup()
+    {
+        $this->groups->expects($this->once())
+            ->method('getGroupId')
+            ->with('test')
+            ->will($this->returnValue('horde_test'));
+        $this->folder->expects($this->once())
+            ->method('getAcl')
+            ->will($this->returnValue(array('group:test' => 'lrid')));
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $this->assertEquals(array('horde_test' => Horde_Perms::ALL), $permission->getGroupPermissions());
+    }
+
+    public function testShowPermissionResultsInImapListAcl()
+    {
+        $this->folder->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $this->folder->expects($this->once())
+            ->method('setAcl')
+            ->with('test', 'l');
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $permission->addUserPermission('test', Horde_Perms::SHOW, true);
+    }
+
+    public function testReadPermissionResultsInImapReadAcl()
+    {
+        $this->folder->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $this->folder->expects($this->once())
+            ->method('setAcl')
+            ->with('test', 'r');
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $permission->addUserPermission('test', Horde_Perms::READ, true);
+    }
+
+    public function testEditPermissionResultsInImapEditAcl()
+    {
+        $this->folder->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $this->folder->expects($this->once())
+            ->method('setAcl')
+            ->with('test', 'iswc');
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $permission->addUserPermission('test', Horde_Perms::EDIT, true);
+    }
+
+    public function testDeletePermissionResultsInImapDeleteAcl() 
+    {
+        $this->folder->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $this->folder->expects($this->once())
+            ->method('setAcl')
+            ->with('test', 'd');
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $permission->addUserPermission('test', Horde_Perms::DELETE, true);
+    }
+
+    public function testGuestUsersMapsToImapAnonymousUser()
+    {
+        $this->folder->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $this->folder->expects($this->once())
+            ->method('setAcl')
+            ->with('anonymous', 'lriswcd');
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $permission->addGuestPermission(Horde_Perms::ALL, true);
+    }
+
+    public function testDefaultUsersMapsToImapAnyoneUser()
+    {
+        $this->folder->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $this->folder->expects($this->once())
+            ->method('setAcl')
+            ->with('anyone', 'lriswcd');
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $permission->addDefaultPermission(Horde_Perms::ALL, true);
+    }
+
+    public function testCreatorMapsToImapOwnerUser()
+    {
+        $storage = $this->getMock('Horde_Kolab_Storage', array(), array(), '', false, false);
+        $connection = $this->getMock('Horde_Kolab_Storage_Driver');
+        $connection->expects($this->any())
+            ->method('getNamespace')
+            ->will(
+                $this->returnValue(
+                    new Horde_Kolab_Storage_Namespace_Imap(
+                        array(
+                            array(
+                                'type' => Horde_Kolab_Storage_Namespace::PERSONAL,
+                                'name' => 'INBOX/',
+                                'delimiter' => '/',
+                                'add' => true,
+                            )
+                        )
+                    )
+                )
+            );
+        $connection->expects($this->any())
+            ->method('getAuth')
+            ->will($this->returnValue('test'));
+        $connection->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $connection->expects($this->once())
+            ->method('setAcl')
+            ->with('INBOX/test', 'test', 'alriswcd');
+        $folder = new Horde_Kolab_Storage_Folder_Base('INBOX/test');
+        $folder->restore($storage, $connection);
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $folder, $this->groups
+        );
+        $permission->addCreatorPermission(Horde_Perms::ALL, true);
+    }
+
+    public function testHordeGroupMapsToImapGroup()
+    {
+        $this->groups->expects($this->once())
+            ->method('getGroupName')
+            ->with('horde_test')
+            ->will($this->returnValue('test'));
+        $this->folder->expects($this->exactly(3))
+            ->method('getAcl')
+            ->will($this->returnValue(array()));
+        $this->folder->expects($this->once())
+            ->method('setAcl')
+            ->with('group:test', 'lriswcd');
+        $permission = new Horde_Kolab_Storage_Folder_Permission(
+            'test', $this->folder, $this->groups
+        );
+        $permission->addGroupPermission('horde_test', Horde_Perms::ALL, true);
+    }
+
+    /**
+     * Test saving permissions
+     */
+    public function testSave()
+    {
+        $this->markTestIncomplete('Currently broken');
+        $GLOBALS['conf']['auth']['driver'] = 'auto';
+        $GLOBALS['conf']['group']['driver'] = 'mock';
+
+        $folder = new DummyFolder(
+            array(
+                'wrobel' => array('l', 'r', 'i', 'd'),
+                'reader' => array('l', 'r'),
+                'viewer' => array('l'),
+                'editor' => array('l', 'r', 'e'),
+                'anyone' => array('l'),
+                'anonymous' => array(''),
+                'group:editors' => array('l', 'r', 'e')
+            ),
+            'wrobel'
+        );
+        $perms = new Horde_Kolab_Storage_Folder_Permissions_Default($folder);
+        $data = $perms->getData();
+        unset($data['guest']);
+        unset($data['default']);
+        unset($data['users']['viewer']);
+        $data['users']['editor'] = Horde_Perms::ALL;
+        $data['users']['test'] = Horde_Perms::SHOW | Horde_Perms::READ;
+        $data['groups']['group'] = Horde_Perms::SHOW | Horde_Perms::READ;
+        $perms->setData($data);
+        $perms->save();
+        $this->assertNotContains('anyone', array_keys($folder->acl));
+        $this->assertNotContains('anonymous', array_keys($folder->acl));
+        $this->assertEquals('lr', join('', $folder->acl['test']));
+        $this->assertEquals('lriswcd', join('', $folder->acl['editor']));
+        $this->assertEquals('alriswcd', join('', $folder->acl['wrobel']));
+    }
+
+    /**
+     * Test using Horde permissions.
+     */
+    public function testHordePermissions()
+    {
+        $this->markTestIncomplete('Currently broken');
+        $GLOBALS['conf']['auth']['driver'] = 'auto';
+        $GLOBALS['conf']['group']['driver'] = 'mock';
+
+        $folder = new DummyFolder(array(), 'wrobel');
+        $hperms = new Horde_Perms_Permission('test');
+        $hperms->addUserPermission('wrobel', Horde_Perms::SHOW, false);
+        $perms = new Horde_Kolab_Storage_Folder_Permissions_Default($folder, $hperms->data);
+        $perms->save();
+        $this->assertEquals('al', join('', $folder->acl['wrobel']));
+    }
+}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/PermsTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/PermsTest.php
deleted file mode 100644 (file)
index f5154ac..0000000
+++ /dev/null
@@ -1,176 +0,0 @@
-<?php
-/**
- * Test the Kolab permission handler.
- *
- * PHP version 5
- *
- * @category Kolab
- * @package  Kolab_Storage
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Storage
- */
-
-/**
- * Prepare the test setup.
- */
-require_once 'Autoload.php';
-
-/**
- * Test the Kolab permission handler.
- *
- * Copyright 2008-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_Storage
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Storage
- */
-class Horde_Kolab_Storage_PermsTest extends PHPUnit_Framework_TestCase
-{
-
-    /**
-     * Test class construction.
-     */
-    public function testConstruct()
-    {
-        $folder = new DummyFolder(null);
-        $perms = new Horde_Kolab_Storage_Permission($folder);
-        $this->assertEquals(array(), $perms->get('perm'));
-        $permissions =  array('users' =>
-                              array(
-                                  'wrobel' => Horde_Perms::ALL
-                              ));
-        $perms = new Horde_Kolab_Storage_Permission($folder, $permissions);
-        $this->assertTrue(is_array($perms->get('perm')));
-    }
-
-    /**
-     * Test retrieving permissions.
-     */
-    public function testGetPerm()
-    {
-        $this->markTestIncomplete('Currently broken');
-        $GLOBALS['conf']['auth']['driver'] = 'auto';
-        $GLOBALS['conf']['group']['driver'] = 'mock';
-
-        $folder = new DummyFolder(
-            array(
-                'wrobel' => array('l', 'r', 'i', 'd'),
-                'reader' => array('l', 'r'),
-                'viewer' => array('l'),
-                'editor' => array('l', 'r', 'e'),
-                'anyone' => array('l'),
-                'anonymous' => array(''),
-                'group:editors' => array('l', 'r', 'e')
-            )
-        );
-        $perms = new Horde_Kolab_Storage_Permission($folder);
-        $data = $perms->getData();
-        $this->assertContains('users', array_keys($data));
-        $this->assertContains('wrobel', array_keys($data['users']));
-        $this->assertContains('reader', array_keys($data['users']));
-        $this->assertContains('groups', array_keys($data));
-        $this->assertContains('default', array_keys($data));
-        $this->assertContains('guest', array_keys($data));
-    }
-
-    /**
-     * Test saving permissions
-     */
-    public function testSave()
-    {
-        $GLOBALS['conf']['auth']['driver'] = 'auto';
-        $GLOBALS['conf']['group']['driver'] = 'mock';
-
-        $folder = new DummyFolder(
-            array(
-                'wrobel' => array('l', 'r', 'i', 'd'),
-                'reader' => array('l', 'r'),
-                'viewer' => array('l'),
-                'editor' => array('l', 'r', 'e'),
-                'anyone' => array('l'),
-                'anonymous' => array(''),
-                'group:editors' => array('l', 'r', 'e')
-            ),
-            'wrobel'
-        );
-        $perms = new Horde_Kolab_Storage_Permission($folder);
-        $data = $perms->getData();
-        unset($data['guest']);
-        unset($data['default']);
-        unset($data['users']['viewer']);
-        $data['users']['editor'] = Horde_Perms::ALL;
-        $data['users']['test'] = Horde_Perms::SHOW | Horde_Perms::READ;
-        $data['groups']['group'] = Horde_Perms::SHOW | Horde_Perms::READ;
-        $perms->setData($data);
-        $perms->save();
-        $this->assertNotContains('anyone', array_keys($folder->acl));
-        $this->assertNotContains('anonymous', array_keys($folder->acl));
-        $this->assertEquals('lr', join('', $folder->acl['test']));
-        $this->assertEquals('lriswcd', join('', $folder->acl['editor']));
-        $this->assertEquals('alriswcd', join('', $folder->acl['wrobel']));
-    }
-
-    /**
-     * Test using Horde permissions.
-     */
-    public function testHordePermissions()
-    {
-        $GLOBALS['conf']['auth']['driver'] = 'auto';
-        $GLOBALS['conf']['group']['driver'] = 'mock';
-
-        $folder = new DummyFolder(array(), 'wrobel');
-        $hperms = new Horde_Perms_Permission('test');
-        $hperms->addUserPermission('wrobel', Horde_Perms::SHOW, false);
-        $perms = new Horde_Kolab_Storage_Permission($folder, $hperms->data);
-        $perms->save();
-        $this->assertEquals('al', join('', $folder->acl['wrobel']));
-    }
-}
-
-/**
- * A dummy folder representation to test the Kolab permission handler.
- *
- * Copyright 2008-2010 The Horde Project (http://www.horde.org/)
- *
- * See the enclosed file COPYING for license information (LGPL). If you
- * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
- *
- * @category Kolab
- * @package  Kolab_Storage
- * @author   Gunnar Wrobel <wrobel@pardus.de>
- * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
- * @link     http://pear.horde.org/index.php?package=Kolab_Storage
- */
-class DummyFolder extends Horde_Kolab_Storage_Folder_Base
-{
-    var $acl;
-    var $_owner;
-    function DummyFolder($acl, $owner = null)
-    {
-        $this->acl = $acl;
-        $this->_owner = $owner;
-    }
-    function getACL()
-    {
-        return $this->acl;
-    }
-    function setACL($user, $acl)
-    {
-        return $this->acl[$user] = str_split($acl);
-    }
-    function deleteACL($user)
-    {
-        unset($this->acl[$user]);
-    }
-    function getOwner()
-    {
-        return $this->_owner;
-    }
-}
-