Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
75 changes: 22 additions & 53 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,61 +1,30 @@
<?php

/**
* -------------------------------------------------------------------------
* Fields plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Fields.
*
* Fields 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.
*
* Fields 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Fields. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @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;
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);
}
}
Loading