Filemanager pin protected folders - fix filter / add result flag protected folders...
authorPaul Mehrer <p.mehrer@metaways.de>
Wed, 26 Jul 2017 12:41:38 +0000 (14:41 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Thu, 27 Jul 2017 08:41:08 +0000 (10:41 +0200)
Change-Id: I626c5ddfc380517f1a22c59e56e723eabddace38
Reviewed-on: http://gerrit.tine20.com/customers/5326
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Filemanager/Frontend/JsonTests.php
tests/tine20/MailFiler/Frontend/JsonTests.php
tine20/Filemanager/Controller/Node.php
tine20/Filemanager/Frontend/Json.php
tine20/Tinebase/Model/Tree/Node/Filter.php

index d16ef4c..344db27 100644 (file)
@@ -1394,11 +1394,10 @@ class Filemanager_Frontend_JsonTests extends TestCase
             array('field' => 'recursive', 'operator' => 'equals',   'value' => 1),
             array('field' => 'path',      'operator' => 'equals',   'value' => '/'),
             array('field' => 'query',     'operator' => 'contains', 'value' => 'color'),
-            array('field' => 'isIndexed', 'operator' => 'equals',   'value' => 0),
         'AND');
         
         $result = $this->_getUit()->searchNodes($filter, array('sort' => 'name', 'start' => 0, 'limit' => 0));
-        $this->assertEquals(3, count($result), '3 files should have been found!');
+        $this->assertEquals(3, count($result['results']), '3 files should have been found!');
     }
     
     /**
index 9be60f1..ca30a17 100644 (file)
@@ -72,7 +72,7 @@ class MailFiler_Frontend_JsonTests extends TestCase
             )
         ));
         $result = $this->_json->searchNodes($filter, array());
-        self::assertEquals(5, count($result['filter']));
+        self::assertEquals(6, count($result['filter']));
         self::assertEquals(0, $result['totalcount']);
     }
 
index 53017a1..3816f23 100644 (file)
@@ -329,7 +329,13 @@ class Filemanager_Controller_Node extends Tinebase_Controller_Record_Abstract
             $context = array();
         }
         $context['quotaResult'] = $quota;
-        $this->setRequestContext($quota);
+        /** @var Tinebase_Model_Tree_Node_Filter $_filter */
+        $_filter->ignorePinProtection();
+        if ((int)$this->_backend->searchNodesCount($_filter) !== $result->count()) {
+            $context['pinProtectedData'] = true;
+        }
+        $this->setRequestContext($context);
+        $_filter->ignorePinProtection(false);
 
         $this->resolveGrants($result);
         return $result;
@@ -371,6 +377,16 @@ class Filemanager_Controller_Node extends Tinebase_Controller_Record_Abstract
 
             $fileNode->path = $parents[$fileNode->parent_id] . '/' . $fileNode->name;
         }
+
+        $filter->ignorePinProtection();
+        if ((int)$this->_backend->searchNodesCount($filter) !== $result->count()) {
+            $context = $this->getRequestContext();
+            if (!is_array($context)) {
+                $context = array();
+            }
+            $context['pinProtectedData'] = true;
+            $this->setRequestContext($context);
+        }
         
         return $result;
     }
index 5bcaebc..5092dcf 100644 (file)
@@ -41,8 +41,13 @@ class Filemanager_Frontend_Json extends Tinebase_Frontend_Json_Abstract
         $this->_removeAppIdFromPathFilter($result);
 
         $context = $controller->getRequestContext();
-        if (is_array($context) && isset($context['quotaResult'])) {
-            $result['quota'] = $context['quotaResult'];
+        if (is_array($context)) {
+            if (isset($context['quotaResult'])) {
+                $result['quota'] = $context['quotaResult'];
+            }
+            if (isset($context['pinProtectedData'])) {
+                $result['pinProtectedData'] = true;
+            }
         }
         
         return $result;
index a1f8f1d..e0e94c6 100644 (file)
@@ -45,6 +45,11 @@ class Tinebase_Model_Tree_Node_Filter extends Tinebase_Model_Filter_GrantsFilter
     protected $_aclIdColumn = 'acl_node';
 
     /**
+     * @var bool
+     */
+    protected $_ignorePinProtection = false;
+
+    /**
      * @var array filter model fieldName => definition
      */
     protected $_filterModel = array(
@@ -146,13 +151,24 @@ class Tinebase_Model_Tree_Node_Filter extends Tinebase_Model_Filter_GrantsFilter
     {
         parent::_appendGrantsFilter($select, $backend, $user);
 
-        if (!Tinebase_Auth_SecondFactor_Abstract::hasValidSecondFactor()) {
-            $select->where('pin_protected = 0');
+        if (!$this->_ignorePinProtection && !Tinebase_Auth_SecondFactor_Abstract::hasValidSecondFactor()) {
+            $db = $backend->getAdapter();
+            $select->joinLeft(array(
+                /* table  */ 'pinProtected' => SQL_TABLE_PREFIX . $backend->getTableName()),
+                /* on     */ "{$db->quoteIdentifier('pinProtected.id')} = {$db->quoteIdentifier($backend->getTableName() . '.' . $this->_aclIdColumn)}",
+                /* select */ array()
+            );
+            $select->where("{$db->quoteIdentifier('pinProtected.pin_protected')} = 0 OR {$db->quoteIdentifier('pinProtected.pin_protected')} IS NULL");
         }
 
         // TODO do something when acl_node = NULL?
     }
 
+    public function ignorePinProtection($_value = true)
+    {
+        $this->_ignorePinProtection = $_value;
+    }
+
     /**
      * return folder + parent_id filter with ignore acl
      *