0013160: user search should find disabled/hidden users
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 30 May 2017 16:37:59 +0000 (18:37 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 31 May 2017 09:44:20 +0000 (11:44 +0200)
* adds recursive param to isFilterSet()
* create contacts for system users
* use var_export instead of print_r for json api payload

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

Change-Id: Idd799c3b09c47d9d84fdc4c31ff1dce0acbb19d4
Reviewed-on: http://gerrit.tine20.com/customers/4781
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/JsonTest.php
tests/tine20/Tinebase/TagsTest.php
tine20/Addressbook/Controller/Contact.php
tine20/Admin/Controller/User.php
tine20/Tinebase/Model/Filter/FilterGroup.php
tine20/Tinebase/Server/Json.php
tine20/Tinebase/User.php

index ad18f23..f067ffd 100644 (file)
@@ -1780,7 +1780,59 @@ Steuernummer 33/111/32212";
         $result = $this->_uit->searchContacts($filter, array());
         $this->assertEquals(1, $result['totalcount']);
     }
-    
+
+    /**
+     * test search hidden user (foir example as role member)
+     *
+     * @see 0013160: user search should find disabled/hidden users
+     */
+    public function testSearchHiddenUser()
+    {
+        $filter = array(
+            0 =>
+                array(
+                    'condition' => 'OR',
+                    'filters' =>
+                        array(
+                            0 =>
+                                array(
+                                    'condition' => 'AND',
+                                    'filters' =>
+                                        array(
+                                            0 =>
+                                                array(
+                                                    'field' => 'query',
+                                                    'operator' => 'contains',
+                                                    'value' => 'replication',
+                                                ),
+                                            1 =>
+                                                array(
+                                                    'field' => 'showDisabled',
+                                                    'operator' => 'equals',
+                                                    'value' => true,
+                                                ),
+                                        ),
+                                ),
+                            1 =>
+                                array(
+                                    'field' => 'path',
+                                    'operator' => 'contains',
+                                    'value' => 'reploic',
+                                ),
+                        ),
+                ),
+            1 =>
+                array(
+                    'field' => 'type',
+                    'operator' => 'equals',
+                    'value' => 'user',
+                ),
+        );
+
+        $result = $this->_uit->searchContacts($filter, array());
+        self::assertEquals(1, $result['totalcount'], 'should find replication user');
+    }
+
     /**
      * test search hidden list -> should not appear
      * 
index f0060a7..a3c20a1 100644 (file)
@@ -251,27 +251,28 @@ class Tinebase_TagsTest extends TestCase
      * testMergeDuplicateTags
      * 
      * @see 0007354: function for merging duplicate tags
-     *
-     * TODO test should be improved: it is very dependent on the current number of contacts in the adb
      */
     public function testMergeDuplicateTags()
     {
-        if (Tinebase_User::getConfiguredBackend() === Tinebase_User::ACTIVEDIRECTORY) {
-            $this->markTestSkipped('AD setup has different number of contacts');
-        }
-
         $sharedTag1 = $this->_createSharedTag();
         // sleep to make sure, $sharedTag1 is always chosen as 'master'
         sleep(1);
         $sharedTag2 = $this->_createSharedTag();
         
-        $contactIds = Addressbook_Controller_Contact::getInstance()->getAll()->getArrayOfIds();
+        $contactIds = Addressbook_Controller_Contact::getInstance()->search(
+            new Addressbook_Model_ContactFilter(),
+            new Tinebase_Model_Pagination(array(
+                'limit' => 6
+            )))->getArrayOfIds();
+
+        // attach to first 3 contacts
         $contactFilter = new Addressbook_Model_ContactFilter(array(
             array('field' => 'id', 'operator' => 'in', 'value' => array_slice($contactIds, 0, 3))
         ));
         $sharedTag1 = Tinebase_Tags::getInstance()->attachTagToMultipleRecords($contactFilter, $sharedTag1);
-        $this->assertEquals(3, $sharedTag1->occurrence);
+        self::assertEquals(3, $sharedTag1->occurrence);
 
+        // attach to next 3 contacts
         $contactFilter = new Addressbook_Model_ContactFilter(array(
             array('field' => 'id', 'operator' => 'in', 'value' => array_slice($contactIds, 3, 3))
         ));
@@ -280,7 +281,7 @@ class Tinebase_TagsTest extends TestCase
         $this->_instance->mergeDuplicateSharedTags('Addressbook_Model_Contact');
         
         $sharedTag1AfterMerge = $this->_instance->get($sharedTag1);
-        $this->assertEquals($sharedTag1->occurrence + 3, $sharedTag1AfterMerge->occurrence,
+        self::assertEquals($sharedTag1->occurrence + 3, $sharedTag1AfterMerge->occurrence,
             'occurrence should have been increased by three: ' . print_r($sharedTag1AfterMerge->toArray(), TRUE));
         $this->setExpectedException('Tinebase_Exception_NotFound');
         $this->_instance->get($sharedTag2);
index 11773c9..751c15f 100644 (file)
@@ -148,7 +148,9 @@ class Addressbook_Controller_Contact extends Tinebase_Controller_Record_Abstract
     */
     protected function _addDefaultFilter(Tinebase_Model_Filter_FilterGroup $_filter = NULL)
     {
-        if (! $_filter->isFilterSet('showDisabled')) {
+        // look into subfilters
+        // TODO only allow admins to see hidden/disabled users?
+        if (! $_filter->isFilterSet('showDisabled', /* recursive */ true)) {
             $disabledFilter = $_filter->createFilter('showDisabled', 'equals', FALSE);
             $disabledFilter->setIsImplicit(TRUE);
             $_filter->addFilter($disabledFilter);
index 8f633cd..5ef942e 100644 (file)
@@ -431,10 +431,11 @@ class Admin_Controller_User extends Tinebase_Controller_Abstract
     /**
      * create or update contact in addressbook backend
      * 
-     * @param  Tinebase_Model_FullUser $_user
+     * @param Tinebase_Model_FullUser $_user
+     * @param boolean $_setModlog
      * @return Addressbook_Model_Contact
      */
-    public function createOrUpdateContact(Tinebase_Model_FullUser $_user)
+    public function createOrUpdateContact(Tinebase_Model_FullUser $_user, $_setModlog = true)
     {
         $contactsBackend = Addressbook_Backend_Factory::factory(Addressbook_Backend_Factory::SQL);
         $contactsBackend->setGetDisabledContacts(true);
@@ -461,9 +462,10 @@ class Admin_Controller_User extends Tinebase_Controller_Abstract
             $contact->container_id = $_user->container_id;
 
             unset($contact->jpegphoto);
-            
-            // add modlog info
-            Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'update');
+
+            if ($_setModlog) {
+                Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'update');
+            }
             
             $contact = $contactsBackend->update($contact);
             
@@ -478,9 +480,10 @@ class Admin_Controller_User extends Tinebase_Controller_Abstract
                 'type'          => Addressbook_Model_Contact::CONTACTTYPE_USER,
                 'container_id'  => $_user->container_id
             ));
-            
-            // add modlog info
-            Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'create');
+
+            if ($_setModlog) {
+                Tinebase_Timemachine_ModificationLog::setRecordMetaData($contact, 'create');
+            }
     
             $contact = $contactsBackend->create($contact);
         }
index ff842ac..6852252 100644 (file)
@@ -788,22 +788,24 @@ class Tinebase_Model_Filter_FilterGroup implements Iterator
      * returns true if filter for a field is set in this group
      *
      * @param string $_field
+     * @param boolean $_recursive
      * @return bool
      */
-    public function isFilterSet($_field)
+    public function isFilterSet($_field, $_recursive = false)
     {
-        $result = FALSE;
-        
         foreach ($this->_filterObjects as $object) {
             if ($object instanceof Tinebase_Model_Filter_Abstract) {
                 if ($object->getField() == $_field) {
-                    $result = TRUE;
-                    break;
+                    return true;
+                }
+            } elseif ($_recursive && $object instanceof Tinebase_Model_Filter_FilterGroup) {
+                if ($object->isFilterSet($_field, $_recursive)) {
+                    return true;
                 }
             }
         }
         
-        return $result;
+        return false;
     }
     
     /**
index b1a4db6..db5d6ea 100644 (file)
@@ -157,7 +157,7 @@ class Tinebase_Server_Json extends Tinebase_Server_Abstract implements Tinebase_
                 }
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
-                . ' is JSON request. rawdata: ' . print_r($_requests, true));
+                . ' is JSON request. rawdata: ' . var_export($_requests, true));
         } 
         
         $response = array();
index 9f5b02c..18a72d0 100644 (file)
@@ -1027,6 +1027,11 @@ class Tinebase_User implements Tinebase_Controller_Interface
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ .
             ' Creating new system user ' . print_r($systemUser->toArray(), true));
 
+        if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
+            $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($systemUser, /* setModlog */ false);
+            $systemUser->contact_id = $contact->getId();
+        }
+
         try {
             $systemUser = Tinebase_User::getInstance()->addUser($systemUser);
             Tinebase_Group::getInstance()->addGroupMember($systemUser->accountPrimaryGroup, $systemUser->getId());