if ($this->_namespace === null) {
if (isset($this->_params['namespaces'])) {
$this->_namespace = $this->_factory->createNamespace(
- 'config', $this->_params['namespaces']
+ 'config', $this->getAuth(), $this->_params['namespaces']
);
} else {
- $this->_namespace = $this->_factory->createNamespace('fixed');
+ $this->_namespace = $this->_factory->createNamespace(
+ 'fixed', $this->getAuth()
+ );
}
}
return $this->_namespace;
}
$c[] = $namespace;
}
- $this->_namespace = $this->getFactory()->createNamespace('imap', $c);
+ $this->_namespace = $this->getFactory()->createNamespace('imap', $this->getAuth(), $c);
}
return parent::getNamespace();
}
}
}
return new Horde_Kolab_Storage_Folder_Namespace_Imap(
+ $this->getAuth(),
$namespaces,
$this->getParam('namespaces', array())
);
$namespace['type'] = 'shared';
break;
}
- $namespace['delimiter'] = $namespace['delimter'];
+ $namespace['delimiter'] = $namespace['delimiter'];
$namespaces[] = $namespace;
}
}
return new Horde_Kolab_Storage_Driver_Namespace_Imap(
$namespaces,
+ $this->getAuth(),
$this->getParam('namespaces', array())
);
}
* Create a namespace handler.
*
* @param string $type The namespace type.
+ * @param string $user The current user.
* @param array $params The parameters for the namespace. See
*
* @return Horde_Kolab_Storage_Folder_Namespace The namespace handler.
*/
- public function createNamespace($type, array $params = array())
+ public function createNamespace($type, $user, array $params = array())
{
$class = 'Horde_Kolab_Storage_Folder_Namespace_' . ucfirst($type);
if (!class_exists($class)) {
)
);
}
- return new $class($params);
+ return new $class($user, $params);
}
/**
{
/**
* Constructor.
+ *
+ * @param string $user The current user.
+ * @param array $configuration The namespace configuration.
*/
- public function __construct(array $configuration)
+ public function __construct($user, array $configuration)
{
$namespace = array();
foreach ($configuration as $element) {
if ($element['type'] == Horde_Kolab_Storage_Folder_Namespace::SHARED
&& isset($element['prefix'])) {
$namespace_element = new Horde_Kolab_Storage_Folder_Namespace_Element_SharedWithPrefix(
- $element['name'], $element['delimiter'], $element['prefix']
+ $element['name'], $element['delimiter'], $user, $element['prefix']
);
} else {
$class = 'Horde_Kolab_Storage_Folder_Namespace_Element_' . ucfirst($element['type']);
- $namespace_element = new $class($element['name'], $element['delimiter']);
+ $namespace_element = new $class($element['name'], $element['delimiter'], $user);
}
$namespaces[] = $namespace_element;
}
protected $_delimiter;
/**
+ * The current user.
+ *
+ * @var string
+ */
+ protected $_user;
+
+ /**
* Constructor.
*
* @param string $name The prefix identifying this namespace.
* @param string $delimiter The delimiter used for this namespace.
+ * @param string $user The current user.
*/
- public function __construct($name, $delimiter)
+ public function __construct($name, $delimiter, $user)
{
if (substr($name, -1) == $delimiter) {
$name = substr($name, 0, -1);
}
$this->_name = $name;
$this->_delimiter = $delimiter;
+ $this->_user = $user;
}
/**
$domain = strstr(array_pop($path), '@');
if (!empty($domain)) {
$user .= $domain;
+ } else {
+ $domain = strstr($this->_user, '@');
+ if (!empty($domain)) {
+ $user .= $domain;
+ }
}
}
- return Horde_Kolab_Storage_Folder_Namespace::OTHER . ':' . $user;
+ return $user;
}
/**
*/
public function getOwner($name)
{
- return Horde_Kolab_Storage_Folder_Namespace::PERSONAL;
+ return $this->_user;
}
}
\ No newline at end of file
*/
public function getOwner($name)
{
- return Horde_Kolab_Storage_Folder_Namespace::SHARED;
+ return 'anonymous';
}
}
\ No newline at end of file
*
* @param string $name The prefix identifying this namespace.
* @param string $delimiter The delimiter used for this namespace.
- * @param string $prefix The prefix to hide.
+ * @param string $user The current user.
+ * @param string $prefix The prefix to hide.
*/
- public function __construct($name, $delimiter, $prefix)
+ public function __construct($name, $delimiter, $user, $prefix)
{
- parent::__construct($name, $delimiter);
+ parent::__construct($name, $delimiter, $user);
$this->_prefix = $prefix;
}
/**
* Constructor.
*/
- public function __construct()
+ public function __construct($user)
{
parent::__construct(
array(
- new Horde_Kolab_Storage_Folder_Namespace_Element_Personal('INBOX/', '/'),
- new Horde_Kolab_Storage_Folder_Namespace_Element_Other('user/', '/'),
- new Horde_Kolab_Storage_Folder_Namespace_Element_SharedWithPrefix('', '/', 'shared.')
+ new Horde_Kolab_Storage_Folder_Namespace_Element_Personal('INBOX/', '/', $user),
+ new Horde_Kolab_Storage_Folder_Namespace_Element_Other('user/', '/', $user),
+ new Horde_Kolab_Storage_Folder_Namespace_Element_SharedWithPrefix('', '/', $user, 'shared.')
)
);
}
public function listByType($type);
/**
+ * Get the folder owners.
+ *
+ * @return array The folder owners with the folder names as key and the
+ * owner as values.
+ */
+// public function listOwners();
+
+ /**
* Get the default folder for a certain type.
*
* @param string $type The type of the share/folder.
}
/**
+ * Get the folder owners.
+ *
+ * @return array The folder owners with the folder names as key and the
+ * owner as values.
+ */
+ public function listOwners()
+ {
+ $result = array();
+ $namespace = $this->_list->getNamespace();
+ foreach ($this->_list->listFolders() as $folder) {
+ $result[$folder] = $namespace->getOwner($folder);
+ }
+ return $result;
+ }
+
+ /**
* Synchronize the query data with the information from the backend.
*
* @return NULL
->will(
$this->returnValue(
new Horde_Kolab_Storage_Folder_Namespace_Imap(
+ 'test',
array(
array(
'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
->will(
$this->returnValue(
new Horde_Kolab_Storage_Folder_Namespace_Imap(
+ 'test',
array(
array(
'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
);
}
+ protected function getNamespaceAccount()
+ {
+ return array(
+ 'username' => 'test@example.com',
+ 'data' => array(
+ 'user/test' => null,
+ 'user/test/a' => null,
+ 'user/test/Calendar' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ 'user/test/Contacts' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'contact.default',
+ )
+ ),
+ 'user/test/Notes' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'note.default',
+ )
+ ),
+ 'user/test/Tasks' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'task.default',
+ )
+ ),
+ 'user/example/Notes' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'note.default',
+ )
+ ),
+ 'user/example/Calendar' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ 'user/someone/Calendars/Events' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event.default',
+ )
+ ),
+ 'user/someone/Calendars/Party' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event',
+ )
+ ),
+ 'shared.Calendars/All' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event',
+ )
+ ),
+ 'shared.Calendars/Others' => array(
+ 'annotations' => array(
+ '/shared/vendor/kolab/folder-type' => 'event',
+ )
+ ),
+ )
+ );
+ }
+
+ protected function getNamespaceMock($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_Driver_Mock(
+ $factory,
+ $this->getNamespaceAccount()
+ );
+ }
+
+ protected function getNamespaceList($factory = null)
+ {
+ $factory = $this->completeFactory($factory);
+ return new Horde_Kolab_Storage_List_Base(
+ $this->getNamespaceMock($factory),
+ $factory
+ );
+ }
+
protected function getCachedQueryForList($bare_list, $factory)
{
$list_cache = $this->getMockListCache();
public function testGetNamespaceReturnsExpectedNamespaces()
{
$driver = new Horde_Kolab_Storage_Driver_Cclient(
- new Horde_Kolab_Storage_Factory(), array()
+ new Horde_Kolab_Storage_Factory(), array('username' => 'test')
);
$namespaces = array();
foreach ($driver->getNamespace() as $namespace) {
public function testGetNamespaceReturnsExpectedNamespaces()
{
$driver = new Horde_Kolab_Storage_Driver_Mock(
- new Horde_Kolab_Storage_Factory(), array()
+ new Horde_Kolab_Storage_Factory(), array('username' => 'test')
);
$namespaces = array();
foreach ($driver->getNamespace() as $namespace) {
{
$factory = new Horde_Kolab_Storage_Factory();
$factory->createNamespace(
- 'undefined'
+ 'undefined', 'test'
);
}
$this->assertInstanceOf(
'Horde_Kolab_Storage_Folder_Namespace_Fixed',
$factory->createNamespace(
- 'fixed'
+ 'fixed', 'test'
)
);
}
public function testTitleForNewFolders()
{
foreach ($this->_getNamespaces() as $namespace) {
- $this->_connection->expects($this->any())
- ->method('getAuth')
- ->will($this->returnValue('test'));
$folder = $this->_getFolder(null, $namespace);
$folder->setTitle('test');
$this->assertEquals('test', $folder->getTitle());
public function testOwnerForPersonalNS()
{
foreach ($this->_getNamespaces() as $namespace) {
- $this->_connection->expects($this->any())
- ->method('getAuth')
- ->will($this->returnValue('test'));
$folder = $this->_getFolder('INBOX', $namespace);
$this->assertEquals('test', $folder->getOwner());
}
public function testOwnerInPersonalNS()
{
foreach ($this->_getNamespaces() as $namespace) {
- $this->_connection->expects($this->any())
- ->method('getAuth')
- ->will($this->returnValue('test'));
$folder = $this->_getFolder('INBOX/mine', $namespace);
$this->assertEquals('test', $folder->getOwner());
}
public function testOwnerForNewFolders()
{
foreach ($this->_getNamespaces() as $namespace) {
- $this->_connection->expects($this->any())
- ->method('getAuth')
- ->will($this->returnValue('test'));
$folder = $this->_getFolder(null, $namespace);
$folder->setTitle('test');
$this->assertEquals('test', $folder->getOwner());
public function testOwnerDomain()
{
- foreach ($this->_getNamespaces() as $namespace) {
- $this->_connection->expects($this->any())
- ->method('getAuth')
- ->will($this->returnValue('test@example.com'));
+ foreach ($this->_getNamespaces('test@example.com') as $namespace) {
$folder = $this->_getFolder('user/test/mine', $namespace);
$this->assertEquals('test@example.com', $folder->getOwner());
}
return $folder;
}
- private function _getNamespaces()
+ private function _getNamespaces($user = 'test')
{
return array(
- new Horde_Kolab_Storage_Folder_Namespace_Fixed(),
+ new Horde_Kolab_Storage_Folder_Namespace_Fixed($user),
new Horde_Kolab_Storage_Folder_Namespace_Config(
+ $user,
array(
array(
'type' => Horde_Kolab_Storage_Folder_Namespace::PERSONAL,
)
),
new Horde_Kolab_Storage_Folder_Namespace_Imap(
+ $user,
array(
array(
'name' => 'INBOX/',
$this->assertInstanceOf('Horde_Kolab_Storage_Folder_Type', $type);
};
}
+
+ public function testListOwnersReturn()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+ $this->assertType(
+ 'array',
+ $query->listOwners()
+ );
+ }
+
+ public function testListOwnerList()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getAnnotatedList($factory));
+ $this->assertEquals(
+ array(
+ 'INBOX' => 'test@example.com',
+ 'INBOX/Calendar' => 'test@example.com',
+ 'INBOX/Contacts' => 'test@example.com',
+ 'INBOX/Notes' => 'test@example.com',
+ 'INBOX/Tasks' => 'test@example.com',
+ 'INBOX/a' => 'test@example.com',
+ ),
+ $query->listOwners()
+ );
+ }
+
+ public function testListOwnerNamespace()
+ {
+ $factory = new Horde_Kolab_Storage_Factory();
+ $query = $factory->createListQuery('Base', $this->getNamespaceList($factory));
+ $this->assertEquals(
+ array(
+ 'INBOX' => 'test@example.com',
+ 'INBOX/Calendar' => 'test@example.com',
+ 'INBOX/Contacts' => 'test@example.com',
+ 'INBOX/Notes' => 'test@example.com',
+ 'INBOX/Tasks' => 'test@example.com',
+ 'INBOX/a' => 'test@example.com',
+ 'shared.Calendars/All' => 'anonymous',
+ 'shared.Calendars/Others' => 'anonymous',
+ 'user/example/Calendar' => 'example@example.com',
+ 'user/example/Notes' => 'example@example.com',
+ 'user/someone/Calendars/Events' => 'someone@example.com',
+ 'user/someone/Calendars/Party' => 'someone@example.com',
+ ),
+ $query->listOwners()
+ );
+ }
}