From 479a51b554f4193322847b7a61d24bc35f78ca13 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Wed, 16 Sep 2026 09:02:03 +0200 Subject: [PATCH 01/27] Fix TreeView support for GLPI 11 Custom Assets Add support for GLPI 11 Custom Assets in TreeView. - Discover Custom Asset classes through AssetDefinitionManager - Filter the shared assets table by asset definition - Use Custom Asset search and form URLs Related to #108 --- inc/config.class.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index da447ff..d4ec255 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -128,6 +128,13 @@ public static function getTypes($all = false) // Only allowed types $types = self::$types; + if (class_exists(\Glpi\Asset\AssetDefinitionManager::class)) { + $types = array_merge( + $types, + \Glpi\Asset\AssetDefinitionManager::getInstance()->getCustomObjectClassNames() + ); + } + foreach ($types as $key => $type) { if (!class_exists($type) || !is_a($type, CommonDBTM::class, true)) { continue; @@ -336,6 +343,10 @@ public function getNodesFromDb() 'ORDER' => [$itemtable . '.name'], ]; + if (is_a($type, \Glpi\Asset\Asset::class, true)) { + $criteria['WHERE']['assets_assetdefinitions_id'] = $type::getDefinition()->fields['id']; + } + if ($item->maybeTemplate()) { $criteria['WHERE']['is_template'] = 0; } @@ -368,7 +379,9 @@ public function getNodesFromDb() $token = Session::getNewCSRFToken(); $getParam = sprintf('?is_deleted=0&criteria[0][field]=%d&criteria[0][searchtype]=equals&criteria[0][value]=%s&search=Rechercher&start=0&_glpi_csrf_token=%s', $field_num, $value, $token); - $searchUrl = Toolbox::getItemTypeSearchURL($type) . $getParam; + $searchUrl = is_a($type, \Glpi\Asset\Asset::class, true) + ? $type::getSearchURL() . '&' . ltrim($getParam, '?') + : Toolbox::getItemTypeSearchURL($type) . $getParam; $params = ['itemtype' => $type, 'locations_id' => $value, @@ -414,7 +427,11 @@ public function getNodesFromDb() } } - $url = Toolbox::getItemTypeFormURL($type) . '?id=' . $r_1['id']; + if (is_a($type, \Glpi\Asset\Asset::class, true)) { + $url = $type::getFormURL() . '&id=' . $r_1['id']; + } else { + $url = Toolbox::getItemTypeFormURL($type) . '?id=' . $r_1['id']; + } $pic = 'ti ti-chevrons-right'; $name = strtr($i_name, $trans); $opt = ['url' => $url, From fcc55e95af1898d49e0e4b638448a262f5a9097a Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 14:07:29 +0200 Subject: [PATCH 02/27] Add regression test for custom asset definitions --- tests/Units/ConfigTest.php | 59 +++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 8046f79..d10ac1c 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -9,14 +9,14 @@ * * This file is part of TreeView. * - * TreeView is free software; you can redistribute it and/or modify + * TreeView is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TreeView is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License @@ -98,7 +98,12 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void ]); // remove all rights to view computers - $this->removeRightFromProfile('Super-Admin', Computer::$rightname, READ + READ_ASSIGNED + READ_OWNED); + $this->removeRightFromProfile( + 'Super-Admin', + Computer::$rightname, + READ + READ_ASSIGNED + READ_OWNED + ); + try { $this->login('glpi'); $this->setEntity($entity_id, false); @@ -106,7 +111,53 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void $this->assertStringNotContainsString($computer->fields['name'], $output); } finally { - $this->addRightToProfile('Super-Admin', Computer::$rightname, READ + READ_ASSIGNED + READ_OWNED); + $this->addRightToProfile( + 'Super-Admin', + Computer::$rightname, + READ + READ_ASSIGNED + READ_OWNED + ); } } + + public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void + { + $this->login(); + $entity_id = $this->getTestRootEntity(true); + + $location = $this->createItem(Location::class, [ + 'name' => 'treeview_asset_loc_' . $this->getUniqueString(), + 'entities_id' => $entity_id, + ]); + + $definition_a = $this->initAssetDefinition( + 'treeview_a_' . $this->getUniqueString() + ); + $definition_b = $this->initAssetDefinition( + 'treeview_b_' . $this->getUniqueString() + ); + + $asset_a = $this->createItem($definition_a->getAssetClassName(), [ + 'name' => 'treeview_asset_a_' . $this->getUniqueString(), + 'entities_id' => $entity_id, + 'locations_id' => $location->getID(), + ]); + $asset_b = $this->createItem($definition_b->getAssetClassName(), [ + 'name' => 'treeview_asset_b_' . $this->getUniqueString(), + 'entities_id' => $entity_id, + 'locations_id' => $location->getID(), + ]); + + $this->setEntity($entity_id, false); + + $output = $this->getTreeOutput($location->getID()); + + $this->assertSame( + 1, + substr_count($output, $asset_a->fields['name']) + ); + $this->assertSame( + 1, + substr_count($output, $asset_b->fields['name']) + ); + } } From 08d1268b98747923c2a854f5490e066a8b0c074c Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 14:21:07 +0200 Subject: [PATCH 03/27] Update CHANGELOG for custom asset filtering --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d834ef4..e844466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Fixed + +- Prevent custom assets from other asset definitions from appearing in the same location + ## [1.20.3] - 2026-09-04 ### Fixed From 0bd044f431cd4511d0635c080e51d59a8ffead75 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:33:40 +0200 Subject: [PATCH 04/27] Apply Rector namespace imports in config class --- inc/config.class.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index d4ec255..39cae2e 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -28,6 +28,8 @@ * ------------------------------------------------------------------------- */ use Glpi\Application\View\TemplateRenderer; +use Glpi\Asset\Asset; +use Glpi\Asset\AssetDefinitionManager; use Glpi\DBAL\QueryExpression; use function Safe\json_encode; @@ -128,10 +130,10 @@ public static function getTypes($all = false) // Only allowed types $types = self::$types; - if (class_exists(\Glpi\Asset\AssetDefinitionManager::class)) { + if (class_exists(AssetDefinitionManager::class)) { $types = array_merge( $types, - \Glpi\Asset\AssetDefinitionManager::getInstance()->getCustomObjectClassNames() + AssetDefinitionManager::getInstance()->getCustomObjectClassNames() ); } @@ -343,7 +345,7 @@ public function getNodesFromDb() 'ORDER' => [$itemtable . '.name'], ]; - if (is_a($type, \Glpi\Asset\Asset::class, true)) { + if (is_a($type, Asset::class, true)) { $criteria['WHERE']['assets_assetdefinitions_id'] = $type::getDefinition()->fields['id']; } @@ -379,7 +381,7 @@ public function getNodesFromDb() $token = Session::getNewCSRFToken(); $getParam = sprintf('?is_deleted=0&criteria[0][field]=%d&criteria[0][searchtype]=equals&criteria[0][value]=%s&search=Rechercher&start=0&_glpi_csrf_token=%s', $field_num, $value, $token); - $searchUrl = is_a($type, \Glpi\Asset\Asset::class, true) + $searchUrl = is_a($type, Asset::class, true) ? $type::getSearchURL() . '&' . ltrim($getParam, '?') : Toolbox::getItemTypeSearchURL($type) . $getParam; @@ -427,12 +429,13 @@ public function getNodesFromDb() } } - if (is_a($type, \Glpi\Asset\Asset::class, true)) { + if (is_a($type, Asset::class, true)) { $url = $type::getFormURL() . '&id=' . $r_1['id']; } else { $url = Toolbox::getItemTypeFormURL($type) . '?id=' . $r_1['id']; } - $pic = 'ti ti-chevrons-right'; + + $pic = 'ti ti-chevrons-right $name = strtr($i_name, $trans); $opt = ['url' => $url, 'pic' => $pic, From 64c6499becc21119baf2044ae9dcd1a6ef3c8eb6 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:38:40 +0200 Subject: [PATCH 05/27] Fix asset definition visibility in regression test --- tests/Units/ConfigTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index d10ac1c..e315010 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -135,7 +135,11 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $definition_b = $this->initAssetDefinition( 'treeview_b_' . $this->getUniqueString() ); - + + $profile_id = Session::getProfileID(); + $definition_a->setProfileRights($profile_id, READ); + $definition_b->setProfileRights($profile_id, READ); + $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, From ae76d5d2c91fa312e51c69d5c8e2be5286629aef Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:41:09 +0200 Subject: [PATCH 06/27] Fix license header in ConfigTest --- tests/Units/ConfigTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index e315010..9eae9cf 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -16,7 +16,7 @@ * * TreeView is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License From 047ad2c7b74bc08cb7478bcfd65202590d6c2397 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:47:56 +0200 Subject: [PATCH 07/27] Fix syntax error in config class --- inc/config.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/config.class.php b/inc/config.class.php index 39cae2e..7548ad5 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -435,7 +435,7 @@ public function getNodesFromDb() $url = Toolbox::getItemTypeFormURL($type) . '?id=' . $r_1['id']; } - $pic = 'ti ti-chevrons-right + $pic = 'ti ti-chevrons-right'; $name = strtr($i_name, $trans); $opt = ['url' => $url, 'pic' => $pic, From c2649ae46cbe0f663c6ab39abbcf2a6cc48e2379 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:56:30 +0200 Subject: [PATCH 08/27] Fix custom asset URLs in TreeView --- inc/config.class.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index 7548ad5..f71342a 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -54,10 +54,10 @@ class PluginTreeviewConfig extends CommonDBTM ]; /** - * Display name of itemtype - * - * @return string - **/ + * Display name of itemtype + * + * @return string + **/ public static function getTypeName($nb = 0) { return __s('Tree view', 'treeview'); @@ -429,12 +429,8 @@ public function getNodesFromDb() } } - if (is_a($type, Asset::class, true)) { - $url = $type::getFormURL() . '&id=' . $r_1['id']; - } else { - $url = Toolbox::getItemTypeFormURL($type) . '?id=' . $r_1['id']; - } - + $url = $type::getFormURLWithID($r_1['id']); + $pic = 'ti ti-chevrons-right'; $name = strtr($i_name, $trans); $opt = ['url' => $url, From c8eb6f6dfe0de2e4c125c4f71b0bd4afb9b0df46 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:57:59 +0200 Subject: [PATCH 09/27] Update changelog for custom assets support --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e844466..6bb2bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Display GLPI 11 Custom Assets in the location tree + ### Fixed - Prevent custom assets from other asset definitions from appearing in the same location From 781601cc7d7da196dcc662684f6d60268289a779 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Wed, 30 Sep 2026 15:29:00 +0200 Subject: [PATCH 10/27] Fix regression test profile access --- tests/Units/ConfigTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 9eae9cf..471c0d4 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -136,7 +136,7 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'treeview_b_' . $this->getUniqueString() ); - $profile_id = Session::getProfileID(); + $profile_id = Session::getCurrentProfile()->getID(); $definition_a->setProfileRights($profile_id, READ); $definition_b->setProfileRights($profile_id, READ); From 0c0edf38f1b6b7152d598795d748f4fbc599b304 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:40:59 +0200 Subject: [PATCH 11/27] test: diagnose custom asset visibility --- tests/Units/ConfigTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 471c0d4..56e8fa0 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -139,6 +139,30 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $profile_id = Session::getCurrentProfile()->getID(); $definition_a->setProfileRights($profile_id, READ); $definition_b->setProfileRights($profile_id, READ); + + $this->assertTrue( + $definition_a->getAssetClassName()::canView(), + 'AssetDefinition A should be visible' + ); + + $this->assertTrue( + $definition_b->getAssetClassName()::canView(), + 'AssetDefinition B should be visible' + ); + + $types = PluginTreeviewConfig::getTypes(); + + $this->assertContains( + $definition_a->getAssetClassName(), + $types, + 'AssetDefinition A should be available in TreeView types' + ); + + $this->assertContains( + $definition_b->getAssetClassName(), + $types, + 'AssetDefinition B should be available in TreeView types' + ); $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), From eaf64ed17dbd87965fa66fafccff0c23136e4e43 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:53:42 +0200 Subject: [PATCH 12/27] Fix custom asset regression test --- tests/Units/ConfigTest.php | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 56e8fa0..3802a8d 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -32,6 +32,7 @@ use Computer; use Entity; +use Glpi\Asset\AssetDefinitionManager; use GlpiPlugin\Treeview\Tests\TreeviewTestCase; use Location; use Session; @@ -135,35 +136,11 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $definition_b = $this->initAssetDefinition( 'treeview_b_' . $this->getUniqueString() ); - + $profile_id = Session::getCurrentProfile()->getID(); $definition_a->setProfileRights($profile_id, READ); $definition_b->setProfileRights($profile_id, READ); - $this->assertTrue( - $definition_a->getAssetClassName()::canView(), - 'AssetDefinition A should be visible' - ); - - $this->assertTrue( - $definition_b->getAssetClassName()::canView(), - 'AssetDefinition B should be visible' - ); - - $types = PluginTreeviewConfig::getTypes(); - - $this->assertContains( - $definition_a->getAssetClassName(), - $types, - 'AssetDefinition A should be available in TreeView types' - ); - - $this->assertContains( - $definition_b->getAssetClassName(), - $types, - 'AssetDefinition B should be available in TreeView types' - ); - $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -175,6 +152,12 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); + // The definition manager caches definitions during the GLPI test + // bootstrap. Refresh it after creating the test definitions so that + // TreeView sees both custom asset classes. + AssetDefinitionManager::getInstance()->clearDefinitionsCache(); + AssetDefinitionManager::getInstance()->bootDefinitions(); + $this->setEntity($entity_id, false); $output = $this->getTreeOutput($location->getID()); From 6d3777fb314e0f67362a97c5aa06cb37474672cf Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Thu, 1 Oct 2026 09:18:03 +0200 Subject: [PATCH 13/27] Remove obsolete AssetDefinitionManager guard --- inc/config.class.php | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index f71342a..1904bbb 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -127,30 +127,27 @@ public static function getTypes($all = false) return self::$types; } - // Only allowed types - $types = self::$types; - - if (class_exists(AssetDefinitionManager::class)) { - $types = array_merge( - $types, - AssetDefinitionManager::getInstance()->getCustomObjectClassNames() - ); + // Only allowed types + $types = self::$types; + + $types = array_merge( + $types, + AssetDefinitionManager::getInstance()->getCustomObjectClassNames() + ); + + foreach ($types as $key => $type) { + if (!class_exists($type) || !is_a($type, CommonDBTM::class, true)) { + continue; } - - foreach ($types as $key => $type) { - if (!class_exists($type) || !is_a($type, CommonDBTM::class, true)) { - continue; - } - - $item = new $type(); - if (!$item->canView()) { - unset($types[$key]); - } + + $item = new $type(); + if (!$item->canView()) { + unset($types[$key]); } - - return $types; } +return $types; + /** * The function to see the treeview **/ From 8af8975345543482a608b0b69247ce05c3c2c08b Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Thu, 1 Oct 2026 09:34:06 +0200 Subject: [PATCH 14/27] Fix AssetDefinition functional test and code style --- tests/Units/ConfigTest.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 3802a8d..eea4cc6 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -11,7 +11,7 @@ * * TreeView is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * TreeView is distributed in the hope that it will be useful, @@ -35,7 +35,6 @@ use Glpi\Asset\AssetDefinitionManager; use GlpiPlugin\Treeview\Tests\TreeviewTestCase; use Location; -use Session; final class ConfigTest extends TreeviewTestCase { @@ -98,7 +97,7 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void 'locations_id' => $location->getID(), ]); - // remove all rights to view computers + // Remove all rights to view computers. $this->removeRightFromProfile( 'Super-Admin', Computer::$rightname, @@ -137,10 +136,6 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'treeview_b_' . $this->getUniqueString() ); - $profile_id = Session::getCurrentProfile()->getID(); - $definition_a->setProfileRights($profile_id, READ); - $definition_b->setProfileRights($profile_id, READ); - $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -152,16 +147,20 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); - // The definition manager caches definitions during the GLPI test - // bootstrap. Refresh it after creating the test definitions so that - // TreeView sees both custom asset classes. - AssetDefinitionManager::getInstance()->clearDefinitionsCache(); - AssetDefinitionManager::getInstance()->bootDefinitions(); + // Refresh the definition manager so that the newly created + // definitions are available to TreeView. + $manager = AssetDefinitionManager::getInstance(); + $manager->clearDefinitionsCache(); + $manager->bootDefinitions(); $this->setEntity($entity_id, false); $output = $this->getTreeOutput($location->getID()); + // Both assets share the same database table. Each asset must only + // appear in the tree group corresponding to its own definition. + // Without the assets_assetdefinitions_id filter, each asset would + // appear twice. $this->assertSame( 1, substr_count($output, $asset_a->fields['name']) From 3be225c25ba19bd5c62173ba0bf6ffd53315c623 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Thu, 1 Oct 2026 09:36:38 +0200 Subject: [PATCH 15/27] Fix TreeView GLPI 11 code style --- inc/config.class.php | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index 1904bbb..6f18ce1 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -9,9 +9,9 @@ * * This file is part of TreeView. * - * TreeView is free software; you can redistribute it and/or modify + * TreeView is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * TreeView is distributed in the hope that it will be useful, @@ -27,6 +27,7 @@ * @link https://github.com/pluginsGLPI/treeview * ------------------------------------------------------------------------- */ + use Glpi\Application\View\TemplateRenderer; use Glpi\Asset\Asset; use Glpi\Asset\AssetDefinitionManager; @@ -36,7 +37,7 @@ /** * Contains the display configuration of the treeview -**/ + **/ class PluginTreeviewConfig extends CommonDBTM { public static $types = [ @@ -127,26 +128,27 @@ public static function getTypes($all = false) return self::$types; } - // Only allowed types - $types = self::$types; - - $types = array_merge( - $types, - AssetDefinitionManager::getInstance()->getCustomObjectClassNames() - ); - - foreach ($types as $key => $type) { - if (!class_exists($type) || !is_a($type, CommonDBTM::class, true)) { - continue; - } - - $item = new $type(); - if (!$item->canView()) { - unset($types[$key]); + // Only allowed types + $types = self::$types; + + $types = array_merge( + $types, + AssetDefinitionManager::getInstance()->getCustomObjectClassNames() + ); + + foreach ($types as $key => $type) { + if (!class_exists($type) || !is_a($type, CommonDBTM::class, true)) { + continue; + } + + $item = new $type(); + if (!$item->canView()) { + unset($types[$key]); + } } - } -return $types; + return $types; + } /** * The function to see the treeview From 0c09515c5cbd6feab63054483c5ce2db5cb96eaf Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Thu, 1 Oct 2026 09:44:02 +0200 Subject: [PATCH 16/27] Fix custom asset functional test and code style --- tests/Units/ConfigTest.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index eea4cc6..e8e07fb 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -1,5 +1,4 @@ getUniqueString() ); + $profile_id = Session::getCurrentProfile()->getID(); + $definition_a->setProfileRights($profile_id, READ); + $definition_b->setProfileRights($profile_id, READ); + $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -147,8 +150,6 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); - // Refresh the definition manager so that the newly created - // definitions are available to TreeView. $manager = AssetDefinitionManager::getInstance(); $manager->clearDefinitionsCache(); $manager->bootDefinitions(); @@ -157,10 +158,6 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $output = $this->getTreeOutput($location->getID()); - // Both assets share the same database table. Each asset must only - // appear in the tree group corresponding to its own definition. - // Without the assets_assetdefinitions_id filter, each asset would - // appear twice. $this->assertSame( 1, substr_count($output, $asset_a->fields['name']) From 83a26b4fbb41b8bfdd912269bf1d88e1c658ae09 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 13:58:39 +0200 Subject: [PATCH 17/27] Fix custom asset test session and code style --- tests/Units/ConfigTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index e8e07fb..5b85395 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -138,6 +138,7 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $profile_id = Session::getCurrentProfile()->getID(); $definition_a->setProfileRights($profile_id, READ); $definition_b->setProfileRights($profile_id, READ); + Session::changeProfile($profile_id); $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), From 1fdd1ca7a15e281c8177f2ad88cdba69a72c14a6 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:11:56 +0200 Subject: [PATCH 18/27] Fix custom asset definition test setup --- tests/Units/ConfigTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 5b85395..ea02f48 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -138,6 +138,11 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $profile_id = Session::getCurrentProfile()->getID(); $definition_a->setProfileRights($profile_id, READ); $definition_b->setProfileRights($profile_id, READ); + + $manager = AssetDefinitionManager::getInstance(); + $manager->clearDefinitionsCache(); + $manager->bootDefinitions(); + Session::changeProfile($profile_id); $asset_a = $this->createItem($definition_a->getAssetClassName(), [ @@ -151,10 +156,6 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); - $manager = AssetDefinitionManager::getInstance(); - $manager->clearDefinitionsCache(); - $manager->bootDefinitions(); - $this->setEntity($entity_id, false); $output = $this->getTreeOutput($location->getID()); From 23e0a2ff6d8dff1369afba5dc6704c3ef6685833 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:19:46 +0200 Subject: [PATCH 19/27] Fix custom asset definition test --- tests/Units/ConfigTest.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index ea02f48..687a44a 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -33,7 +33,6 @@ use Glpi\Asset\AssetDefinitionManager; use GlpiPlugin\Treeview\Tests\TreeviewTestCase; use Location; -use Session; final class ConfigTest extends TreeviewTestCase { @@ -135,16 +134,6 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'treeview_b_' . $this->getUniqueString() ); - $profile_id = Session::getCurrentProfile()->getID(); - $definition_a->setProfileRights($profile_id, READ); - $definition_b->setProfileRights($profile_id, READ); - - $manager = AssetDefinitionManager::getInstance(); - $manager->clearDefinitionsCache(); - $manager->bootDefinitions(); - - Session::changeProfile($profile_id); - $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -156,6 +145,10 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); + $manager = AssetDefinitionManager::getInstance(); + $manager->clearDefinitionsCache(); + $manager->bootDefinitions(); + $this->setEntity($entity_id, false); $output = $this->getTreeOutput($location->getID()); From 1190e2828dfc14fa774e0296bf14af9fbc47de48 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:30:10 +0200 Subject: [PATCH 20/27] Fix custom asset visibility in functional test --- tests/Units/ConfigTest.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 687a44a..b021df4 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -26,6 +26,7 @@ * @link https://github.com/pluginsGLPI/treeview * ------------------------------------------------------------------------- */ + namespace GlpiPlugin\Treeview\Tests\Units; use Computer; @@ -33,6 +34,7 @@ use Glpi\Asset\AssetDefinitionManager; use GlpiPlugin\Treeview\Tests\TreeviewTestCase; use Location; +use Session; final class ConfigTest extends TreeviewTestCase { @@ -134,6 +136,18 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'treeview_b_' . $this->getUniqueString() ); + $profile_id = Session::getCurrentProfile()->getID(); + $definition_a->setProfileRights($profile_id, READ); + $definition_b->setProfileRights($profile_id, READ); + + $manager = AssetDefinitionManager::getInstance(); + $manager->clearDefinitionsCache(); + $manager->bootDefinitions(); + + // Reload the session so the rights of the custom asset definitions + // are available to canView(). + $this->login('glpi'); + $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -145,10 +159,6 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); - $manager = AssetDefinitionManager::getInstance(); - $manager->clearDefinitionsCache(); - $manager->bootDefinitions(); - $this->setEntity($entity_id, false); $output = $this->getTreeOutput($location->getID()); From 1828f5892c6125d2bd11e06d16313fa059768c77 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:37:29 +0200 Subject: [PATCH 21/27] Update ConfigTest.php --- tests/Units/ConfigTest.php | 46 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index b021df4..c23479d 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -144,9 +144,8 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $manager->clearDefinitionsCache(); $manager->bootDefinitions(); - // Reload the session so the rights of the custom asset definitions - // are available to canView(). $this->login('glpi'); + $this->setEntity($entity_id, false); $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), @@ -159,17 +158,40 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); - $this->setEntity($entity_id, false); + $original_types = PluginTreeviewConfig::$types; - $output = $this->getTreeOutput($location->getID()); + try { + PluginTreeviewConfig::$types = [ + $definition_a->getAssetClassName(), + ]; - $this->assertSame( - 1, - substr_count($output, $asset_a->fields['name']) - ); - $this->assertSame( - 1, - substr_count($output, $asset_b->fields['name']) - ); + $output_a = $this->getTreeOutput($location->getID()); + + $this->assertStringContainsString( + $asset_a->fields['name'], + $output_a + ); + $this->assertStringNotContainsString( + $asset_b->fields['name'], + $output_a + ); + + PluginTreeviewConfig::$types = [ + $definition_b->getAssetClassName(), + ]; + + $output_b = $this->getTreeOutput($location->getID()); + + $this->assertStringContainsString( + $asset_b->fields['name'], + $output_b + ); + $this->assertStringNotContainsString( + $asset_a->fields['name'], + $output_b + ); + } finally { + PluginTreeviewConfig::$types = $original_types; + } } } From aa88cf097e3b366a6764a79533adae9365bd4993 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:00:32 +0200 Subject: [PATCH 22/27] Update ConfigTest.php --- tests/Units/ConfigTest.php | 67 ++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index c23479d..c0d83f8 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -8,9 +8,9 @@ * * This file is part of TreeView. * - * TreeView is free software; you can redistribute it and/or modify + * TreeView is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * TreeView is distributed in the hope that it will be useful, @@ -41,12 +41,14 @@ final class ConfigTest extends TreeviewTestCase public function testGetNodesFromDbOnlyShowsActiveEntityData(): void { $this->login(); + $root_id = $this->getTestRootEntity(true); $entity_a = $this->createItem(Entity::class, [ 'name' => 'treeview_entity_a_' . $this->getUniqueString(), 'entities_id' => $root_id, ]); + $entity_b = $this->createItem(Entity::class, [ 'name' => 'treeview_entity_b_' . $this->getUniqueString(), 'entities_id' => $root_id, @@ -56,6 +58,7 @@ public function testGetNodesFromDbOnlyShowsActiveEntityData(): void 'name' => 'treeview_loc_a_' . $this->getUniqueString(), 'entities_id' => $entity_a->getID(), ]); + $location_b = $this->createItem(Location::class, [ 'name' => 'treeview_loc_b_' . $this->getUniqueString(), 'entities_id' => $entity_b->getID(), @@ -66,6 +69,7 @@ public function testGetNodesFromDbOnlyShowsActiveEntityData(): void 'entities_id' => $entity_a->getID(), 'locations_id' => $location_a->getID(), ]); + $computer_b = $this->createItem(Computer::class, [ 'name' => 'treeview_computer_b_' . $this->getUniqueString(), 'entities_id' => $entity_b->getID(), @@ -85,12 +89,14 @@ public function testGetNodesFromDbOnlyShowsActiveEntityData(): void public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void { $this->login(); + $entity_id = $this->getTestRootEntity(true); $location = $this->createItem(Location::class, [ 'name' => 'treeview_loc_' . $this->getUniqueString(), 'entities_id' => $entity_id, ]); + $computer = $this->createItem(Computer::class, [ 'name' => 'treeview_computer_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -107,9 +113,13 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void try { $this->login('glpi'); $this->setEntity($entity_id, false); + $output = $this->getTreeOutput($location->getID()); - $this->assertStringNotContainsString($computer->fields['name'], $output); + $this->assertStringNotContainsString( + $computer->fields['name'], + $output + ); } finally { $this->addRightToProfile( 'Super-Admin', @@ -121,7 +131,8 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void { - $this->login(); + $this->login('glpi'); + $entity_id = $this->getTestRootEntity(true); $location = $this->createItem(Location::class, [ @@ -132,11 +143,13 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $definition_a = $this->initAssetDefinition( 'treeview_a_' . $this->getUniqueString() ); + $definition_b = $this->initAssetDefinition( 'treeview_b_' . $this->getUniqueString() ); $profile_id = Session::getCurrentProfile()->getID(); + $definition_a->setProfileRights($profile_id, READ); $definition_b->setProfileRights($profile_id, READ); @@ -144,54 +157,30 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $manager->clearDefinitionsCache(); $manager->bootDefinitions(); - $this->login('glpi'); - $this->setEntity($entity_id, false); - $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, 'locations_id' => $location->getID(), ]); + $asset_b = $this->createItem($definition_b->getAssetClassName(), [ 'name' => 'treeview_asset_b_' . $this->getUniqueString(), 'entities_id' => $entity_id, 'locations_id' => $location->getID(), ]); - $original_types = PluginTreeviewConfig::$types; - - try { - PluginTreeviewConfig::$types = [ - $definition_a->getAssetClassName(), - ]; - - $output_a = $this->getTreeOutput($location->getID()); - - $this->assertStringContainsString( - $asset_a->fields['name'], - $output_a - ); - $this->assertStringNotContainsString( - $asset_b->fields['name'], - $output_a - ); + $this->setEntity($entity_id, false); - PluginTreeviewConfig::$types = [ - $definition_b->getAssetClassName(), - ]; + $output = $this->getTreeOutput($location->getID()); - $output_b = $this->getTreeOutput($location->getID()); + $this->assertSame( + 1, + substr_count($output, $asset_a->fields['name']) + ); - $this->assertStringContainsString( - $asset_b->fields['name'], - $output_b - ); - $this->assertStringNotContainsString( - $asset_a->fields['name'], - $output_b - ); - } finally { - PluginTreeviewConfig::$types = $original_types; - } + $this->assertSame( + 1, + substr_count($output, $asset_b->fields['name']) + ); } } From 11d207813d6bbb34844480fed401cd45bc5ba7aa Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:10:21 +0200 Subject: [PATCH 23/27] Update ConfigTest.php --- tests/Units/ConfigTest.php | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index c0d83f8..07352d1 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -10,7 +10,7 @@ * * TreeView is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or + * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TreeView is distributed in the hope that it will be useful, @@ -41,14 +41,12 @@ final class ConfigTest extends TreeviewTestCase public function testGetNodesFromDbOnlyShowsActiveEntityData(): void { $this->login(); - $root_id = $this->getTestRootEntity(true); $entity_a = $this->createItem(Entity::class, [ 'name' => 'treeview_entity_a_' . $this->getUniqueString(), 'entities_id' => $root_id, ]); - $entity_b = $this->createItem(Entity::class, [ 'name' => 'treeview_entity_b_' . $this->getUniqueString(), 'entities_id' => $root_id, @@ -58,7 +56,6 @@ public function testGetNodesFromDbOnlyShowsActiveEntityData(): void 'name' => 'treeview_loc_a_' . $this->getUniqueString(), 'entities_id' => $entity_a->getID(), ]); - $location_b = $this->createItem(Location::class, [ 'name' => 'treeview_loc_b_' . $this->getUniqueString(), 'entities_id' => $entity_b->getID(), @@ -69,7 +66,6 @@ public function testGetNodesFromDbOnlyShowsActiveEntityData(): void 'entities_id' => $entity_a->getID(), 'locations_id' => $location_a->getID(), ]); - $computer_b = $this->createItem(Computer::class, [ 'name' => 'treeview_computer_b_' . $this->getUniqueString(), 'entities_id' => $entity_b->getID(), @@ -89,14 +85,12 @@ public function testGetNodesFromDbOnlyShowsActiveEntityData(): void public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void { $this->login(); - $entity_id = $this->getTestRootEntity(true); $location = $this->createItem(Location::class, [ 'name' => 'treeview_loc_' . $this->getUniqueString(), 'entities_id' => $entity_id, ]); - $computer = $this->createItem(Computer::class, [ 'name' => 'treeview_computer_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -113,13 +107,9 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void try { $this->login('glpi'); $this->setEntity($entity_id, false); - $output = $this->getTreeOutput($location->getID()); - $this->assertStringNotContainsString( - $computer->fields['name'], - $output - ); + $this->assertStringNotContainsString($computer->fields['name'], $output); } finally { $this->addRightToProfile( 'Super-Admin', @@ -131,7 +121,7 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void { - $this->login('glpi'); + $this->login(); $entity_id = $this->getTestRootEntity(true); @@ -143,7 +133,6 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $definition_a = $this->initAssetDefinition( 'treeview_a_' . $this->getUniqueString() ); - $definition_b = $this->initAssetDefinition( 'treeview_b_' . $this->getUniqueString() ); @@ -157,6 +146,9 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $manager->clearDefinitionsCache(); $manager->bootDefinitions(); + $this->login('glpi'); + $this->setEntity($entity_id, false); + $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, @@ -169,15 +161,12 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'locations_id' => $location->getID(), ]); - $this->setEntity($entity_id, false); - $output = $this->getTreeOutput($location->getID()); $this->assertSame( 1, substr_count($output, $asset_a->fields['name']) ); - $this->assertSame( 1, substr_count($output, $asset_b->fields['name']) From afd18bcdb9bdb9469fccc484ce97f1496df7a9a5 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:14:42 +0200 Subject: [PATCH 24/27] Update ConfigTest.php --- tests/Units/ConfigTest.php | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index 07352d1..eea4cc6 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -1,4 +1,5 @@ login(); - $entity_id = $this->getTestRootEntity(true); $location = $this->createItem(Location::class, [ @@ -137,32 +136,31 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void 'treeview_b_' . $this->getUniqueString() ); - $profile_id = Session::getCurrentProfile()->getID(); - - $definition_a->setProfileRights($profile_id, READ); - $definition_b->setProfileRights($profile_id, READ); - - $manager = AssetDefinitionManager::getInstance(); - $manager->clearDefinitionsCache(); - $manager->bootDefinitions(); - - $this->login('glpi'); - $this->setEntity($entity_id, false); - $asset_a = $this->createItem($definition_a->getAssetClassName(), [ 'name' => 'treeview_asset_a_' . $this->getUniqueString(), 'entities_id' => $entity_id, 'locations_id' => $location->getID(), ]); - $asset_b = $this->createItem($definition_b->getAssetClassName(), [ 'name' => 'treeview_asset_b_' . $this->getUniqueString(), 'entities_id' => $entity_id, 'locations_id' => $location->getID(), ]); + // Refresh the definition manager so that the newly created + // definitions are available to TreeView. + $manager = AssetDefinitionManager::getInstance(); + $manager->clearDefinitionsCache(); + $manager->bootDefinitions(); + + $this->setEntity($entity_id, false); + $output = $this->getTreeOutput($location->getID()); + // Both assets share the same database table. Each asset must only + // appear in the tree group corresponding to its own definition. + // Without the assets_assetdefinitions_id filter, each asset would + // appear twice. $this->assertSame( 1, substr_count($output, $asset_a->fields['name']) From 16f42513f238a5eca1a016bbf4157afa8c4cfb10 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:39:21 +0200 Subject: [PATCH 25/27] Fix custom asset test permissions and CI checks. --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 8338bce..b59a610 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "glpi-project/tools": "^0.8.3" }, "config": { + "autoloader-suffix": "PluginTreeview", "optimize-autoloader": true, "platform": { "php": "8.2.99" From f6f6fefd0c30e1c6d0bd9b94997d74df63be8520 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:40:59 +0200 Subject: [PATCH 26/27] Fix custom asset test permissions and CI checks. --- tests/Units/ConfigTest.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/Units/ConfigTest.php b/tests/Units/ConfigTest.php index eea4cc6..b0f3a36 100644 --- a/tests/Units/ConfigTest.php +++ b/tests/Units/ConfigTest.php @@ -9,9 +9,9 @@ * * This file is part of TreeView. * - * TreeView is free software: you can redistribute it and/or modify + * TreeView is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or + * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TreeView is distributed in the hope that it will be useful, @@ -35,6 +35,8 @@ use Glpi\Asset\AssetDefinitionManager; use GlpiPlugin\Treeview\Tests\TreeviewTestCase; use Location; +use PluginTreeviewConfig; +use Session; final class ConfigTest extends TreeviewTestCase { @@ -101,7 +103,7 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void $this->removeRightFromProfile( 'Super-Admin', Computer::$rightname, - READ + READ_ASSIGNED + READ_OWNED + READ + READ_ASSIGNED + READ_OWNED, ); try { @@ -114,7 +116,7 @@ public function testGetNodesFromDbHidesItemtypeWithoutViewRight(): void $this->addRightToProfile( 'Super-Admin', Computer::$rightname, - READ + READ_ASSIGNED + READ_OWNED + READ + READ_ASSIGNED + READ_OWNED, ); } } @@ -123,6 +125,7 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void { $this->login(); $entity_id = $this->getTestRootEntity(true); + $profile_id = $_SESSION['glpiactiveprofile']['id']; $location = $this->createItem(Location::class, [ 'name' => 'treeview_asset_loc_' . $this->getUniqueString(), @@ -130,10 +133,12 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void ]); $definition_a = $this->initAssetDefinition( - 'treeview_a_' . $this->getUniqueString() + 'treeview_a_' . $this->getUniqueString(), + profiles: [$profile_id => READ], ); $definition_b = $this->initAssetDefinition( - 'treeview_b_' . $this->getUniqueString() + 'treeview_b_' . $this->getUniqueString(), + profiles: [$profile_id => READ], ); $asset_a = $this->createItem($definition_a->getAssetClassName(), [ @@ -153,8 +158,16 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void $manager->clearDefinitionsCache(); $manager->bootDefinitions(); + // Definition creation stores rights in the database. Reload the + // current profile so that canView() sees these new rights in session. + Session::changeProfile($profile_id); $this->setEntity($entity_id, false); + $this->assertTrue($asset_a::canView()); + $this->assertTrue($asset_b::canView()); + $this->assertContains($definition_a->getAssetClassName(), PluginTreeviewConfig::getTypes()); + $this->assertContains($definition_b->getAssetClassName(), PluginTreeviewConfig::getTypes()); + $output = $this->getTreeOutput($location->getID()); // Both assets share the same database table. Each asset must only @@ -163,11 +176,11 @@ public function testGetNodesFromDbDoesNotMixAssetDefinitions(): void // appear twice. $this->assertSame( 1, - substr_count($output, $asset_a->fields['name']) + substr_count($output, $asset_a->fields['name']), ); $this->assertSame( 1, - substr_count($output, $asset_b->fields['name']) + substr_count($output, $asset_b->fields['name']), ); } } From 0f0c2da1a8e3fec59264daa5a970abcc44db9bf4 Mon Sep 17 00:00:00 2001 From: BenLasTed <125013808+BenLasTed@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:42:00 +0200 Subject: [PATCH 27/27] Fix custom asset test permissions and CI checks. --- inc/config.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index 6f18ce1..ce7b5f2 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -9,9 +9,9 @@ * * This file is part of TreeView. * - * TreeView is free software: you can redistribute it and/or modify + * TreeView is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or + * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TreeView is distributed in the hope that it will be useful, @@ -133,7 +133,7 @@ public static function getTypes($all = false) $types = array_merge( $types, - AssetDefinitionManager::getInstance()->getCustomObjectClassNames() + AssetDefinitionManager::getInstance()->getCustomObjectClassNames(), ); foreach ($types as $key => $type) {