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) {
}
/**
- * 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.
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()
{
$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(