0011090: user id replaced "currentAccount" placeholder
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 2 Mar 2016 09:20:07 +0000 (10:20 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 10 Mar 2016 09:02:32 +0000 (10:02 +0100)
* adds a test and updates json frontend tests
* problem fixed in Tinebase_Model_Filter_User::setValue/toArray:
  -> we save the magic CURRENTACCOUNT value in setValue and
   return it in toArray

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

Change-Id: Ie64155782258c2673add89cceaedb574d11aab01
Reviewed-on: http://gerrit.tine20.com/customers/2838
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Tinebase/Frontend/Json/PersistentFilterTest.php
tests/tine20/Tinebase/PersistentFilterTest.php
tine20/Tasks/Setup/Initialize.php
tine20/Tinebase/Model/Filter/User.php
tine20/Tinebase/PersistentFilter/Backend/Sql.php

index ffa7910..1955d80 100644 (file)
@@ -304,7 +304,11 @@ class Tinebase_Frontend_Json_PersistentFilterTest extends TestCase
                     break;
                 case 'organizer':
                     $this->assertTrue(is_array($responseFilter['value']), 'user is not resolved');
-                    $this->assertEquals($requestFilter['value'], $responseFilter['value']['accountId'], 'wrong accountId');
+                    if ($requestFilter['value'] !== 'currentAccount') {
+                        $this->assertEquals($requestFilter['value'], $responseFilter['value']['accountId'], 'wrong accountId');
+                    } else {
+                        $this->assertEquals(Tinebase_Core::getUser()->getId(), $responseFilter['value']['accountId'], 'wrong accountId');
+                    }
                     break;
                 case 'due':
                     $this->assertEquals($requestFilter['value'], $responseFilter['value'], 'wrong due date');
@@ -332,7 +336,7 @@ class Tinebase_Frontend_Json_PersistentFilterTest extends TestCase
             'filters'           => array(
                 array('field' => 'query',        'operator' => 'contains',  'value' => 'test'),
                 array('field' => 'container_id', 'operator' => 'equals',    'value' => Tasks_Controller::getInstance()->getDefaultContainer()->getId()),
-                array('field' => 'organizer',    'operator' => 'equals',    'value' => Tinebase_Core::getUser()->getId()),
+                array('field' => 'organizer',    'operator' => 'equals',    'value' => Tinebase_Model_User::CURRENTACCOUNT),
                 array('field' => 'due',          'operator' => 'after',     'value' => '2010-03-20 18:00:00'),
             )
         );
index d94e556..ca89169 100644 (file)
@@ -4,7 +4,7 @@
  * 
  * @package     Tinebase
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2014-2016 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  * 
  */
@@ -81,13 +81,19 @@ class Tinebase_PersistentFilterTest extends TestCase
      */
     public function testSaveSharedFavorite()
     {
-        $filter = new Tinebase_Model_PersistentFilter(Tinebase_Frontend_Json_PersistentFilterTest::getPersistentFilterData());
+        $filter = new Tinebase_Model_PersistentFilter(
+            Tinebase_Frontend_Json_PersistentFilterTest::getPersistentFilterData()
+        );
         $filter->account_id = null;
         $newFilter = $this->_instance->create($filter);
         
         $this->assertTrue(count($newFilter->grants) === 2, 'did not find default grants in filter: '
             . print_r($newFilter->toArray(), true));
-        
+
+        $filterArray = $newFilter->toArray();
+        $this->assertEquals(Tinebase_Model_User::CURRENTACCOUNT, $filterArray['filters'][2]['value'],
+            print_r($filterArray['filters'], true));
+
         return $newFilter;
     }
     
@@ -188,4 +194,36 @@ class Tinebase_PersistentFilterTest extends TestCase
         $this->assertTrue($grant !== null);
         $this->assertTrue($grant->userHasGrant(Tinebase_Model_PersistentFilterGrant::GRANT_READ));
     }
+
+    /**
+     * testCurrentAccountValue: checks if organizer is "magic word" Tinebase_Model_User::CURRENTACCOUNT
+     *
+     * @see 0011090: Aufgaben - Favoriten - Falscher Verantwortlicher
+     */
+    public function testCurrentAccountValue()
+    {
+        // look at default task favorites: currentAccount should be set as value
+        foreach (array('My open tasks', 'All tasks for me') as $filterName) {
+            $filter = new Tinebase_Model_PersistentFilterFilter(array(
+                //array('field' => 'account_id',      'operator' => 'equals', 'value' => Tinebase_Core::getUser()->getId()),
+                array(
+                    'field' => 'name',
+                    'operator' => 'equals',
+                    'value' => $filterName
+                ),
+                array(
+                    'field' => 'application_id',
+                    'operator' => 'equals',
+                    'value' => Tinebase_Application::getInstance()->getApplicationById('Tasks')->getId()
+                ),
+            ));
+
+            $result = Tinebase_PersistentFilter::getInstance()->search($filter)->getFirstRecord();
+
+            $this->assertTrue($result !== null);
+            $filters = $result->toArray();
+            $filters = $filters['filters'];
+            $this->assertEquals(Tinebase_Model_User::CURRENTACCOUNT, $filters[0]['value'], print_r($filters, true));
+        }
+    }
 }
index a988faa..6e2acbd 100644 (file)
@@ -46,7 +46,7 @@ class Tasks_Setup_Initialize extends Setup_Initialize
             'name'              => "My open tasks",
             'description'       => "My open tasks", // _("My open tasks")
             'filters'           => array(
-                array('field' => 'organizer',    'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT),
+                array('field' => 'organizer', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT),
                 array('field' => 'status',    'operator' => 'notin',  'value' => $closedStatus->getId()),
             )
         ))));
index 1ed29fb..5f2eca5 100644 (file)
@@ -56,8 +56,11 @@ class Tinebase_Model_Filter_User extends Tinebase_Model_Filter_Text
             $_value = Tinebase_Group::getInstance()->getGroupMembers($this->_userValue);
         }
         
-        // transform current user 
-        $_value = ($_value == Tinebase_Model_User::CURRENTACCOUNT && is_object(Tinebase_Core::getUser())) ? Tinebase_Core::getUser()->getId() : $_value;
+        // transform current user
+        if ($_value == Tinebase_Model_User::CURRENTACCOUNT && is_object(Tinebase_Core::getUser())) {
+            $_value = Tinebase_Core::getUser()->getId();
+            $this->_userValue = Tinebase_Model_User::CURRENTACCOUNT;
+        }
         
         parent::setValue($_value);
     }
@@ -75,6 +78,9 @@ class Tinebase_Model_Filter_User extends Tinebase_Model_Filter_Text
         if ($this->_userOperator && $this->_userOperator == 'inGroup') {
             $result['operator'] = $this->_userOperator;
             $result['value']    = $this->_userValue;
+        } else if ($this->_userValue === Tinebase_Model_User::CURRENTACCOUNT) {
+            // switch back to CURRENTACCOUNT to make sure filter is saved and shown in client correctly
+            $result['value']    = $this->_userValue;
         }
         
         if ($_valueToJson == true ) {
index f10368d..8423c63 100644 (file)
@@ -54,7 +54,7 @@ class Tinebase_PersistentFilter_Backend_Sql extends Tinebase_Backend_Sql_Abstrac
      */
     public static function getFilterById($_id)
     {
-        $obj = new Tinebase_PersistentFilter();
+        $obj = Tinebase_PersistentFilter::getInstance();
         $persistentFilter = $obj->get($_id);
         
         return $persistentFilter->filters;