Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Tinebase/TreeNode): did not load persistentFilters if TreeNodePat…
Browse files Browse the repository at this point in the history
…hFilter is broken

... we now catch "user not found" exceptions in PathFilter
  • Loading branch information
Christian Feitl authored and pschuele committed Mar 20, 2023
1 parent 761dbbf commit 159884c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
34 changes: 32 additions & 2 deletions tests/tine20/Tinebase/Frontend/JsonTest.php
Expand Up @@ -775,8 +775,6 @@ protected function _assertImportExportDefinitions($registryData)
*/
public function testGetAllPersistentFilters()
{
$this->markTestSkipped('@see 0010192: fix persistent filter tests');

$registryData = $this->_instance->getAllRegistryData();

$filterData = $registryData['Tinebase']['persistentFilters'];
Expand All @@ -788,6 +786,38 @@ public function testGetAllPersistentFilters()
// check if accounts are resolved
$this->assertTrue(is_array($grants[0]['account_name']), 'account should be resolved: ' . print_r($grants[0], true));
}

public function testGetAllPersistentFiltersAfterRenameUser() {

$userToCreate = TestCase::getTestUser([
'accountLoginName' => 'phpunitadminjson',
'accountEmailAddress' => 'phpunitadminjson@' . TestServer::getPrimaryMailDomain(),
]);
$userToCreate->smtpUser = new Tinebase_Model_EmailUser(array(
'emailAddress' => $userToCreate->accountEmailAddress,
));
$pw = Tinebase_Record_Abstract::generateUID(12);
$user = Admin_Controller_User::getInstance()->create($userToCreate, $pw, $pw);

$filter = new Tinebase_Model_PersistentFilter([
'name' => 'PHPUnit testFilter',
'description' => 'a test filter created by PHPUnit',
'account_id' => null,
'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Filemanager')->getId(),
'model' => 'Filemanager_Model_NodeFilter',
'filters' => [
['field' => 'path', 'operator' => 'equals', 'value' => '/personal/phpunitadminjson/']
]]);
$newFilter = Tinebase_PersistentFilter::getInstance()->create($filter);

$user['accountLoginName'] = 'phpunitadminjsonTest';
Admin_Controller_User::getInstance()->update($user);

$registryData = $this->_instance->getAllRegistryData();

$filterData = $registryData['Tinebase']['persistentFilters'];
self::assertNotEmpty($filterData, 'persistent filters can not loaded in the store');
}

/**
* testGetUserProfile
Expand Down
14 changes: 12 additions & 2 deletions tine20/Tinebase/Model/Tree/Node/PathFilter.php
Expand Up @@ -67,15 +67,23 @@ public function setValue($_value)
/**
* returns array with the filter settings of this filter
*
* @param bool $_valueToJson resolve value for json api?
* @param bool $_valueToJson resolve value for json api?
* @return array
* @throws Tinebase_Exception_Record_DefinitionFailure
* @throws Tinebase_Exception_Record_Validation
*/
public function toArray($_valueToJson = false)
{
$result = parent::toArray($_valueToJson);

if (! $this->_path && '/' !== $this->_value) {
$this->_path = Tinebase_Model_Tree_Node_Path::createFromPath($this->_value);
try {
$this->_path = Tinebase_Model_Tree_Node_Path::createFromPath($this->_value);
} catch (Tinebase_Exception_NotFound $tenf) {
if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
. ' ' . $tenf->getMessage());
return $result;
}
}

if ('/' === $this->_value || $this->_path->containerType === Tinebase_Model_Tree_Node_Path::TYPE_ROOT) {
Expand Down Expand Up @@ -105,6 +113,8 @@ public function toArray($_valueToJson = false)
$result['value']['path'] = $nodePath;
}
} catch (Exception $e) {
if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
. ' ' . $e->getMessage());
$result['value'] = $node->toArray();
}

Expand Down
2 changes: 1 addition & 1 deletion tine20/Tinebase/Record/RecordSet.php
Expand Up @@ -242,7 +242,7 @@ public function getValidationErrors()
public function toArray()
{
$resultArray = array();
foreach($this->_listOfRecords as $index => $record) {
foreach ($this->_listOfRecords as $index => $record) {
$resultArray[$index] = $record->toArray();
}

Expand Down

0 comments on commit 159884c

Please sign in to comment.