0013032: add GRANT_DOWNLOAD
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 8 May 2017 09:06:28 +0000 (11:06 +0200)
committerMichael Spahn <m.spahn@metaways.de>
Wed, 17 May 2017 07:54:10 +0000 (09:54 +0200)
* check in gui (action updater)
* check on server
* adds download to default grants
* use GetProtectedMethodTrait for testing
 to prevent problems with exit

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

Change-Id: Ia99a0dc42e7977976ac0af390d8e591e19c2885c
Reviewed-on: http://gerrit.tine20.com/customers/4629
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Michael Spahn <m.spahn@metaways.de>
Tested-by: Michael Spahn <m.spahn@metaways.de>
tests/tine20/Filemanager/Frontend/HttpTest.php [new file with mode: 0644]
tests/tine20/Filemanager/Frontend/JsonTests.php
tests/tine20/GetProtectedMethodTrait.php
tine20/Filemanager/Frontend/Http.php
tine20/Filemanager/js/nodeActions.js
tine20/Tinebase/FileSystem.php
tine20/Tinebase/Frontend/Http/Abstract.php
tine20/Tinebase/Frontend/WebDAV/File.php
tine20/Tinebase/Model/Grants.php

diff --git a/tests/tine20/Filemanager/Frontend/HttpTest.php b/tests/tine20/Filemanager/Frontend/HttpTest.php
new file mode 100644 (file)
index 0000000..8370801
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Tine 2.0 - http://www.tine20.org
+ * 
+ * @package     Filemanager
+ * @license     http://www.gnu.org/licenses/agpl.html
+ * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @author      Philipp Schüle <p.schuele@metaways.de>
+ */
+
+/**
+ * Test class for Filemanager_Frontend_Tree
+ * 
+ * @package     Filemanager
+ */
+class Filemanager_Frontend_HttpTest extends TestCase
+{
+    use GetProtectedMethodTrait;
+
+    public function testDownloadFile()
+    {
+        $jsonTests = new Filemanager_Frontend_JsonTests();
+        $file = $jsonTests->testCreateFileNodeWithTempfile();
+
+        $uit = $this->_getUit();
+        ob_start();
+        $reflectionMethod = $this->getProtectedMethod(Filemanager_Frontend_Http::class, '_downloadFileNodeByPathOrId');
+        $reflectionMethod->invokeArgs($uit, [$file['path'], null]);
+        $out = ob_get_clean();
+
+        self::assertEquals('test file content', $out);
+    }
+
+    public function testDownloadFileWithoutGrant()
+    {
+        $jsonTests = new Filemanager_Frontend_JsonTests();
+        $file = $jsonTests->testCreateFileNodeWithTempfile();
+
+        // remove download grant from folder node
+        $testPath = Tinebase_FileSystem::getInstance()->getApplicationBasePath('Filemanager', Tinebase_FileSystem::FOLDER_TYPE_SHARED)
+            . '/testcontainer';
+        $node = Tinebase_FileSystem::getInstance()->stat($testPath);
+        Tinebase_FileSystem::getInstance()->setGrantsForNode($node, Tinebase_Model_Grants::getDefaultGrants());
+
+        $uit = $this->_getUit();
+        try {
+            $reflectionMethod = $this->getProtectedMethod(Filemanager_Frontend_Http::class, '_downloadFileNodeByPathOrId');
+            $reflectionMethod->invokeArgs($uit, [$file['path'], null]);
+            self::fail('download should not be allowed');
+        } catch (Tinebase_Exception_AccessDenied $tead) {
+            self::assertEquals('download not allowed', $tead->getMessage());
+        }
+    }
+}
index a02da04..0691104 100644 (file)
@@ -26,7 +26,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
      *
      * @var Filemanager_Frontend_Json
      */
-    protected $_json;
+    protected $_json = null;
     
     /**
      * fs controller
@@ -79,8 +79,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     protected function setUp()
     {
         parent::setUp();
-        
-        $this->_json = new Filemanager_Frontend_Json();
+
         $this->_fsController = Tinebase_FileSystem::getInstance();
         $this->_application = Tinebase_Application::getInstance()->getApplicationByName('Filemanager');
         $this->_rmDir = array();
@@ -101,7 +100,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
 
         if (count($this->_rmDir) > 0) {
             foreach($this->_rmDir as $dir) {
-                $this->_json->deleteNodes($dir);
+                $this->_getUit()->deleteNodes($dir);
             }
         }
         
@@ -112,7 +111,18 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $this->_sharedContainer    = null;
         $this->_otherUserContainer = null;
     }
-    
+
+    /**
+     * @return Filemanager_Frontend_Json
+     */
+    protected function _getUit()
+    {
+        if ($this->_json === null) {
+            $this->_json = new Filemanager_Frontend_Json();
+        }
+        return $this->_json;
+    }
+
     /**
      * test search nodes (personal)
      */
@@ -123,7 +133,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => '/'
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         $this->_assertRootNodes($result);
     }
     
@@ -154,6 +164,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
                 Tinebase_Model_Grants::GRANT_ADMIN => true,
                 Tinebase_Model_Grants::GRANT_FREEBUSY => false,
                 Tinebase_Model_Grants::GRANT_PRIVATE => false,
+                Tinebase_Model_Grants::GRANT_DOWNLOAD => false,
             ),
             'tags'           => array(),
             ), $searchResult['results'][0], 'my user folder mismatch');
@@ -175,6 +186,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
                 Tinebase_Model_Grants::GRANT_ADMIN => false,
                 Tinebase_Model_Grants::GRANT_FREEBUSY => false,
                 Tinebase_Model_Grants::GRANT_PRIVATE => false,
+                Tinebase_Model_Grants::GRANT_DOWNLOAD => false,
             ),
             'tags' => array(),
         ), $searchResult['results'][1], 'shared folder mismatch');
@@ -196,6 +208,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
                 Tinebase_Model_Grants::GRANT_ADMIN => false,
                 Tinebase_Model_Grants::GRANT_FREEBUSY => false,
                 Tinebase_Model_Grants::GRANT_PRIVATE => false,
+                Tinebase_Model_Grants::GRANT_DOWNLOAD => false,
             ),
             'tags' => array(),
         ), $searchResult['results'][2], 'other user folder mismatch');
@@ -229,7 +242,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
      */
     protected function _searchHelper($_filter, $_expectedName, $_toplevel = FALSE, $_checkAccountGrants = TRUE)
     {
-        $result = $this->_json->searchNodes($_filter, array('sort' => 'size'));
+        $result = $this->_getUit()->searchNodes($_filter, array('sort' => 'size'));
         
         $this->assertGreaterThanOrEqual(1, $result['totalcount'], 'expected at least one entry');
         if ($_toplevel) {
@@ -390,16 +403,16 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'value'    => '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/xyz'
         ));
         
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         $this->_assertRootNodes($result);
         
         // wrong type
         $filter[0]['value'] = '/lala';
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         $this->_assertRootNodes($result);
 
         // no path filter
-        $result = $this->_json->searchNodes(array(), array());
+        $result = $this->_getUit()->searchNodes(array(), array());
         $this->_assertRootNodes($result);
     }
     
@@ -411,7 +424,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     public function testCreateContainerNodeInPersonalFolder($containerName = 'testcontainer')
     {
         $testPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/' . $containerName;
-        $result = $this->_json->createNodes($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
+        $result = $this->_getUit()->createNodes($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
         $createdNode = $result[0];
         
         $this->assertTrue(isset($createdNode['name']));
@@ -431,7 +444,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $testPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testcon/tainer';
         
         $this->setExpectedException('Tinebase_Exception_NotFound');
-        $result = $this->_json->createNodes($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
+        $result = $this->_getUit()->createNodes($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
     }
 
     /**
@@ -443,7 +456,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     public function testCreateContainerNodeInSharedFolder($_name = 'testcontainer')
     {
         $testPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_SHARED . '/' . $_name;
-        $result = $this->_json->createNode($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, NULL, FALSE);
+        $result = $this->_getUit()->createNode($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, NULL, FALSE);
         $createdNode = $result;
         
         $this->assertEquals($_name, $createdNode['name']);
@@ -478,7 +491,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             }
         }
 
-        $result = $this->_json->createNodes($filepaths, Tinebase_Model_Tree_FileObject::TYPE_FILE, $tempFileIds, FALSE);
+        $result = $this->_getUit()->createNodes($filepaths, Tinebase_Model_Tree_FileObject::TYPE_FILE, $tempFileIds, FALSE);
         
         $this->assertEquals(2, count($result));
         $this->assertEquals('file1', $result[0]['name']);
@@ -501,7 +514,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         static::assertEquals(16, $parentFolder->size, 'two files with 8 bytes each created, excpected 16 bytes folder size');
         static::assertEquals(0, $secondFolderNode['size'], 'expect new folder to be empty');
 
-        $this->_json->moveNodes($file0Path, $targetPath, false);
+        $this->_getUit()->moveNodes($file0Path, $targetPath, false);
 
         $parentFolder = $this->_fsController->stat(dirname($file0Path));
         static::assertEquals(8, $parentFolder->size, 'one file with 8 bytes expected');
@@ -523,7 +536,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $personalContainerNode = $this->testCreateContainerNodeInPersonalFolder();
         
         $testPaths = array($personalContainerNode['path'] . '/ütest.eml', $personalContainerNode['path'] . '/Безимени.txt');
-        $result = $this->_json->createNodes($testPaths, Tinebase_Model_Tree_FileObject::TYPE_FILE, array(), FALSE);
+        $result = $this->_getUit()->createNodes($testPaths, Tinebase_Model_Tree_FileObject::TYPE_FILE, array(), FALSE);
     
         $this->assertEquals(2, count($result));
         $this->assertEquals('ütest.eml', $result[0]['name']);
@@ -546,11 +559,11 @@ class Filemanager_Frontend_JsonTests extends TestCase
         
         $filepath = $sharedContainerNode['path'] . '/test.txt';
         // create empty file first (like the js frontend does)
-        $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, array(), FALSE);
+        $result = $this->_getUit()->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, array(), FALSE);
 
         $tempFileBackend = new Tinebase_TempFile();
         $tempFile = $tempFileBackend->createTempFile(dirname(dirname(__FILE__)) . '/files/test.txt');
-        $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, $tempFile->getId(), TRUE);
+        $result = $this->_getUit()->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, $tempFile->getId(), TRUE);
         
         $this->assertEquals('text/plain', $result['contenttype'], print_r($result, TRUE));
         $this->assertEquals(17, $result['size']);
@@ -591,7 +604,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             $sharedContainerNode['path'] . '/dir1',
             $sharedContainerNode['path'] . '/dir2',
         );
-        $result = $this->_json->createNodes($dirpaths, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
+        $result = $this->_getUit()->createNodes($dirpaths, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
         
         $this->assertEquals(2, count($result));
         $this->assertEquals('dir1', $result[0]['name']);
@@ -606,7 +619,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => Tinebase_Model_Tree_FileObject::TYPE_FOLDER,
         ));
-        $result = $this->_json->searchNodes($filter, array('sort' => 'creation_time'));
+        $result = $this->_getUit()->searchNodes($filter, array('sort' => 'creation_time'));
         $this->assertEquals(2, $result['totalcount']);
         
         return $dirpaths;
@@ -627,7 +640,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             $personalContainerNode['path'] . '/dir1',
             $personalContainerNode['path'] . '/dir2',
         );
-        $result = $this->_json->createNodes($dirpaths, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
+        $result = $this->_getUit()->createNodes($dirpaths, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
         
         $this->assertEquals(2, count($result));
         $this->assertEquals('dir1', $result[0]['name']);
@@ -642,7 +655,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => Tinebase_Model_Tree_FileObject::TYPE_FOLDER,
         ));
-        $result = $this->_json->searchNodes($filter, array('sort' => 'contenttype'));
+        $result = $this->_getUit()->searchNodes($filter, array('sort' => 'contenttype'));
         $this->assertEquals(2, $result['totalcount']);
         
         return $dirpaths;
@@ -674,9 +687,9 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $cf = $this->_createCustomfield('fmancf', 'Filemanager_Model_Node');
         $personalContainerNode = $this->testCreateContainerNodeInPersonalFolder();
 
-        $personalContainerNode = $this->_json->getNode($personalContainerNode['id']);
+        $personalContainerNode = $this->_getUit()->getNode($personalContainerNode['id']);
         $personalContainerNode['customfields'][$cf->name] = 'cf value';
-        $updatedNode = $this->_json->saveNode($personalContainerNode);
+        $updatedNode = $this->_getUit()->saveNode($personalContainerNode);
 
         $this->assertTrue(isset($updatedNode['customfields']) && isset($updatedNode['customfields'][$cf->name]), 'no customfields in record');
         $this->assertEquals($personalContainerNode['customfields'][$cf->name], $updatedNode['customfields'][$cf->name]);
@@ -699,7 +712,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         
         // rename
         $newPath = '/personal/sclever/testcontainer';
-        $result = $this->_json->moveNodes(array($personalContainerNodeOfsclever['path']), array($newPath), FALSE);
+        $result = $this->_getUit()->moveNodes(array($personalContainerNodeOfsclever['path']), array($newPath), FALSE);
         $this->assertEquals(1, count($result));
         $this->assertEquals($newPath, $result[0]['path']);
     }
@@ -712,7 +725,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $dirsToCopy = $this->testCreateDirectoryNodesInShared();
         $targetNode = $this->testCreateContainerNodeInPersonalFolder();
         
-        $result = $this->_json->copyNodes($dirsToCopy, $targetNode['path'], FALSE);
+        $result = $this->_getUit()->copyNodes($dirsToCopy, $targetNode['path'], FALSE);
         $this->assertEquals(2, count($result));
         $this->assertEquals($targetNode['path'] . '/dir1', $result[0]['path']);
     }
@@ -725,7 +738,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $sharedContainerNode = $this->testCreateContainerNodeInSharedFolder();
         $target = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName;
         $this->_objects['paths'][] = Filemanager_Controller_Node::getInstance()->addBasePath($target . '/testcontainer');
-        $result = $this->_json->copyNodes($sharedContainerNode['path'], $target, FALSE);
+        $result = $this->_getUit()->copyNodes($sharedContainerNode['path'], $target, FALSE);
         $this->assertEquals(1, count($result));
         $this->assertTrue(isset($result[0]['name']), print_r($result, true));
         $this->assertEquals('testcontainer', $result[0]['name']);
@@ -741,7 +754,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $filesToCopy = $this->testCreateFileNodes();
         $targetNode = $this->testCreateContainerNodeInPersonalFolder();
         
-        $result = $this->_json->copyNodes($filesToCopy, $targetNode['path'], FALSE);
+        $result = $this->_getUit()->copyNodes($filesToCopy, $targetNode['path'], FALSE);
         $this->assertEquals(2, count($result));
         $this->assertEquals($targetNode['path'] . '/file1', $result[0]['path']);
         
@@ -756,7 +769,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $filesToCopy = $this->testCreateFileNodes();
         $target = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName;
         
-        $result = $this->_json->copyNodes(
+        $result = $this->_getUit()->copyNodes(
             '/' . Tinebase_FileSystem::FOLDER_TYPE_SHARED . '/testcontainer',
             $target, 
             FALSE
@@ -774,7 +787,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => Tinebase_Model_Tree_FileObject::TYPE_FILE,
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         $this->assertEquals(2, $result['totalcount']);
     }
     
@@ -786,7 +799,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $fileToCopy = $this->testCreateFileNodeWithTempfile();
         $targetNode = $this->testCreateContainerNodeInPersonalFolder();
         
-        $result = $this->_json->copyNodes($fileToCopy['path'], $targetNode['path'], FALSE);
+        $result = $this->_getUit()->copyNodes($fileToCopy['path'], $targetNode['path'], FALSE);
         $this->assertEquals(1, count($result));
         $this->assertEquals($targetNode['path'] . '/test.txt', $result[0]['path']);
         $this->assertEquals('text/plain', $result[0]['contenttype']);
@@ -802,7 +815,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $file2 = $filesToCopy[1];
         
         $this->setExpectedException('Filemanager_Exception_NodeExists');
-        $result = $this->_json->copyNodes(array($file1), array($file2), FALSE);
+        $result = $this->_getUit()->copyNodes(array($file1), array($file2), FALSE);
     }
     
     /**
@@ -815,7 +828,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $file2 = $filesToCopy[1];
         
         try {
-            $result = $this->_json->copyNodes(array($file1), array($file2), FALSE);
+            $result = $this->_getUit()->copyNodes(array($file1), array($file2), FALSE);
         } catch (Filemanager_Exception_NodeExists $fene) {
             $info = $fene->toArray();
             $this->assertEquals(1, count($info['existingnodesinfo']));
@@ -833,7 +846,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $dirsToMove = $this->testCreateDirectoryNodesInShared();
         $targetNode = $this->testCreateContainerNodeInPersonalFolder();
         
-        $result = $this->_json->moveNodes($dirsToMove, $targetNode['path'], FALSE);
+        $result = $this->_getUit()->moveNodes($dirsToMove, $targetNode['path'], FALSE);
         $this->assertEquals(2, count($result));
         $this->assertEquals($targetNode['path'] . '/dir1', $result[0]['path'], 'no new path: ' . print_r($result, TRUE));
         
@@ -847,7 +860,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'value'    => Tinebase_Model_Tree_FileObject::TYPE_FOLDER,
         ));
 
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         $this->assertEquals(0, $result['totalcount']);
     }
     
@@ -861,13 +874,13 @@ class Filemanager_Frontend_JsonTests extends TestCase
         sleep(1);
         $targetNode = $this->testCreateContainerNodeInPersonalFolder();
         $testPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/dir1';
-        $result = $this->_json->moveNodes(array($targetNode['path']), array($testPath), FALSE);
+        $result = $this->_getUit()->moveNodes(array($targetNode['path']), array($testPath), FALSE);
         $dirs = $this->testCreateDirectoryNodesInShared();
         try {
-            $result = $this->_json->moveNodes(array($testPath), '/shared/testcontainer', FALSE);
+            $result = $this->_getUit()->moveNodes(array($testPath), '/shared/testcontainer', FALSE);
             $this->fail('Expected Filemanager_Exception_NodeExists!');
         } catch (Filemanager_Exception_NodeExists $fene) {
-            $result = $this->_json->moveNodes(array($testPath), '/shared/testcontainer', TRUE);
+            $result = $this->_getUit()->moveNodes(array($testPath), '/shared/testcontainer', TRUE);
             $this->assertEquals(1, count($result));
             $this->assertEquals('/shared/testcontainer/dir1', $result[0]['path']);
         }
@@ -883,14 +896,14 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $targetNode = $this->testCreateContainerNodeInPersonalFolder();
         
         $testPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testcontainer2';
-        $result = $this->_json->createNodes($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
+        $result = $this->_getUit()->createNodes($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
         $createdNode = $result[0];
 
         try {
-            $result = $this->_json->moveNodes(array($targetNode['path']), array($createdNode['path']), FALSE);
+            $result = $this->_getUit()->moveNodes(array($targetNode['path']), array($createdNode['path']), FALSE);
             $this->fail('Expected Filemanager_Exception_NodeExists!');
         } catch (Filemanager_Exception_NodeExists $fene) {
-            $result = $this->_json->moveNodes(array($targetNode['path']), array($createdNode['path']), TRUE);
+            $result = $this->_getUit()->moveNodes(array($targetNode['path']), array($createdNode['path']), TRUE);
             $this->assertEquals(1, count($result));
             $this->assertEquals($testPath, $result[0]['path']);
         }
@@ -909,7 +922,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $this->_objects['paths'][] = Filemanager_Controller_Node::getInstance()->addBasePath($targetPath . '/dir1');
         $this->_objects['paths'][] = Filemanager_Controller_Node::getInstance()->addBasePath($targetPath . '/dir2');
         
-        $result = $this->_json->moveNodes($dirsToMove, $targetPath, FALSE);
+        $result = $this->_getUit()->moveNodes($dirsToMove, $targetPath, FALSE);
         $this->assertEquals(2, count($result));
         $this->assertEquals($targetPath . '/dir1', $result[0]['path']);
     }
@@ -922,7 +935,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $sourceNode = $this->testCreateContainerNodeInPersonalFolder();
         
         $newPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testcontainermoved';
-        $result = $this->_json->moveNodes($sourceNode['path'], array($newPath), FALSE);
+        $result = $this->_getUit()->moveNodes($sourceNode['path'], array($newPath), FALSE);
         $this->assertEquals(1, count($result));
         $this->assertEquals($newPath, $result[0]['path'], 'no new path: ' . print_r($result, TRUE));
 
@@ -935,7 +948,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => Tinebase_Model_Tree_FileObject::TYPE_FOLDER,
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         foreach ($result['results'] as $node) {
             $this->assertNotEquals($sourceNode['path'], $node['path']);
         }
@@ -950,7 +963,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         
         $oldPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testcontainer';
         $newPath = $oldPath . 'moved';
-        $result = $this->_json->moveNodes(array($oldPath), array($newPath), FALSE);
+        $result = $this->_getUit()->moveNodes(array($oldPath), array($newPath), FALSE);
         $this->assertEquals(1, count($result));
         $this->assertEquals($newPath, $result[0]['path']);
 
@@ -963,7 +976,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => Tinebase_Model_Tree_FileObject::TYPE_FOLDER,
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         $this->assertEquals(2, $result['totalcount']);
     }
     
@@ -977,7 +990,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $filesToMove = $this->testCreateFileNodes();
         $targetNode = $this->testCreateContainerNodeInPersonalFolder();
         
-        $result = $this->_json->moveNodes($filesToMove, $targetNode['path'], FALSE);
+        $result = $this->_getUit()->moveNodes($filesToMove, $targetNode['path'], FALSE);
         $this->assertEquals(2, count($result));
         $this->assertEquals($targetNode['path'] . '/file1', $result[0]['path']);
 
@@ -990,7 +1003,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => Tinebase_Model_Tree_FileObject::TYPE_FILE,
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         $this->assertEquals(0, $result['totalcount']);
         
         return $targetNode;
@@ -1005,7 +1018,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         
         $sharedContainerPath = '/' . Tinebase_FileSystem::FOLDER_TYPE_SHARED . '/testcontainer/';
         $filesToMove = array($sharedContainerPath . 'file1', $sharedContainerPath . 'file2');
-        $result = $this->_json->moveNodes($filesToMove, $targetNode['path'], TRUE);
+        $result = $this->_getUit()->moveNodes($filesToMove, $targetNode['path'], TRUE);
         
         $this->assertEquals(2, count($result));
     }
@@ -1019,7 +1032,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         
         $target = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName;
         $this->_objects['paths'][] = Filemanager_Controller_Node::getInstance()->addBasePath($target . '/testcontainer');
-        $result = $this->_json->moveNodes($children[0], $target, FALSE);
+        $result = $this->_getUit()->moveNodes($children[0], $target, FALSE);
         $this->assertEquals(1, count($result));
         $this->assertEquals('dir1', $result[0]['name'], print_r($result[0], TRUE));
     }
@@ -1044,7 +1057,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $sharedContainerNode = $this->testCreateContainerNodeInSharedFolder();
         
-        $this->_json->deleteNodes($sharedContainerNode['path']);
+        $this->_getUit()->deleteNodes($sharedContainerNode['path']);
 
         // check if node is deleted
         $this->setExpectedException('Tinebase_Exception_NotFound');
@@ -1063,7 +1076,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             static::assertEquals(16, $parentFolder->size, 'two files with 8 bytes each created, excpected 16 bytes folder size');
         }
         
-        $this->_json->deleteNodes($filepaths);
+        $this->_getUit()->deleteNodes($filepaths);
 
         if (true === $_addData) {
             $parentFolder = $this->_fsController->stat(Filemanager_Controller_Node::getInstance()->addBasePath(dirname($filepaths[0])));
@@ -1101,7 +1114,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         
         // node should no longer be found
         try {
-            $this->_json->getNode($fileNode['id']);
+            $this->_getUit()->getNode($fileNode['id']);
             $this->fail('tree node still exists: ' . print_r($fileNode, TRUE));
         } catch (Tinebase_Exception_NotFound $tenf) {
             $this->assertEquals('Tinebase_Model_Tree_Node record with id = ' . $fileNode['id'] . ' not found!', $tenf->getMessage());
@@ -1115,7 +1128,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $dirpaths = $this->testCreateDirectoryNodesInShared();
         
-        $result = $this->_json->deleteNodes($dirpaths);
+        $result = $this->_getUit()->deleteNodes($dirpaths);
 
         // check if node is deleted
         $this->setExpectedException('Tinebase_Exception_NotFound');
@@ -1136,16 +1149,16 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals', 
             'value'    => '/' . Tinebase_FileSystem::FOLDER_TYPE_SHARED . '/testcontainer'
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         
         $this->assertEquals(2, $result['totalcount']);
         $initialNode = $result['results'][0];
         
-        $node = $this->_json->getNode($initialNode['id']);
+        $node = $this->_getUit()->getNode($initialNode['id']);
         $this->assertEquals('file', $node['type']);
         
         $node['description'] = 'UNITTEST';
-        $node = $this->_json->saveNode($node);
+        $node = $this->_getUit()->saveNode($node);
         
         $this->assertEquals('UNITTEST', $node['description']);
         $this->assertEquals($initialNode['contenttype'], $node['contenttype'], 'contenttype  not preserved');
@@ -1169,7 +1182,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $node['path'] = '';
         // remove hash field that the client does not send
         unset($node['hash']);
-        $updatedNode = $this->_json->saveNode($node);
+        $updatedNode = $this->_getUit()->saveNode($node);
 
         $this->assertEquals(1, count($updatedNode['tags']));
         $this->assertEquals($node['contenttype'], $updatedNode['contenttype'], 'contenttype  not preserved');
@@ -1184,7 +1197,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $node = $this->testGetUpdate();
         $node['relations'] = array($this->_getRelationData($node));
-        $node = $this->_json->saveNode($node);
+        $node = $this->_getUit()->saveNode($node);
         
         $this->assertEquals(1, count($node['relations']));
         $this->assertEquals('PHPUNIT, ali', $node['relations'][0]['related_record']['n_fileas']);
@@ -1230,7 +1243,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $node = $this->testCreateFileNodeWithUTF8Filenames();
         $node['relations'] = array($this->_getRelationData($node));
-        $node = $this->_json->saveNode($node);
+        $node = $this->_getUit()->saveNode($node);
         
         $adbJson = new Addressbook_Frontend_Json();
         $contact = $adbJson->getContact($node['relations'][0]['related_id']);
@@ -1250,13 +1263,13 @@ class Filemanager_Frontend_JsonTests extends TestCase
      {
         $path = '/personal/' .Tinebase_Core::getUser()->accountLoginName . '/' . $this->_getPersonalFilemanagerContainer()->name;
      
-        $this->_json->createNode($path . '/Test1', 'folder', NULL, FALSE);
-        $this->_json->createNode($path . '/Test1/Test2', 'folder', NULL, FALSE);
-        $this->_json->createNode($path . '/Test1/Test3', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode($path . '/Test1', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode($path . '/Test1/Test2', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode($path . '/Test1/Test3', 'folder', NULL, FALSE);
         
         $this->setExpectedException('Filemanager_Exception_NodeExists');
         
-        $this->_json->moveNodes(array($path . '/Test1/Test3'), array($path . '/Test1/Test2'), FALSE);
+        $this->_getUit()->moveNodes(array($path . '/Test1/Test3'), array($path . '/Test1/Test2'), FALSE);
      }
     
     /**
@@ -1272,7 +1285,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $tempFileBackend = new Tinebase_TempFile();
         
         foreach($fixtures as $path) {
-            $node = $this->_json->createNode($path[0], Tinebase_Model_Tree_FileObject::TYPE_FOLDER, NULL, FALSE);
+            $node = $this->_getUit()->createNode($path[0], Tinebase_Model_Tree_FileObject::TYPE_FOLDER, NULL, FALSE);
             
             $this->assertEquals(str_replace('/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/', '', $path[0]), $node['name']);
             $this->assertEquals($path[0], $node['path']);
@@ -1281,9 +1294,9 @@ class Filemanager_Frontend_JsonTests extends TestCase
     
             $filepath = $node['path'] . '/' . $path[1];
             // create empty file first (like the js frontend does)
-            $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, array(), FALSE);
+            $result = $this->_getUit()->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, array(), FALSE);
             $tempFile = $tempFileBackend->createTempFile(dirname(dirname(__FILE__)) . '/files/' . $path[1]);
-            $result = $this->_json->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, $tempFile->getId(), TRUE);
+            $result = $this->_getUit()->createNode($filepath, Tinebase_Model_Tree_FileObject::TYPE_FILE, $tempFile->getId(), TRUE);
         }
         
         $filter = array(
@@ -1292,7 +1305,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             array('field' => 'query',     'operator' => 'contains', 'value' => 'color'),
         'AND');
         
-        $result = $this->_json->searchNodes($filter, array('sort' => 'name', 'start' => 0, 'limit' => 0));
+        $result = $this->_getUit()->searchNodes($filter, array('sort' => 'name', 'start' => 0, 'limit' => 0));
         $this->assertEquals(3, count($result), '3 files should have been found!');
     }
     
@@ -1328,13 +1341,13 @@ class Filemanager_Frontend_JsonTests extends TestCase
      */
     public function testMoveFolderIntoChildFolder()
     {
-        $this->_json->createNode('/shared/Parent', 'folder', NULL, FALSE);
-        $this->_json->createNode('/shared/Parent/Child', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode('/shared/Parent', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode('/shared/Parent/Child', 'folder', NULL, FALSE);
         
         $this->setExpectedException('Filemanager_Exception_DestinationIsOwnChild');
         
         // this must not work
-        $this->_json->moveNodes(array('/shared/Parent'), array('/shared/Parent/Child/Parent'), FALSE);
+        $this->_getUit()->moveNodes(array('/shared/Parent'), array('/shared/Parent/Child/Parent'), FALSE);
     }
     
     /**
@@ -1344,13 +1357,13 @@ class Filemanager_Frontend_JsonTests extends TestCase
      */
     public function testMoveFolderToSamePosition()
     {
-        $this->_json->createNode('/shared/Parent', 'folder', NULL, FALSE);
-        $this->_json->createNode('/shared/Parent/Child', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode('/shared/Parent', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode('/shared/Parent/Child', 'folder', NULL, FALSE);
     
         $this->setExpectedException('Filemanager_Exception_DestinationIsSameNode');
     
         // this must not work
-        $this->_json->moveNodes(array('/shared/Parent/Child'), array('/shared/Parent/Child'), FALSE);
+        $this->_getUit()->moveNodes(array('/shared/Parent/Child'), array('/shared/Parent/Child'), FALSE);
     }
 
     /**
@@ -1362,13 +1375,13 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $path = '/personal/' .Tinebase_Core::getUser()->accountLoginName . '/' . $this->_getPersonalFilemanagerContainer()->name;
     
-        $this->_json->createNode($path . '/Parent', 'folder', NULL, FALSE);
-        $this->_json->createNode($path . '/Parent/Child', 'folder', NULL, FALSE);
-        $this->_json->createNode('/shared/Another', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode($path . '/Parent', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode($path . '/Parent/Child', 'folder', NULL, FALSE);
+        $this->_getUit()->createNode('/shared/Another', 'folder', NULL, FALSE);
     
         // move forth and back, no exception should occur
-        $this->_json->moveNodes(array($path . '/Parent'), array('/shared/Parent'), FALSE);
-        $this->_json->moveNodes(array('/shared/Parent'), array($path . '/Parent'), FALSE);
+        $this->_getUit()->moveNodes(array($path . '/Parent'), array('/shared/Parent'), FALSE);
+        $this->_getUit()->moveNodes(array('/shared/Parent'), array($path . '/Parent'), FALSE);
     
         try {
             $c = Tinebase_Container::getInstance()->getContainerByName('Filemanager', 'Parent', Tinebase_FileSystem::FOLDER_TYPE_SHARED);
@@ -1380,7 +1393,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $e = new Tinebase_Exception('Dog eats cat');
     
         try {
-            $this->_json->moveNodes(array($path . '/Parent'), array('/shared/Parent'), FALSE);
+            $this->_getUit()->moveNodes(array($path . '/Parent'), array('/shared/Parent'), FALSE);
         } catch (Filemanager_Exception_NodeExists $e) {
         }
     
@@ -1397,13 +1410,13 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $path = '/personal/' .Tinebase_Core::getUser()->accountLoginName . '/' . $this->_getPersonalFilemanagerContainer()->name;
 
-        $result = $this->_json->createNode($path . '/Test1', 'folder', NULL, FALSE);
+        $result = $this->_getUit()->createNode($path . '/Test1', 'folder', NULL, FALSE);
         $this->assertTrue(isset($result['id']));
-        $result = $this->_json->createNode($path . '/Test1/Test1', 'folder', NULL, FALSE);
+        $result = $this->_getUit()->createNode($path . '/Test1/Test1', 'folder', NULL, FALSE);
         $this->assertTrue(isset($result['id']), 'node has not been created');
         $e = new Tinebase_Exception('nothing');
         try {
-            $this->_json->createNode($path . '/Test1/Test1/Test2', 'folder', NULL, FALSE);
+            $this->_getUit()->createNode($path . '/Test1/Test1/Test2', 'folder', NULL, FALSE);
         } catch (Exception $e) {
             $this->fail('The folder couldn\'t be found, so it hasn\'t ben created');
         }
@@ -1516,7 +1529,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     public function testSaveDownloadLinkFile()
     {
         $downloadLinkData = $this->_getDownloadLinkData();
-        $result = $this->_json->saveDownloadLink($downloadLinkData);
+        $result = $this->_getUit()->saveDownloadLink($downloadLinkData);
         
         $this->assertTrue(! empty($result['url']));
         $this->assertEquals($this->_getDownloadUrl($result['id']), $result['url']);
@@ -1538,7 +1551,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     public function testSaveDownloadLinkDirectory()
     {
         $downloadLinkData = $this->_getDownloadLinkData();
-        $result = $this->_json->saveDownloadLink($downloadLinkData);
+        $result = $this->_getUit()->saveDownloadLink($downloadLinkData);
         
         $this->assertTrue(! empty($result['url']));
         $this->assertEquals($this->_getDownloadUrl($result['id']), $result['url']);
@@ -1578,7 +1591,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $downloadLink = $this->testSaveDownloadLinkFile();
         
-        $this->assertEquals($downloadLink, $this->_json->getDownloadLink($downloadLink['id']));
+        $this->assertEquals($downloadLink, $this->_getUit()->getDownloadLink($downloadLink['id']));
     }
     
     /**
@@ -1592,7 +1605,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator'  => 'equals',
             'value'     => $downloadLink['id']
         ));
-        $result = $this->_json->searchDownloadLinks($filter, array());
+        $result = $this->_getUit()->searchDownloadLinks($filter, array());
         
         $this->assertEquals(1, $result['totalcount']);
     }
@@ -1604,7 +1617,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $downloadLink = $this->testSaveDownloadLinkFile();
 
-        $this->_json->deleteDownloadLinks(array($downloadLink['id']));
+        $this->_getUit()->deleteDownloadLinks(array($downloadLink['id']));
         try {
             Filemanager_Controller_DownloadLink::getInstance()->get($downloadLink['id']);
             $this->fail('link should have been deleted');
@@ -1627,7 +1640,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals',
             'value'    => $sharedRoot
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
 
         self::assertEquals(1, $result['totalcount']);
         $node = $result['results'][0];
@@ -1640,13 +1653,13 @@ class Filemanager_Frontend_JsonTests extends TestCase
             'operator' => 'equals',
             'value'    => $node['path']
         ));
-        $result = $this->_json->searchNodes($filter, array());
+        $result = $this->_getUit()->searchNodes($filter, array());
         self::assertEquals(2, $result['totalcount'], 'no files found in path: ' . print_r($result, true));
         $file1Node = $result['results'][0];
         self::assertContains('/shared/testcontainer/file', $file1Node['path'], 'no path found in node: ' . print_r($file1Node, true));
         $this->_assertGrantsInNode($file1Node);
 
-        $file2Node = $this->_json->getNode($result['results'][1]['id']);
+        $file2Node = $this->_getUit()->getNode($result['results'][1]['id']);
         self::assertContains('/shared/testcontainer/file', $file2Node['path'], 'no path found in node: ' . print_r($file2Node, true));
         $this->_assertGrantsInNode($file2Node);
     }
@@ -1667,7 +1680,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $node = $this->testCreateContainerNodeInSharedFolder();
         $node['grants'] = Tinebase_Model_Grants::getPersonalGrants(Tinebase_Core::getUser())->toArray();
-        $result = $this->_json->saveNode($node);
+        $result = $this->_getUit()->saveNode($node);
 
         self::assertEquals(1, count($result['grants']), print_r($result['grants'], true));
         self::assertEquals(Tinebase_Acl_Rights::ACCOUNT_TYPE_USER, $result['grants'][0]['account_type']);
@@ -1679,7 +1692,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $node = $this->testSetNodeAcl();
         $node['grants'] = null;
-        $result = $this->_json->saveNode($node);
+        $result = $this->_getUit()->saveNode($node);
 
         self::assertEquals(1, count($result['grants']), 'it is not allowed to remove top level node grants - '
             . print_r($result['grants'], true));
@@ -1690,17 +1703,17 @@ class Filemanager_Frontend_JsonTests extends TestCase
         $node = $this->testCreateContainerNodeInSharedFolder();
         // create child folder node
         $testPath = $node['path'] . '/child';
-        $child = $this->_json->createNode($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, NULL, FALSE);
+        $child = $this->_getUit()->createNode($testPath, Tinebase_Model_Tree_FileObject::TYPE_FOLDER, NULL, FALSE);
 
         $child['grants'] = Tinebase_Model_Grants::getPersonalGrants(Tinebase_Core::getUser())->toArray();
         $child['acl_node'] = $child['id'];
-        $child = $this->_json->saveNode($child);
+        $child = $this->_getUit()->saveNode($child);
 
         self::assertEquals(1, count($child['grants']), 'node should have only personal grants - '
             . print_r($child['grants'], true));
 
         $child['acl_node'] = null;
-        $childWithoutPersonalGrants = $this->_json->saveNode($child);
+        $childWithoutPersonalGrants = $this->_getUit()->saveNode($child);
 
         self::assertEquals(2, count($childWithoutPersonalGrants['grants']), 'node should have parent grants again - '
             . print_r($childWithoutPersonalGrants['grants'], true));
@@ -1730,7 +1743,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         Tinebase_TransactionManager::getInstance()->commitTransaction($this->_transactionId);
         $this->_transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
 
-        $result = $this->_json->searchNodes(array(
+        $result = $this->_getUit()->searchNodes(array(
             array(
                 'field'    => 'recursive',
                 'operator' => 'equals',
@@ -1791,8 +1804,8 @@ class Filemanager_Frontend_JsonTests extends TestCase
 
         $this->testCreateDirectoryNodesInPersonal();
         $path = '/' . Tinebase_FileSystem::FOLDER_TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/testcontainer';
-        $this->_json->createNodes(array($path . '/dir1/subdir11', $path . '/dir1/subdir12'), Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
-        $this->_json->createNodes(array($path . '/dir2/subdir21', $path . '/dir2/subdir22'), Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
+        $this->_getUit()->createNodes(array($path . '/dir1/subdir11', $path . '/dir1/subdir12'), Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
+        $this->_getUit()->createNodes(array($path . '/dir2/subdir21', $path . '/dir2/subdir22'), Tinebase_Model_Tree_FileObject::TYPE_FOLDER, array(), FALSE);
 
 
         // NONE of them have revision properties
@@ -1819,7 +1832,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         );
         $this->_setRevisionProperties($nodes['dir1'], $dir1TreeRevisionProperties);
 
-        $this->_json->saveNode($nodes['dir1']->toArray());
+        $this->_getUit()->saveNode($nodes['dir1']->toArray());
 
         $fileSystem->clearStatCache();
         $nodes = $this->_statPaths($paths);
@@ -1855,7 +1868,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         );
         $this->_setRevisionProperties($nodes['subDir22'], $subdir22TreeRevisionProperties);
 
-        $this->_json->saveNode($nodes['subDir22']->toArray());
+        $this->_getUit()->saveNode($nodes['subDir22']->toArray());
 
         // MOVE DIR1 from SUBDIR21 to SUBDIR22 => they should still not change!
         $fileSystem->rename($paths['dir1']->statpath, $paths['subDir22']->statpath . '/tmp');
@@ -1896,7 +1909,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
         );
         $this->_setRevisionProperties($nodes['testContainer'], $testContainerRevisionProperties);
 
-        $this->_json->saveNode($nodes['testContainer']->toArray());
+        $this->_getUit()->saveNode($nodes['testContainer']->toArray());
 
         $fileSystem->clearStatCache();
         $nodes = $this->_statPaths($paths);
@@ -1907,7 +1920,7 @@ class Filemanager_Frontend_JsonTests extends TestCase
     {
         $result = $this->testCreateFileNodeWithTempfile();
 
-        $usageInfo = $this->_json->getFolderUsage($result['parent_id']);
+        $usageInfo = $this->_getUit()->getFolderUsage($result['parent_id']);
         $userId = Tinebase_Core::getUser()->contact_id;
 
         $this->assertEquals(17, $usageInfo['type']['txt']['size']);
index daf0daf..24a9608 100644 (file)
@@ -5,6 +5,18 @@
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Michael Spahn <m.spahn@metaways.de>
  * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
+ *
+ * usage:
+ *
+ * 1) add trait:
+ *
+ *    use GetProtectedMethodTrait;
+ *
+ * 2) use trait:
+ *
+ *    $reflectionMethod = $this->getProtectedMethod(Felamimail_Model_Message::class, 'sanitizeMailAddress');
+ *    $result = $reflectionMethod->invokeArgs(new Felamimail_Model_Message(), [$obfuscatedMail]);
+ *
  */
 trait GetProtectedMethodTrait
 {
index cce33b4..e535fc0 100644 (file)
@@ -30,8 +30,24 @@ class Filemanager_Frontend_Http extends Tinebase_Frontend_Http_Abstract
      */
     public function downloadFile($path, $id, $revision = null)
     {
+        $this->_downloadFileNodeByPathOrId($path, $id, $revision);
+        exit;
+    }
+
+    /**
+     * _downloadFileNodeByPathOrId
+     *
+     * @param      $path
+     * @param      $id
+     * @param null $revision
+     * @throws Filemanager_Exception
+     * @throws Tinebase_Exception_AccessDenied
+     * @throws Tinebase_Exception_InvalidArgument
+     */
+    protected function _downloadFileNodeByPathOrId($path, $id, $revision = null)
+    {
         $revision = $revision ?: null;
-        
+
         $nodeController = Filemanager_Controller_Node::getInstance();
         if ($path) {
             $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($path));
@@ -45,8 +61,6 @@ class Filemanager_Frontend_Http extends Tinebase_Frontend_Http_Abstract
         }
 
         $this->_downloadFileNode($node, $pathRecord->streamwrapperpath, $revision);
-
-        exit;
     }
 
     /**
index 5b1aaee..ad4c228 100644 (file)
@@ -251,7 +251,7 @@ Tine.Filemanager.nodeActions.Move = {
  */
 Tine.Filemanager.nodeActions.Download = {
     app: 'Filemanager',
-    requiredGrant: 'readGrant',
+    requiredGrant: 'downloadGrant',
     allowMultiple: false,
     actionType: 'download',
     text: 'Save locally', // _('Save locally')
@@ -265,7 +265,7 @@ Tine.Filemanager.nodeActions.Download = {
         var enabled = !isFilterSelect
             && records && records.length == 1
             && records[0].get('type') != 'folder'
-            && window.lodash.get(records, '[0].data.account_grants.readGrant', false);
+            && window.lodash.get(records, '[0].data.account_grants.downloadGrant', false);
 
         action.setDisabled(!enabled);
     }
index 6f8a25d..3e5a6ee 100644 (file)
@@ -289,10 +289,14 @@ class Tinebase_FileSystem implements Tinebase_Controller_Interface, Tinebase_Con
             if (null === $grants) {
                 switch ($pathRecord->containerType) {
                     case self::FOLDER_TYPE_PERSONAL:
-                        $node->grants = Tinebase_Model_Grants::getPersonalGrants($pathRecord->getUser());
+                        $node->grants = Tinebase_Model_Grants::getPersonalGrants($pathRecord->getUser(), array(
+                            Tinebase_Model_Grants::GRANT_DOWNLOAD => true
+                        ));
                         break;
                     case self::FOLDER_TYPE_SHARED:
-                        $node->grants = Tinebase_Model_Grants::getDefaultGrants();
+                        $node->grants = Tinebase_Model_Grants::getDefaultGrants(array(
+                            Tinebase_Model_Grants::GRANT_DOWNLOAD => true
+                        ));
                         break;
                 }
             } else {
index 68b8385..6a54e51 100644 (file)
@@ -149,6 +149,10 @@ abstract class Tinebase_Frontend_Http_Abstract extends Tinebase_Frontend_Abstrac
      */
     protected function _downloadFileNode(Tinebase_Model_Tree_Node $node, $filesystemPath, $revision = null)
     {
+        if (! Tinebase_Core::getUser()->hasGrant($node, Tinebase_Model_Grants::GRANT_DOWNLOAD)) {
+            throw new Tinebase_Exception_AccessDenied('download not allowed');
+        }
+
         Tinebase_Core::setExecutionLifeTime(0);
         
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
@@ -180,6 +184,10 @@ abstract class Tinebase_Frontend_Http_Abstract extends Tinebase_Frontend_Abstrac
      */
     protected function _prepareHeader($filename, $contentType, $disposition = 'attachment')
     {
+        if (headers_sent()) {
+            return;
+        }
+
         // cache for 3600 seconds
         $maxAge = 3600;
         header('Cache-Control: private, max-age=' . $maxAge);
index 92f8130..ff6f2a0 100644 (file)
@@ -18,6 +18,9 @@ class Tinebase_Frontend_WebDAV_File extends Tinebase_Frontend_WebDAV_Node implem
 {
     public function get() 
     {
+        if (!Tinebase_Core::getUser()->hasGrant($this->_getContainer(), Tinebase_Model_Grants::GRANT_DOWNLOAD)) {
+            throw new Sabre\DAV\Exception\Forbidden('Forbidden to download file: ' . $this->_path);
+        }
         $handle = Tinebase_FileSystem::getInstance()->fopen($this->_path, 'r');
          
         return $handle;
index 9962003..a6ec23f 100644 (file)
@@ -63,7 +63,12 @@ class Tinebase_Model_Grants extends Tinebase_Record_Abstract
      * @todo move to Calendar_Model_Grant once we are able to cope with app specific grant classes
      */
     const GRANT_FREEBUSY = 'freebusyGrant';
-    
+
+    /**
+     * grant to download file nodes
+     */
+    const GRANT_DOWNLOAD = 'downloadGrant';
+
     /**
      * key in $_validators/$_properties array for the filed which 
      * represents the identifier
@@ -132,6 +137,7 @@ class Tinebase_Model_Grants extends Tinebase_Record_Abstract
             self::GRANT_SYNC,
             self::GRANT_ADMIN,
             self::GRANT_FREEBUSY,
+            self::GRANT_DOWNLOAD,
         );
     
         return $allGrants;
@@ -218,20 +224,21 @@ class Tinebase_Model_Grants extends Tinebase_Record_Abstract
     /**
      * return default grants with read for user group and write/admin for admin group
      *
+     * @param array $_additionalGrants
      * @return Tinebase_Record_RecordSet of Tinebase_Model_Grants
      */
-    public static function getDefaultGrants()
+    public static function getDefaultGrants($_additionalGrants = array())
     {
         $groupsBackend = Tinebase_Group::getInstance();
         return new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(
-            array(
+            array_merge(array(
                 'account_id' => $groupsBackend->getDefaultGroup()->getId(),
                 'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP,
                 Tinebase_Model_Grants::GRANT_READ => true,
                 Tinebase_Model_Grants::GRANT_EXPORT => true,
                 Tinebase_Model_Grants::GRANT_SYNC => true,
-            ),
-            array(
+            ), $_additionalGrants),
+            array_merge(array(
                 'account_id' => $groupsBackend->getDefaultAdminGroup()->getId(),
                 'account_type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_GROUP,
                 Tinebase_Model_Grants::GRANT_READ => true,
@@ -241,7 +248,7 @@ class Tinebase_Model_Grants extends Tinebase_Record_Abstract
                 Tinebase_Model_Grants::GRANT_ADMIN => true,
                 Tinebase_Model_Grants::GRANT_EXPORT => true,
                 Tinebase_Model_Grants::GRANT_SYNC => true,
-            ),
+            ), $_additionalGrants),
         ), TRUE);
     }
 
@@ -249,21 +256,24 @@ class Tinebase_Model_Grants extends Tinebase_Record_Abstract
      * return personal grants for given account
      *
      * @param string|Tinebase_Model_User          $_accountId
+     * @param array $_additionalGrants
      * @return Tinebase_Record_RecordSet of Tinebase_Model_Grants
      */
-    public static function getPersonalGrants($_accountId)
+    public static function getPersonalGrants($_accountId, $_additionalGrants = array())
     {
         $accountId = Tinebase_Model_User::convertUserIdToInt($_accountId);
-        return new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array(
-            'account_id'     => $accountId,
-            'account_type'   => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER,
-            Tinebase_Model_Grants::GRANT_READ      => true,
+        $grants = array(Tinebase_Model_Grants::GRANT_READ      => true,
             Tinebase_Model_Grants::GRANT_ADD       => true,
             Tinebase_Model_Grants::GRANT_EDIT      => true,
             Tinebase_Model_Grants::GRANT_DELETE    => true,
             Tinebase_Model_Grants::GRANT_EXPORT    => true,
             Tinebase_Model_Grants::GRANT_SYNC      => true,
             Tinebase_Model_Grants::GRANT_ADMIN     => true,
-        )));
+        );
+        $grants = array_merge($grants, $_additionalGrants);
+        return new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array_merge(array(
+            'account_id'     => $accountId,
+            'account_type'   => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER,
+        ), $grants)));
     }
 }