diff --git a/src/Glpi/Search/SearchOption.php b/src/Glpi/Search/SearchOption.php index 27c39d18c2d..558ba934cb6 100644 --- a/src/Glpi/Search/SearchOption.php +++ b/src/Glpi/Search/SearchOption.php @@ -253,6 +253,19 @@ public static function getOptionsForItemtype($itemtype, $withplugins = true): ar $search[$itemtype][71]['table'] = 'glpi_groups'; $search[$itemtype][71]['field'] = 'completename'; $search[$itemtype][71]['name'] = Group::getTypeName(1); + $search[$itemtype][71]['condition'] = ['is_itemgroup' => 1]; + $search[$itemtype][71]['joinparams'] = [ + 'beforejoin' => [ + 'table' => 'glpi_groups_items', + 'joinparams' => [ + 'jointype' => 'itemtype_item', + 'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_NORMAL], + ], + ], + ]; + $search[$itemtype][71]['forcegroupby'] = true; + $search[$itemtype][71]['massiveaction'] = false; + $search[$itemtype][71]['datatype'] = 'dropdown'; $search[$itemtype][19]['table'] = 'asset_types'; $search[$itemtype][19]['field'] = 'date_mod'; diff --git a/tests/functional/Glpi/Search/SearchOptionTest.php b/tests/functional/Glpi/Search/SearchOptionTest.php index 7c0ed88f171..ad229f1bada 100644 --- a/tests/functional/Glpi/Search/SearchOptionTest.php +++ b/tests/functional/Glpi/Search/SearchOptionTest.php @@ -161,4 +161,83 @@ public function testAllAssetsGroupInChargeSearchResults(): void // If we reach this point, the SQL was successful $this->assertTrue(true, 'Search completed without SQL error - fix is working'); } + + public function testAllAssetsGroupSearchResults(): void + { + $this->login(); + + $group = $this->createItem( + \Group::class, + [ + 'name' => 'Test Normal Group ' . __FUNCTION__, + 'is_itemgroup' => 1, + 'entities_id' => $this->getTestRootEntity(true), + ] + ); + + $computer = $this->createItem( + \Computer::class, + [ + 'name' => 'Test Computer ' . __FUNCTION__, + 'entities_id' => $this->getTestRootEntity(true), + ] + ); + + $this->createItem( + \Group_Item::class, + [ + 'groups_id' => $group->getID(), + 'itemtype' => \Computer::class, + 'items_id' => $computer->getID(), + 'type' => \Group_Item::GROUP_TYPE_NORMAL, + ] + ); + + $result = \Search::getDatas( + \AllAssets::class, + [ + 'criteria' => [ + [ + 'field' => 71, + 'searchtype' => 'equals', + 'value' => $group->getID(), + ], + ], + 'forcetoview' => [1, 71], + ] + ); + + $this->assertArrayHasKey('data', $result); + $this->assertArrayHasKey('rows', $result['data']); + $this->assertEquals(1, $result['data']['totalcount'], '1 pc found'); + + $row = $result['data']['rows'][0]; + + $this->assertArrayHasKey('AllAssets_1', $row); + $this->assertStringContainsString('Test Computer ' . __FUNCTION__, $row['AllAssets_1']['displayname']); + + $this->assertArrayHasKey('AllAssets_71', $row); + $this->assertStringContainsString( + 'Test Normal Group ' . __FUNCTION__, + $row['AllAssets_71']['displayname'] + ); + + $result2 = \Search::getDatas( + \AllAssets::class, + [ + 'criteria' => [ + [ + 'field' => 71, + 'searchtype' => 'contains', + 'value' => 'Test Normal Group ' . __FUNCTION__, + ], + ], + 'forcetoview' => [1, 71], + ] + ); + + $this->assertArrayHasKey('data', $result2); + $this->assertArrayHasKey('rows', $result2['data']); + $this->assertGreaterThan(0, $result2['data']['totalcount']); + } }