From: Gunnar Wrobel Date: Fri, 14 Jan 2011 09:03:43 +0000 (+0100) Subject: Start with listShares(). X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d3aa627e20029e6b8939a1f436711bf3c060c721;p=horde.git Start with listShares(). --- diff --git a/framework/Share/lib/Horde/Share/Kolab.php b/framework/Share/lib/Horde/Share/Kolab.php index 1184f9ac3..90b97b3f1 100644 --- a/framework/Share/lib/Horde/Share/Kolab.php +++ b/framework/Share/lib/Horde/Share/Kolab.php @@ -65,6 +65,80 @@ class Horde_Share_Kolab extends Horde_Share_Base return $this->_storage; } + /** + * Returns an array of all shares that $userid has access to. + * + * @param string $userid The userid of the user to check access for. + * @param array $params See listShares(). + * + * @return array The shares the user has access to. + */ + protected function _listShares($userid, array $params = array()) + { + return array(); + + $key = serialize(array($userid, $params['perm'], $params['attributes'])); + if ($this->_storage === false) { + $this->_listcache[$key] = array(); + } else if (empty($this->_listcache[$key]) + || $this->_list->validity != $this->_listCacheValidity) { + $sharelist = $this->_storage->getByType($this->_type); + if ($sharelist instanceof PEAR_Error) { + throw new Horde_Share_Exception($sharelist->getMessage()); + } + + $shares = array(); + foreach ($sharelist as $folder) { + $id = $folder->getShareId(); + $share = $this->getShare($id); + $keep = true; + if (!$share->hasPermission($userid, $params['perm'])) { + $keep = false; + } + if (isset($params['attributes']) && $keep) { + if (is_array($params['attributes'])) { + foreach ($params['attributes'] as $key => $value) { + if (!$share->get($key) == $value) { + $keep = false; + break; + } + } + } elseif (!$share->get('owner') == $params['attributes']) { + $keep = false; + } + } + if ($keep) { + $shares[] = $id; + } + } + $this->_listcache[$key] = $shares; + $this->_listCacheValidity = $this->_storage->validity; + } + + return $this->_listcache[$key]; + } + + + /** + * Lists *all* shares for the current app/share, regardless of + * permissions. + * + * For the Kolab backend this cannot work in the same way as for the SQL + * based backend. Permissions are always handled by the backend automatically (IMAP ACLs) and cannot be disabled. + * + * listAllShares() is apparently used during command line scipts where it + * represents administrator access. This is possible on Kolab by using the + * "manager" user. In that case a standard listShares() authenticated as + * "manager" should be sufficient. + * + * @return array All shares for the current app/share. + */ + protected function _listAllShares() + { + return array(); + } + + private function _getFolderType($app) { switch ($app) { @@ -156,70 +230,6 @@ class Horde_Share_Kolab extends Horde_Share_Base } /** - * Lists *all* shares for the current app/share, regardless of - * permissions. - * - * Currently not implemented in this class. - * - * @return array All shares for the current app/share. - */ - protected function _listAllShares() - { - return array(); - } - - /** - * Returns an array of all shares that $userid has access to. - * - * @param string $userid The userid of the user to check access for. - * @param array $params See listShares(). - * - * @return array The shares the user has access to. - */ - protected function _listShares($userid, array $params = array()) - { - $key = serialize(array($this->_type, $userid, $params['perm'], $params['attributes'])); - if ($this->_storage === false) { - $this->_listCache[$key] = array(); - } else if (empty($this->_listCache[$key]) - || $this->_list->validity != $this->_listCacheValidity) { - $sharelist = $this->_storage->getByType($this->_type); - if ($sharelist instanceof PEAR_Error) { - throw new Horde_Share_Exception($sharelist->getMessage()); - } - - $shares = array(); - foreach ($sharelist as $folder) { - $id = $folder->getShareId(); - $share = $this->getShare($id); - $keep = true; - if (!$share->hasPermission($userid, $params['perm'])) { - $keep = false; - } - if (isset($params['attributes']) && $keep) { - if (is_array($params['attributes'])) { - foreach ($params['attributes'] as $key => $value) { - if (!$share->get($key) == $value) { - $keep = false; - break; - } - } - } elseif (!$share->get('owner') == $params['attributes']) { - $keep = false; - } - } - if ($keep) { - $shares[] = $id; - } - } - $this->_listCache[$key] = $shares; - $this->_listCacheValidity = $this->_storage->validity; - } - - return $this->_listCache[$key]; - } - - /** * Returns a new share object. * * @param string $name The share's name. diff --git a/framework/Share/test/Horde/Share/Kolab/MockTest.php b/framework/Share/test/Horde/Share/Kolab/MockTest.php index 80da0ce04..9bc03b2fc 100644 --- a/framework/Share/test/Horde/Share/Kolab/MockTest.php +++ b/framework/Share/test/Horde/Share/Kolab/MockTest.php @@ -40,5 +40,12 @@ class Horde_Share_Kolab_MockTest extends Horde_Share_Test_Base self::$share = new Horde_Share_Kolab('test', 'john', new Horde_Perms(), $group); } + public function setUp() + { + if (!class_exists('Horde_Kolab_Storage')) { + $this->markTestSkipped('The Kolab_Storage package seems to be unavailable.'); + } + } + } \ No newline at end of file diff --git a/framework/Share/test/Horde/Share/Kolab/UnitTest.php b/framework/Share/test/Horde/Share/Kolab/UnitTest.php index fac68eb3c..b75bedbe6 100644 --- a/framework/Share/test/Horde/Share/Kolab/UnitTest.php +++ b/framework/Share/test/Horde/Share/Kolab/UnitTest.php @@ -35,6 +35,12 @@ require_once dirname(__FILE__) . '/../Autoload.php'; class Horde_Share_Kolab_UnitTest extends PHPUnit_Framework_TestCase { + public function setUp() + { + if (!interface_exists('Horde_Kolab_Storage')) { + $this->markTestSkipped('The Kolab_Storage package seems to be unavailable.'); + } + } public function testGetStorage() { @@ -53,6 +59,32 @@ extends PHPUnit_Framework_TestCase $driver->getStorage(); } + public function testListArray() + { + $this->assertType( + 'array', + $this->_getCompleteDriver()->listShares('john') + ); + } + + private function _getCompleteDriver() + { + $factory = new Horde_Kolab_Storage_Factory(); + $driver = $this->_getDriver(); + $driver->setStorage( + $factory->createFromParams( + array( + 'driver' => 'mock', + 'data' => array('user/john' => array()), + 'cache' => new Horde_Cache( + new Horde_Cache_Storage_Mock() + ), + ) + ) + ); + return $driver; + } + private function _getDriver() { return new Horde_Share_Kolab(