0012204: allow account loginname instead of contact displayname
authorsstamer <s.stamer@metaways.de>
Wed, 31 Aug 2016 16:23:34 +0000 (18:23 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 15 Sep 2016 07:51:36 +0000 (09:51 +0200)
... and add config option for switching behavior:
'useLoginnameAsFoldername'

https://forge.tine20.org/view.php?id=12204

Change-Id: I87bd3622eb1f0e3a00b164d2150d82da530d7e63
Reviewed-on: http://gerrit.tine20.com/customers/3500
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Filemanager/Frontend/WebDAVTest.php
tests/tine20/Tinebase/ConfigTest.php
tests/tine20/Tinebase/WebDav/Plugin/OwnCloudTest.php
tests/tine20/Tinebase/WebDav/RootTest.php
tine20/Tinebase/Config.php
tine20/Tinebase/WebDav/Collection/AbstractContainerTree.php

index 27fb478..e67e93c 100644 (file)
@@ -21,7 +21,16 @@ class Filemanager_Frontend_WebDAVTest extends TestCase
      * @var Sabre\DAV\ObjectTree
      */
     protected $_webdavTree;
-    
+
+    /**
+     * tear down tests
+     */
+    protected function tearDown()
+    {
+        parent::tearDown();
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, false);
+    }
+
     /**
      * testgetNodeForPath
      */
@@ -237,6 +246,24 @@ class Filemanager_Frontend_WebDAVTest extends TestCase
         $savedMTime = new Tinebase_DateTime($node->getLastModified());
         $this->assertEquals($mtime, $savedMTime, 'X_OC_MTIME not saved');
     }
+    
+    public function testgetNodeForPath_webdav_filemanager_currentuser2()
+    {
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, true);
+        $node = $this->_getWebDAVTree()->getNodeForPath('/webdav/Filemanager/' . Tinebase_Core::getUser()->accountLoginName);
+    
+        $this->assertInstanceOf('Filemanager_Frontend_WebDAV', $node, 'wrong node class');
+        $this->assertEquals(Tinebase_Core::getUser()->accountLoginName, $node->getName());
+    
+        $children = $node->getChildren();
+    
+        $this->assertGreaterThanOrEqual(1, count($children));
+        $this->assertInstanceOf('Filemanager_Frontend_WebDAV_Container', $children[0], 'wrong node class');
+    
+        $this->setExpectedException('Sabre\DAV\Exception\Forbidden');
+    
+        $this->_getWebDAVTree()->delete('/webdav/Filemanager/' . Tinebase_Core::getUser()->accountLoginName);
+    }
 
     /**
      * test chunked upload from OwnCloud clients
index 425f5d5..4d62347 100644 (file)
@@ -20,6 +20,7 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
 {
     /**
      * unit under test (UIT)
+     *
      * @var Tinebase_Config
      */
     protected $_instance;
@@ -30,7 +31,7 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
     protected $objects = array();
 
     protected $_filenamesToDelete = array();
-    
+
     /**
      * Sets up the fixture.
      * This method is called before a test is executed.
@@ -56,16 +57,16 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
 
         Tinebase_Config::getInstance()->clearCache();
     }
-    
+
     /**
      * test instance retrival
-     * 
+     *
      */
     public function testConfigInstance()
     {
         $this->assertTrue($this->_instance === Tinebase_Core::getConfig(), 'Tinebase_Core::getConfig() is wrong instance');
     }
-    
+
     /**
      * test basic config getting/setting/deleting cycle
      */
@@ -73,14 +74,14 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
     {
         $this->_instance->set(Tinebase_Config::PAGETITLEPOSTFIX, 'phpunit');
         $this->assertEquals('phpunit', $this->_instance->{Tinebase_Config::PAGETITLEPOSTFIX}, 'could not set config');
-        
+
         $this->_instance->delete(Tinebase_Config::PAGETITLEPOSTFIX, 'phpunit');
-        
+
         $this->assertEquals('###PHPUNIT-NOTSET###', $this->_instance->get(Tinebase_Config::PAGETITLEPOSTFIX, '###PHPUNIT-NOTSET###'), 'config got not deleted');
-        
+
         $this->assertFalse(isset($this->_instance->{Tinebase_Config::PAGETITLEPOSTFIX}), '__isset not working');
     }
-    
+
     /**
      * test if config from config.inc.php overwrites config in db
      *
@@ -88,20 +89,20 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
     public function testConfigFromFileOverwrites()
     {
         $configData = include('config.inc.php');
-        
-        if (! (isset($configData['Overwrite Test']) || array_key_exists('Overwrite Test', $configData))) {
+
+        if (!(isset($configData['Overwrite Test']) || array_key_exists('Overwrite Test', $configData))) {
             $this->markTestSkipped('config.inc.php has no test key "Overwrite Test"');
             return;
         }
-        
+
         $overwrittenValue = Tinebase_Record_Abstract::generateUID();
         $this->_instance->{'Overwrite Test'} = $overwrittenValue;
-        
+
         $this->assertEquals($configData['Overwrite Test'], $this->_instance->{'Overwrite Test'});
-        
+
         $this->_instance->delete('Overwrite Test');
     }
-    
+
     /**
      * test get config from config.inc.php
      *
@@ -109,11 +110,11 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
     public function testGetConfigFromFile()
     {
         $dbConfig = $this->_instance->database;
-        
+
         $this->assertGreaterThan(0, count($dbConfig), 'could not get db config');
         $this->assertTrue($dbConfig['dbname'] != '', 'could not get dbname');
     }
-    
+
     /**
      * test config value is a struct
      *
@@ -121,15 +122,15 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
     public function testConfigTypeStruct()
     {
         $dbConfig = $this->_instance->database;
-        
+
         $this->assertTrue($dbConfig instanceof Tinebase_Config_Struct, 'db config is not a struct');
         $this->assertTrue($dbConfig['dbname'] != '', 'could not get dbname via arrayAccess');
         $this->assertTrue($dbConfig->dbname != '', 'could not get dbname via objectAccess');
     }
-    
+
     /**
      * test client config retrival
-     * 
+     *
      */
     public function testGetClientRegistryConfig()
     {
@@ -137,10 +138,10 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($clientConfig instanceof Tinebase_Config_Struct, 'clientconfig is not a struct');
         $this->assertTrue($clientConfig->Calendar instanceof Tinebase_Config_Struct, 'calendar clientconfig is not a struct');
         $this->assertEquals(Calendar_Config::getInstance()->fixedCalendars, $clientConfig->Calendar->fixedCalendars->value, 'fixed calendar config not correct');
-        
+
         $this->assertFalse((isset($clientConfig->Tinebase['SMTP']) || array_key_exists('SMTP', $clientConfig->Tinebase)), 'SMTP is not a client config');
     }
-    
+
     /**
      * test if config returns empty array if it's empty
      */
@@ -148,52 +149,52 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
     {
         // Hold original value for further tests of sieve.
         $keepOriginalValue = $this->_instance->get("sieve");
-        
+
         // Ensure  sieve key is null
         $this->_instance->set("sieve", null);
-        
+
         // If key is null it throws an exception, so return empty array if it's null.
         $this->assertTrue($this->_instance->get("sieve") instanceof Tinebase_Config_Struct);
-        
+
         // Check common function of the getFunction
         $this->assertTrue(is_numeric($this->_instance->get("acceptedTermsVersion")));
-        
+
         // restore value
         $this->_instance->set("sieve", $keepOriginalValue);
     }
-    
+
     /**
      * testApplicationDefaultConfig
      */
     public function testApplicationDefaultConfig()
     {
         $defaultConfigFile = $this->_getSalesCustomDefaultConfig();
-        
+
         if (file_exists($defaultConfigFile)) {
             $this->markTestSkipped('ignore test because Sales default config exists');
         }
-        
+
         $ignoreBillablesConfig = Sales_Config::getInstance()->get(Sales_Config::IGNORE_BILLABLES_BEFORE);
         $this->assertEquals('2000-01-01 22:00:00', $ignoreBillablesConfig);
-        
+
         copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . 'configtest.inc.php', $defaultConfigFile);
         $this->_filenamesToDelete[] = $defaultConfigFile;
 
         Sales_Config::getInstance()->clearCache();
-        
+
         $ignoreBillablesConfigAppDefault = Sales_Config::getInstance()->get(Sales_Config::IGNORE_BILLABLES_BEFORE);
         $this->assertEquals('1999-10-01 22:00:00', $ignoreBillablesConfigAppDefault);
     }
-    
+
     protected function _getSalesCustomDefaultConfig()
     {
         return dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'tine20'
-            . DIRECTORY_SEPARATOR . 'Sales' . DIRECTORY_SEPARATOR . 'config.inc.php';
+        . DIRECTORY_SEPARATOR . 'Sales' . DIRECTORY_SEPARATOR . 'config.inc.php';
     }
-    
+
     /**
      * testFeatureEnabled
-     * 
+     *
      * @see 0010756: add feature switches for easy enabling/disabling of features
      */
     public function testFeatureEnabled()
@@ -202,9 +203,9 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
         if (file_exists($customConfigFilename)) {
             $this->markTestSkipped('do not test with existing custom config');
         }
-        
+
         $invoicesFeatureEnabled = Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE);
-        
+
         $this->assertTrue($invoicesFeatureEnabled);
     }
 
@@ -216,7 +217,7 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
     public function testComposeConfigDir()
     {
         $confdfolder = Tinebase_Config::getInstance()->get(Tinebase_Config::CONFD_FOLDER);
-        if (empty($confdfolder) || ! is_readable($confdfolder)) {
+        if (empty($confdfolder) || !is_readable($confdfolder)) {
             $this->markTestSkipped('no confdfolder configured/readable');
         }
 
@@ -239,4 +240,14 @@ class Tinebase_ConfigTest extends PHPUnit_Framework_TestCase
         $defaultPolicy = ActiveSync_Config::getInstance()->get(ActiveSync_Config::DEFAULT_POLICY, null);
         $this->assertTrue(is_null($defaultPolicy), 'config should be null: ' . var_export($defaultPolicy, true));
     }
+
+    /**
+     * set + get bool config
+     */
+    public function testBoolConfig()
+    {
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, true);
+
+        $this->assertEquals(true, Tinebase_Config::getInstance()->get(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME));
+    }
 }
index c992c9f..6448d72 100644 (file)
@@ -43,6 +43,15 @@ class Tinebase_WebDav_Plugin_OwnCloudTest extends Tinebase_WebDav_Plugin_Abstrac
     }
 
     /**
+     * tear down tests
+     */
+    protected function tearDown()
+    {
+        parent::tearDown();
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, false);
+    }
+
+    /**
      * test getPluginName method
      */
     public function testGetPluginName()
@@ -90,4 +99,45 @@ class Tinebase_WebDav_Plugin_OwnCloudTest extends Tinebase_WebDav_Plugin_Abstrac
         $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
         $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
     }
+    
+    /**
+     * test testGetProperties method with alternate loginname config
+     */
+    public function testGetProperties2()
+    {
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, true);
+        
+        $body = '<?xml version="1.0" encoding="utf-8"?>
+                 <propfind xmlns="DAV:">
+                    <prop>
+                        <getlastmodified xmlns="DAV:"/>
+                        <getcontentlength xmlns="DAV:"/>
+                        <resourcetype xmlns="DAV:"/>
+                        <getetag xmlns="DAV:"/>
+                        <id xmlns="http://owncloud.org/ns"/>
+                    </prop>
+                 </propfind>';
+    
+        $request = new Sabre\HTTP\Request(array(
+                'REQUEST_METHOD' => 'PROPFIND',
+                'REQUEST_URI'    => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountLoginName,
+                'HTTP_DEPTH'     => '0',
+        ));
+        $request->setBody($body);
+    
+        $this->server->httpRequest = $request;
+        $this->server->exec();
+        //var_dump($this->response->body);
+        $this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
+    
+        $responseDoc = new DOMDocument();
+        $responseDoc->loadXML($this->response->body);
+        //$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
+        $xpath = new DomXPath($responseDoc);
+        $xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
+    
+        $nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
+        $this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
+        $this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
+    }
 }
index af1b5e2..02a0380 100644 (file)
@@ -28,17 +28,14 @@ class Tinebase_WebDav_RootTest extends TestCase
      * @var array test objects
      */
     protected $objects = array();
-    
+
     /**
-     * Runs the test methods of this class.
-     *
-     * @access public
-     * @static
+     * tear down tests
      */
-    public static function main()
+    protected function tearDown()
     {
-        $suite  = new PHPUnit_Framework_TestSuite('Tinebase_WebDav_RootTest');
-        PHPUnit_TextUI_TestRunner::run($suite);
+        parent::tearDown();
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, false);
     }
 
     /**
@@ -91,6 +88,54 @@ class Tinebase_WebDav_RootTest extends TestCase
     }
     
     /**
+     * test getLastModified method
+     */
+    public function testGetLastModified2()
+    {
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, true);
+        
+        $remoteWebDav = $this->_getWebDAVTree()->getNodeForPath('/remote.php/webdav');
+        
+        $this->assertNotEmpty($remoteWebDav->getLastModified());
+        
+        $personal = $remoteWebDav->getChild(Tinebase_Core::getUser()->accountLoginName);
+        
+        $this->assertNotEmpty($personal->getLastModified());
+        
+        $shared = $remoteWebDav->getChild('shared');
+        
+        $this->assertNotEmpty($shared->getLastModified());
+        
+        $this->assertContains($remoteWebDav->getLastModified(), array($personal->getLastModified(), $shared->getLastModified()));
+        
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, false);
+        
+    }
+    
+    /**
+     * test getETag
+     */
+    public function testGetETag2()
+    {
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, true);
+        
+        $remoteWebDav = $this->_getWebDAVTree()->getNodeForPath('/remote.php/webdav');
+        $properties = $remoteWebDav->getProperties(array('{DAV:}getetag'));
+        $this->assertArrayHasKey('{DAV:}getetag', $properties);
+    
+        $currentUser = $remoteWebDav->getChild(Tinebase_Core::getUser()->accountLoginName);
+        $properties = $currentUser->getProperties(array('{DAV:}getetag'));
+        $this->assertArrayHasKey('{DAV:}getetag', $properties);
+    
+        foreach ($currentUser->getChildren() as $child) {
+            $properties = $child->getProperties(array('{DAV:}getetag'));
+            $this->assertArrayHasKey('{DAV:}getetag', $properties);
+        }
+        
+        Tinebase_Config::getInstance()->set(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME, false);
+    }
+    
+    /**
      * 
      * @return \Sabre\DAV\ObjectTree
      */
index 3271fb9..27f70c8 100644 (file)
@@ -360,6 +360,11 @@ class Tinebase_Config extends Tinebase_Config_Abstract
      * @var array of strings
      */
     const FAT_CLIENT_CUSTOM_JS = 'fatClientCustomJS';
+    
+    /**
+     * @var boolean
+     */
+    const USE_LOGINNAME_AS_FOLDERNAME = 'useLoginnameAsFoldername';
 
     /**
      * @var array of strings
@@ -872,6 +877,17 @@ class Tinebase_Config extends Tinebase_Config_Abstract
             'setByAdminModule'      => FALSE,
             'setBySetupModule'      => FALSE,
         ),
+        self::USE_LOGINNAME_AS_FOLDERNAME => array(
+        //_('Use login name instead of full name')
+            'label'                 => 'Use login name instead of full name',
+        //_('Use login name instead of full name for webdav.')
+            'description'           => 'Use login name instead of full name for webdav.',
+            'type'                  => 'bool',
+            'clientRegistryInclude' => FALSE,
+            'setByAdminModule'      => FALSE,
+            'setBySetupModule'      => FALSE,
+            'default'               => FALSE,
+        )
     );
     
     /**
index f2496a1..058d812 100644 (file)
@@ -64,7 +64,7 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
     protected $_useIdAsName;
     
     protected static $_classCache = array (
-        '_getContact' => array()
+        '_getUser' => array()
     );
     
     /**
@@ -78,6 +78,16 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
         $this->_path        = $path;
         $this->_useIdAsName = $useIdAsName;
     }
+
+    /**
+     * use login as folder name
+     *
+     * @return boolean
+     */
+    protected function _useLoginAsFolderName()
+    {
+        return Tinebase_Config::getInstance()->get(Tinebase_Config::USE_LOGINNAME_AS_FOLDERNAME);
+    }
     
     /**
      * (non-PHPdoc)
@@ -94,7 +104,7 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
      * (non-PHPdoc)
      * @see \Sabre\DAV\IExtendedCollection::createExtendedCollection()
      */
-    function createExtendedCollection($name, array $resourceType, array $properties)
+    public function createExtendedCollection($name, array $resourceType, array $properties)
     {
         return $this->_createContainer(array(
             'name'  => isset($properties['{DAV:}displayname']) ? $properties['{DAV:}displayname'] : $name,
@@ -126,13 +136,17 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                         
                     } else {
                         try {
-                            $contact = $this->_getContact($name);
+                            // check if it exists only
+                            $this->_getUser($name);
                             
                         } catch (Tinebase_Exception_NotFound $tenf) {
-                            throw new \Sabre\DAV\Exception\NotFound("Directory $this->_path/$name not found");
+                            $message = "Directory $this->_path/$name not found";
+                            if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(
+                                __METHOD__ . '::' . __LINE__ . ' ' . $message);
+                            throw new \Sabre\DAV\Exception\NotFound($message);
                         }
                         
-                        $path = $this->_path . '/' . ($this->_useIdAsName ? $contact->getId() : $contact->n_fileas);
+                        $path = $this->_path . '/' . $name;
                     }
                     
                 } else {
@@ -185,7 +199,7 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                         
                     } else {
                         try {
-                            $accountId = $this->_getContact(Tinebase_Helper::array_value(1, $this->_getPathParts()))->account_id;
+                            $accountId = $this->_getUser(Tinebase_Helper::array_value(1, $this->_getPathParts()))->accountId;
                             
                         } catch (Tinebase_Exception_NotFound $tenf) {
                             throw new \Sabre\DAV\Exception\NotFound("Directory $this->_path/$name not found");
@@ -266,8 +280,7 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                 
                 if ($this->_hasPersonalFolders) {
                     $children[] = $this->getChild(
-                        $this->_useIdAsName ? Tinebase_Core::getUser()->contact_id :
-                        Addressbook_Controller_Contact::getInstance()->get(Tinebase_Core::getUser()->contact_id)->n_fileas
+                        $this->_useIdAsName ? Tinebase_Core::getUser()->contact_id : $this->_useLoginAsFolderName() ? Tinebase_Core::getUser()->accountLoginName : Tinebase_Core::getUser()->accountDisplayName
                     );
                     
                     $otherUsers = Tinebase_Container::getInstance()->getOtherUsers(Tinebase_Core::getUser(), $this->_getApplicationName(), array(
@@ -278,8 +291,7 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                     foreach ($otherUsers as $user) {
                         if ($user->contact_id && $user->visibility === Tinebase_Model_User::VISIBILITY_DISPLAYED) {
                             try {
-                                $folderId = $this->_useIdAsName ? $user->contact_id :
-                                    Addressbook_Controller_Contact::getInstance()->get($user->contact_id)->n_fileas;
+                                $folderId = $this->_useIdAsName ? $user->contact_id : $this->_useLoginAsFolderName() ? $user->accountLoginName : $user->accountDisplayName;
 
                                 $children[] = $this->getChild($folderId);
                             } catch (\Sabre\DAV\Exception\NotFound $sdavenf) {
@@ -310,7 +322,7 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                         
                     } else {
                         try {
-                            $accountId = $this->_getContact(Tinebase_Helper::array_value(1, $this->_getPathParts()))->account_id;
+                            $accountId = $this->_getUser(Tinebase_Helper::array_value(1, $this->_getPathParts()))->accountId;
                         } catch (Tinebase_Exception_NotFound $tenf) {
                             throw new \Sabre\DAV\Exception\NotFound("Path $this->_path not found");
                         }
@@ -466,9 +478,9 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
             !$this->_useIdAsName
         ) {
             try {
-                $contact = $this->_getContact(Tinebase_Helper::array_value(1, $this->_getPathParts()));
+                $user = $this->_getUser(Tinebase_Helper::array_value(1, $this->_getPathParts()));
                 
-                $name = $contact->n_fileas;
+                $name = $this->_useLoginAsFolderName() ? $user->accountLoginName : $user->accountDisplayName;
                 
             } catch (Tinebase_Exception_NotFound $tenf) {
                 list(,$name) = Sabre\DAV\URLUtil::splitPath($this->_path);
@@ -492,12 +504,12 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
     {
         if (count($this->_getPathParts()) === 2 && $this->getName() !== Tinebase_Model_Container::TYPE_SHARED) {
             try {
-                $contact = $this->_getContact(Tinebase_Helper::array_value(1, $this->_getPathParts()));
+                $user = $this->_getUser(Tinebase_Helper::array_value(1, $this->_getPathParts()));
             } catch (Tinebase_Exception_NotFound $tenf) {
                 return null;
             }
             
-            return 'principals/users/' . $contact->getId();
+            return 'principals/users/' . $user->contact_id;
         }
         
         return null;
@@ -521,7 +533,8 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
                 case '{DAV:}displayname':
                     if (count($this->_getPathParts()) === 2 && $this->getName() !== Tinebase_Model_Container::TYPE_SHARED) {
                         try {
-                            $contact = $this->_getContact(Tinebase_Helper::array_value(1, $this->_getPathParts()));
+                            $user = $this->_getUser(Tinebase_Helper::array_value(1, $this->_getPathParts()));
+                            $contact = Addressbook_Controller_Contact::getInstance()->get($user->contact_id);
                         } catch (Tinebase_Exception_NotFound $tenf) {
                             continue;
                         }
@@ -726,41 +739,28 @@ abstract class Tinebase_WebDav_Collection_AbstractContainerTree extends \Sabre\D
         
         return $pathParts;
     }
-    
-    /**
-     * resolve contact_id to Addressbook_Model_Contact
-     * 
-     * @return Addressbook_Model_Contact
-     */
-    protected function _getContact($contactId)
+
+    protected function _getUser($_id)
     {
-        $classCacheId = ($this->_useIdAsName ? 'id' : 'n_fileas') . $contactId;
-        
+        $classCacheId = ($this->_useIdAsName ? 'contact_id' : $this->_useLoginAsFolderName() ? 'accountLoginName' : 'accountDisplayName') . $_id;
+
         if (isset(self::$_classCache[__FUNCTION__][$classCacheId])) {
             return self::$_classCache[__FUNCTION__][$classCacheId];
         }
-        
-        $filter = new Addressbook_Model_ContactFilter(array(
-            array(
-                'field'     => 'type',
-                'operator'  => 'equals',
-                'value'     => Addressbook_Model_Contact::CONTACTTYPE_USER
-            ),
-            array(
-                'field'     => $this->_useIdAsName ? 'id' : 'n_fileas',
-                'operator'  => 'equals',
-                'value'     => $contactId
-            ),
-        ));
-        
-        $contact = Addressbook_Controller_Contact::getInstance()->search($filter)->getFirstRecord();
-        
-        if (!$contact) {
-            throw new Tinebase_Exception_NotFound('contact not found');
+
+        if ($this->_useIdAsName) {
+            $contact = Addressbook_Controller_Contact::getInstance()->get($_id);
+            $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountId', $contact->account_id, 'Tinebase_Model_FullUser');
+        } else {
+            if ($this->_useLoginAsFolderName()) {
+                $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountLoginName', $_id, 'Tinebase_Model_FullUser');
+            } else {
+                $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountDisplayName', $_id, 'Tinebase_Model_FullUser');
+            }
         }
-        
-        self::$_classCache[__FUNCTION__][$classCacheId] = $contact;
-        
-        return $contact;
+
+        self::$_classCache[__FUNCTION__][$classCacheId] = $user;
+
+        return $user;
     }
 }