Fix system tag filter AND condition

If one of the results is empty, no need to do array_intersect and return
an empty result directly.
This commit is contained in:
Vincent Petry 2016-02-09 11:39:22 +01:00
parent d11179a0f5
commit 3028684d89
2 changed files with 27 additions and 0 deletions

View file

@ -239,6 +239,11 @@ class FilesReportPlugin extends ServerPlugin {
foreach ($systemTagIds as $systemTagId) { foreach ($systemTagIds as $systemTagId) {
$fileIds = $this->tagMapper->getObjectIdsForTags($systemTagId, 'files'); $fileIds = $this->tagMapper->getObjectIdsForTags($systemTagId, 'files');
if (empty($fileIds)) {
return [];
}
// first run ?
if (empty($resultFileIds)) { if (empty($resultFileIds)) {
$resultFileIds = $fileIds; $resultFileIds = $fileIds;
} else { } else {

View file

@ -395,6 +395,28 @@ class FilesReportPlugin extends \Test\TestCase {
$this->assertEquals(['222'], array_values($this->plugin->processFilterRules($rules))); $this->assertEquals(['222'], array_values($this->plugin->processFilterRules($rules)));
} }
public function testProcessFilterRulesAndConditionWithOneEmptyResult() {
$this->groupManager->expects($this->any())
->method('isAdmin')
->will($this->returnValue(true));
$this->tagMapper->expects($this->at(0))
->method('getObjectIdsForTags')
->with('123')
->will($this->returnValue(['111', '222']));
$this->tagMapper->expects($this->at(1))
->method('getObjectIdsForTags')
->with('456')
->will($this->returnValue([]));
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
$this->assertEquals([], array_values($this->plugin->processFilterRules($rules)));
}
public function testProcessFilterRulesInvisibleTagAsAdmin() { public function testProcessFilterRulesInvisibleTagAsAdmin() {
$this->groupManager->expects($this->any()) $this->groupManager->expects($this->any())
->method('isAdmin') ->method('isAdmin')