From dc8c2b0f1bed62e22490d49166f3b6c90246d770 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Mon, 27 Jul 2026 15:32:18 +0200 Subject: [PATCH 1/6] fix: A bug that make the user able to link a container type and a object that are not normaly linkable --- inc/container.class.php | 12 ++++++++++++ tests/Units/ContainerItemUpdateTest.php | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index 979a5a09..5438349a 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -700,6 +700,17 @@ public function prepareInputForAdd($input) } } } + + $accepted_itemtypes = self::getItemtypes(true); + foreach ($input['itemtypes'] as $itemtype) { + foreach ($accepted_itemtypes as $accepted_itemtype) { + if (!in_array($itemtype, array_keys($accepted_itemtype))) { + Session::AddMessageAfterRedirect(__("At least one selected object cannot be linked with type 'Insertion in the form of a specific tab'.", 'fields'), false, ERROR); + + return false; + } + } + } } $input = PluginFieldsToolbox::prepareLabel($input); @@ -1040,6 +1051,7 @@ public function showForm($ID, $options = []) self::showFormItemtype([ 'rand' => $rand, 'subtype' => $this->fields['subtype'], + 'type' => $this->fields['type'], ]); echo ''; } diff --git a/tests/Units/ContainerItemUpdateTest.php b/tests/Units/ContainerItemUpdateTest.php index b7a456de..587a13be 100644 --- a/tests/Units/ContainerItemUpdateTest.php +++ b/tests/Units/ContainerItemUpdateTest.php @@ -35,6 +35,8 @@ use GlpiPlugin\Field\Tests\FieldTestTrait; use PluginFieldsContainer; use Ticket; +use Entity; +use Notification; require_once __DIR__ . '/../FieldTestCase.php'; @@ -392,8 +394,8 @@ public function testCreateIsNotBlockedWhenMandatoryTabOrDomtabFieldIsMissing(): $domtab_container = $this->createFieldContainer([ 'label' => 'Mandatory Domtab Container', 'type' => 'domtab', - 'subtype' => Ticket::class . '$1', - 'itemtypes' => [Ticket::class], + 'subtype' => Notification::class . '$1', + 'itemtypes' => [Entity::class], 'is_active' => 1, 'entities_id' => 0, 'is_recursive' => 1, From 1be1c99b903d945ccdf666cfc8cbc9288ffd7482 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Mon, 27 Jul 2026 15:39:58 +0200 Subject: [PATCH 2/6] chore: update Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be0ec1ad..e23a565d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fix a container creation bug that was allowing to link incompatible container types and object types + +### Fixed + - Fix item creation with null value for mandatory fields - Fix search crash when two containers share a dropdown field with the same name. From 9035e24ee4c10deb8cf62f6beccf9a67b4442fd3 Mon Sep 17 00:00:00 2001 From: Julien DURAND Date: Mon, 27 Jul 2026 16:38:40 +0200 Subject: [PATCH 3/6] Apply suggestion from @Rom1-B Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e23a565d..317dc241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,9 +10,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix a container creation bug that was allowing to link incompatible container types and object types - -### Fixed - - Fix item creation with null value for mandatory fields - Fix search crash when two containers share a dropdown field with the same name. From 3528db2302dbc2b658cedf0e334e674718bdff30 Mon Sep 17 00:00:00 2001 From: Julien DURAND Date: Mon, 27 Jul 2026 16:45:13 +0200 Subject: [PATCH 4/6] Update inc/container.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/container.class.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index 5438349a..0bfbf70d 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -701,14 +701,12 @@ public function prepareInputForAdd($input) } } - $accepted_itemtypes = self::getItemtypes(true); + $accepted_itemtypes = array_keys(array_merge(...array_values(self::getItemtypes(true)))); foreach ($input['itemtypes'] as $itemtype) { - foreach ($accepted_itemtypes as $accepted_itemtype) { - if (!in_array($itemtype, array_keys($accepted_itemtype))) { - Session::AddMessageAfterRedirect(__("At least one selected object cannot be linked with type 'Insertion in the form of a specific tab'.", 'fields'), false, ERROR); + if (!in_array($itemtype, $accepted_itemtypes)) { + Session::AddMessageAfterRedirect(__("At least one selected object cannot be linked with type 'Insertion in the form of a specific tab'.", 'fields'), false, ERROR); - return false; - } + return false; } } } From 71c5a9e9e312af41cac37a1915beafb726b8daea Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Mon, 27 Jul 2026 16:55:16 +0200 Subject: [PATCH 5/6] chore: Add unit test following code review --- tests/Units/ContainerTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Units/ContainerTest.php b/tests/Units/ContainerTest.php index a7fa7098..ee094f5e 100644 --- a/tests/Units/ContainerTest.php +++ b/tests/Units/ContainerTest.php @@ -36,6 +36,7 @@ use GlpiPlugin\Field\Tests\FieldTestTrait; use PHPUnit\Framework\Attributes\DataProvider; use PluginFieldsContainer; +use Ticket; require_once __DIR__ . '/../FieldTestCase.php'; @@ -106,4 +107,19 @@ public function testAddWithValidItemtypesSucceeds(): void $this->assertGreaterThan(0, $container->getID()); } + + public function testAddDomtabWithIncompatibleItemtypeIsRejected(): void + { + $container = new PluginFieldsContainer(); + $result = $container->add([ + 'label' => 'Domtab with invalid item type', + 'type' => 'domtab', + 'subtype' => '', + 'itemtypes' => [Ticket::class], + 'is_active' => 1, + 'entities_id' => 0, + 'is_recursive' => 1, + ]); + $this->assertFalse($result); + } } From c372d24b261cf3b4178bf021fc2b9ef6a832303c Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Tue, 28 Jul 2026 16:38:16 +0200 Subject: [PATCH 6/6] chore: update rector --- rector.php | 75 ++++++++++++++++-------------------------------------- 1 file changed, 22 insertions(+), 53 deletions(-) diff --git a/rector.php b/rector.php index 3cdf1519..0b6ade4b 100644 --- a/rector.php +++ b/rector.php @@ -1,61 +1,30 @@ . - * ------------------------------------------------------------------------- - * @copyright Copyright (C) 2013-2023 by Fields plugin team. - * @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html - * @link https://github.com/pluginsGLPI/fields - * ------------------------------------------------------------------------- - */ +use Rector\Configuration\RectorConfigBuilder; declare(strict_types=1); require_once __DIR__ . '/../../src/Plugin.php'; -use Rector\Caching\ValueObject\Storage\FileCacheStorage; -use Rector\Config\RectorConfig; -use Rector\ValueObject\PhpVersion; +$baseline_file = __DIR__ . '/../../PluginsRector.php'; +if (!file_exists($baseline_file)) { + throw new RuntimeException( + sprintf( + 'Unable to find "%s". Running rector on a plugin requires a GLPI development checkout that ships PluginsRector.php.', + $baseline_file, + ), + ); +} -return RectorConfig::configure() - ->withPaths([ - __DIR__ . '/ajax', - __DIR__ . '/front', - __DIR__ . '/inc', - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->withPhpVersion(PhpVersion::PHP_82) - ->withCache( - cacheDirectory: __DIR__ . '/var/rector', - cacheClass: FileCacheStorage::class, - ) - ->withRootFiles() - ->withParallel(timeoutSeconds: 300) - ->withImportNames(removeUnusedImports: true) - ->withPreparedSets( - deadCode: true, - codeQuality: true, - codingStyle: true, - ) - ->withPhpSets(php82: true) // apply PHP sets up to PHP 8.2 -; +$baseline = require $baseline_file; + +/** @var RectorConfigBuilder $config */ +$config = $baseline([ + __DIR__ . '/ajax', + __DIR__ . '/front', + __DIR__ . '/inc', + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +return $config;