Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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
- Fix missing right checks on some ajax config endpoints and escape default value and URL field output.
- Fix item creation with null value for mandatory fields
- Fix search crash when two containers share a dropdown field with the same name.
Expand Down
10 changes: 10 additions & 0 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,15 @@ public function prepareInputForAdd($input)
}
}
}

$accepted_itemtypes = array_keys(array_merge(...array_values(self::getItemtypes(true))));
foreach ($input['itemtypes'] as $itemtype) {
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;
}
}
}

$input = PluginFieldsToolbox::prepareLabel($input);
Expand Down Expand Up @@ -1046,6 +1055,7 @@ public function showForm($ID, $options = [])
self::showFormItemtype([
'rand' => $rand,
'subtype' => $this->fields['subtype'],
'type' => $this->fields['type'],
]);
echo '</span>';
}
Expand Down
49 changes: 22 additions & 27 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,29 @@
* -------------------------------------------------------------------------
*/

declare(strict_types=1);
use Rector\Configuration\RectorConfigBuilder;

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;
6 changes: 4 additions & 2 deletions tests/Units/ContainerItemUpdateTest.php
Comment thread
jdurand-teclib marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
use GlpiPlugin\Field\Tests\FieldTestTrait;
use PluginFieldsContainer;
use Ticket;
use Entity;
use Notification;

require_once __DIR__ . '/../FieldTestCase.php';

Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions tests/Units/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use GlpiPlugin\Field\Tests\FieldTestTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PluginFieldsContainer;
use Ticket;

require_once __DIR__ . '/../FieldTestCase.php';

Expand Down Expand Up @@ -108,4 +109,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);
}
}