Skip to content

Commit

Permalink
Merge branch '10.0/bugfixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Nov 20, 2024
2 parents cb1194c + 91f75a3 commit 6620379
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 7 deletions.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**⚠️ Please never use standard issues to report security problems; vulnerabilities are never published before a fix release is available. ⚠️**

Critical advisories are published one month after the release. All other advisories are published one week after the fix release.
Critical and high advisories are published one month after the release. All other advisories are published one week after the fix release.

## Reporting a Vulnerability

Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

138 changes: 138 additions & 0 deletions phpunit/functional/Glpi/Inventory/InventoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9243,4 +9243,142 @@ public function testRuleRefuseUpdateComputerVirtualMachines()
$c_update->getFromDBByCrit(['uuid' => 'zrerythegfzed']);
$this->assertSame("mailpit_update", $c_update->fields['name']);
}

public function testRuleRecursivityYes(): void
{
$this->login();

$entity_id = getItemByTypeName('Entity', '_test_child_2', true);

$rule = new \Rule();
$input = [
'is_active' => 1,
'name' => __METHOD__,
'match' => 'AND',
'sub_type' => 'RuleImportEntity',
'ranking' => 1
];
$rule1_id = $rule->add($input);
$this->assertGreaterThan(0, $rule1_id);

// Add criteria
$rulecriteria = new \RuleCriteria();
$input = [
'rules_id' => $rule1_id,
'criteria' => "name",
'pattern' => "/.*/",
'condition' => \RuleImportEntity::REGEX_MATCH
];
$this->assertGreaterThan(0, $rulecriteria->add($input));

// Add action
$ruleaction = new \RuleAction();
$input = [
'rules_id' => $rule1_id,
'action_type' => 'assign',
'field' => 'entities_id',
'value' => $entity_id,
];
$this->assertGreaterThan(0, $ruleaction->add($input));

$input = [
'rules_id' => $rule1_id,
'action_type' => 'assign',
'field' => 'is_recursive',
'value' => 1
];
$this->assertGreaterThan(0, $ruleaction->add($input));

$files = [
'computer_1.json',
'networkequipment_1.json',
'phone_1.json',
'printer_1.json',
];

foreach ($files as $file) {
//run inventory
$json = json_decode(file_get_contents(self::INV_FIXTURES . $file));
$inventory = $this->doInventory($json);
$assets = $inventory->getAssets();

foreach ($assets as $assettype) {
foreach ($assettype as $asset) {
$this->assertSame($entity_id, $asset->getEntity());
if (
$asset->maybeRecursive()
&& !($asset instanceof \Glpi\Inventory\Asset\Software)
) {
$this->assertTrue($asset->isRecursive());
}
}
}
}
}

public function testRuleRecursivityNo(): void
{
$this->login();

$rule = new \Rule();
$input = [
'is_active' => 1,
'name' => __METHOD__,
'match' => 'AND',
'sub_type' => 'RuleImportEntity',
'ranking' => 1
];
$rule1_id = $rule->add($input);
$this->assertGreaterThan(0, $rule1_id);

// Add criteria
$rulecriteria = new \RuleCriteria();
$input = [
'rules_id' => $rule1_id,
'criteria' => "name",
'pattern' => "/.*/",
'condition' => \RuleImportEntity::REGEX_MATCH
];
$this->assertGreaterThan(0, $rulecriteria->add($input));

// Add action
$ruleaction = new \RuleAction();
$input = [
'rules_id' => $rule1_id,
'action_type' => 'assign',
'field' => 'entities_id',
'value' => getItemByTypeName('Entity', '_test_child_2', true),
];
$this->assertGreaterThan(0, $ruleaction->add($input));

$input = [
'rules_id' => $rule1_id,
'action_type' => 'assign',
'field' => 'is_recursive',
'value' => 0
];
$this->assertGreaterThan(0, $ruleaction->add($input));

$files = [
'computer_1.json',
'networkequipment_1.json',
'phone_1.json',
'printer_1.json',
];

foreach ($files as $file) {
//run inventory
$json = json_decode(file_get_contents(self::INV_FIXTURES . $file));
$inventory = $this->doInventory($json);
$assets = $inventory->getAssets();

foreach ($assets as $assettype) {
foreach ($assettype as $asset) {
if ($asset->maybeRecursive()) {
$this->assertFalse($asset->isRecursive());
}
}
}
}
}
}
65 changes: 65 additions & 0 deletions phpunit/functional/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8057,4 +8057,69 @@ public function testIsCategoryValid(array $category_fields, array $input, bool $
$input['itilcategories_id'] = $category->getID();
$this->assertSame($expected, \Ticket::isCategoryValid($input));
}

public function testGlobalValidationUpdate(): void
{
$this->login();
$uid1 = getItemByTypeName('User', 'glpi', true);

$ticket = $this->createItem('Ticket', [
'name' => 'Global_Validation_Update',
'content' => 'Global_Validation_Update',
'validation_percent' => 100,
]);

$ticketobj = new \Ticket();

$this->assertTrue($ticketobj->getFromDB($ticket->getID()));

$v1_id = $this->createItem('TicketValidation', [
'tickets_id' => $ticket->getID(),
'itemtype_target' => User::class,
'items_id_target' => $uid1,
]);

$this->updateItem('TicketValidation', $v1_id->getID(), [
'status' => \CommonITILValidation::ACCEPTED,
]);

$this->updateItem('Ticket', $ticket->getID(), [
'validation_percent' => 0,
]);

$this->assertEquals(\CommonITILValidation::ACCEPTED, TicketValidation::computeValidationStatus($ticket));

$this->updateItem('Ticket', $ticket->getID(), [
'validation_percent' => 50,
]);

$v2_id = $this->createItem('TicketValidation', [
'tickets_id' => $ticket->getID(),
'itemtype_target' => User::class,
'items_id_target' => $uid1,
]);

$this->updateItem('TicketValidation', $v2_id->getID(), [
'status' => \CommonITILValidation::WAITING,
]);

$this->assertEquals(\CommonITILValidation::WAITING, TicketValidation::computeValidationStatus($ticket));

$this->updateItem('Ticket', $ticket->getID(), [
'validation_percent' => 100,
]);

$v3_id = $this->createItem('TicketValidation', [
'tickets_id' => $ticket->getID(),
'itemtype_target' => User::class,
'items_id_target' => $uid1,
]);

$this->updateItem('TicketValidation', $v3_id->getID(), [
'status' => \CommonITILValidation::REFUSED,
]);


$this->assertEquals(\CommonITILValidation::REFUSED, TicketValidation::computeValidationStatus($ticket));
}
}
6 changes: 6 additions & 0 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2695,6 +2695,12 @@ public function pre_updateInDB()
$this->fields['close_delay_stat'] = $this->computeCloseDelayStat();
}

// Update of the global validation status if the validation percentage has changed
if (in_array("validation_percent", $this->updates)) {
$this->updates[] = 'global_validation';
$this->fields['global_validation'] = $this->getValidationClassInstance()->computeValidationStatus($this);
}

//Look for reopening
$statuses = array_merge(
$this->getSolvedStatusArray(),
Expand Down
4 changes: 2 additions & 2 deletions src/Glpi/Console/Database/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function __construct($dbh)
OutputInterface::VERBOSITY_VERBOSE
);
if (
!$mysqli->query('CREATE DATABASE IF NOT EXISTS `' . $db_name . '`')
!$mysqli->query('CREATE DATABASE IF NOT EXISTS `' . $mysqli->real_escape_string($db_name) . '`')
|| !$mysqli->select_db($db_name)
) {
$message = sprintf(
Expand All @@ -288,7 +288,7 @@ public function __construct($dbh)
$tables_result = $mysqli->query(
"SELECT COUNT(table_name)
FROM information_schema.tables
WHERE table_schema = '{$db_name}'
WHERE table_schema = '" . $mysqli->real_escape_string($db_name) . "'
AND table_type = 'BASE TABLE'
AND table_name LIKE 'glpi\_%'"
);
Expand Down
28 changes: 28 additions & 0 deletions src/Glpi/Inventory/Asset/InventoryAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ public function setData(array $data): InventoryAsset
return $this;
}

public function getEntity(): int
{
return $this->entities_id;
}

public function maybeRecursive()
{
return true;
}

public function isRecursive(): bool
{
return (bool) $this->is_recursive;
}

/**
* Get current data
*
Expand Down Expand Up @@ -323,6 +338,19 @@ public function setEntityID($id): InventoryAsset
return $this;
}

/**
* Set entity recursive from main asset
*
* @param integer $is_recursive
*
* @return $this
*/
public function setEntityRecursive($is_recursive): InventoryAsset
{
$this->is_recursive = $is_recursive;
return $this;
}

/**
* Set request query
*
Expand Down
16 changes: 16 additions & 0 deletions src/Glpi/Inventory/Asset/MainAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,10 @@ public function handle()
$input['entities_id'] = $dataEntity['entities_id'];
}
$this->entities_id = $input['entities_id'];
if (isset($dataEntity['is_recursive'])) {
$input['is_recursive'] = $dataEntity['is_recursive'];
$this->setEntityRecursive($dataEntity['is_recursive']);
}

// get data from rules (like locations_id, states_id, groups_id_tech, etc)
// we don't want virtual action (prefixed by _)
Expand Down Expand Up @@ -974,6 +978,16 @@ public function getEntityID()
return $this->entities_id;
}

/**
* Retrieve computer entities is_recursive
*
* @return integer
*/
public function getEntityRecursive()
{
return $this->is_recursive;
}

public function handleAssets()
{
$key = $this->current_key;
Expand All @@ -997,6 +1011,7 @@ public function handleAssets()
foreach ($assets_list as $assets) {
foreach ($assets as $asset) {
$asset->setEntityID($this->getEntityID());
$asset->setEntityRecursive($this->getEntityRecursive());
$asset->setExtraData($this->assets);
foreach ($this->assets as $asset_type => $asset_list) {
if ($asset_type != '\\' . get_class($asset)) {
Expand All @@ -1013,6 +1028,7 @@ public function handleAssets()
//do controllers
foreach ($controllers as $asset) {
$asset->setEntityID($this->getEntityID());
$asset->setEntityRecursive($this->getEntityRecursive());
$asset->setExtraData($this->assets);
$asset->setExtraData(['\\' . get_class($this) => $mainasset]);
//do not handle ignored controllers
Expand Down
1 change: 1 addition & 0 deletions src/Glpi/Inventory/Asset/Monitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function handle()
if ($data['found_inventories'][0] == 0) {
// add monitor
$val->entities_id = $entities_id;
$val->is_recursive = $this->is_recursive;
$val->is_dynamic = 1;
$items_id = $monitor->add($this->handleInput($val, $monitor));
} else {
Expand Down
1 change: 1 addition & 0 deletions src/Glpi/Inventory/Asset/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ protected function handleConnectedPrinter()
if ($data['found_inventories'][0] == 0) {
// add printer
$val->entities_id = $entities_id;
$val->is_recursive = $this->is_recursive;
$val->is_dynamic = 1;
$items_id = $printer->add($this->handleInput($val, $printer));
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/Glpi/Inventory/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,11 @@ public function getMetadata(): array
return $this->metadata;
}

public function getAssets()
{
return $this->assets;
}

public function getMainAsset(): MainAsset
{
return $this->mainasset;
Expand Down
2 changes: 2 additions & 0 deletions src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ public function rawSearchOptions()
'name' => __('Real end date'),
'datatype' => 'datetime',
'massiveaction' => false,
'forcegroupby' => true,
'splititems' => true,
'joinparams' => [
'jointype' => 'child'
]
Expand Down
Loading

0 comments on commit 6620379

Please sign in to comment.