Skip to content

Commit

Permalink
fix(targetticket): allow more itemtypes to associated elements (#3155)
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jan 23, 2023
1 parent 7ece642 commit cee504c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 3 additions & 2 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ protected function showAssociateSettings($rand) {
* @return array
*/
protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAnswer $formanswer) : array {
global $DB, $CFG_GLPI;
global $DB;

switch ($this->fields['associate_rule']) {
case self::ASSOCIATE_RULE_ANSWER:
Expand Down Expand Up @@ -1265,6 +1265,7 @@ protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAns
]
]);

$valid_associated_itemtypes = $_SESSION["glpiactiveprofile"]["helpdesk_item_type"];
foreach ($answers as $answer) {
// Skip if the object type is not valid asset type
$question = new PluginFormcreatorQuestion();
Expand All @@ -1273,7 +1274,7 @@ protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAns
$field = $question->getSubField();
$field->deserializeValue($answer['answer']);
$itemtype = $field->getSubItemtype();
if (!in_array($itemtype, $CFG_GLPI['asset_types'])) {
if (!in_array($itemtype, $valid_associated_itemtypes)) {
continue;
}

Expand Down
14 changes: 6 additions & 8 deletions tests/3-unit/PluginFormcreatorTargetTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,17 +1064,15 @@ public function providerSetTargetAssociatedItem_1() {
}

public function providerSetTargetAssociatedItem_LastItem() {
global $CFG_GLPI;

// Prepare form
$validItemtype = $CFG_GLPI["asset_types"][0];
if (array_search(Computer::getType(), $CFG_GLPI['asset_types']) === false) {
$CFG_GLPI['asset_types'][] = Computer::getType();
$validItemtype = $_SESSION["glpiactiveprofile"]["helpdesk_item_type"][0];
if (array_search(Computer::getType(), $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) === false) {
$_SESSION["glpiactiveprofile"]["helpdesk_item_type"][] = Computer::getType();
}
$invalidItemtype = Monitor::getType();

// Ensure an itemtype is not in the asset types
$CFG_GLPI['asset_types'] = array_filter($CFG_GLPI['asset_types'], function ($itemtype) use ($invalidItemtype) {
$_SESSION["glpiactiveprofile"]["helpdesk_item_type"] = array_filter($_SESSION["glpiactiveprofile"]["helpdesk_item_type"], function ($itemtype) use ($invalidItemtype) {
return ($itemtype != $invalidItemtype);
});

Expand Down Expand Up @@ -1384,7 +1382,7 @@ public function providerSetTargetLocation_NotSet() {

$form1 = $this->getForm();

$instance1 = new PluginFormcreatorTargetTicket();
$instance1 = $this->newTestedInstance();
$instance1->add([
'name' => 'foo',
'target_name' => '',
Expand Down Expand Up @@ -1438,7 +1436,7 @@ public function providerSetTargetLocation_LastItem() {
'fieldtype' => 'dropdown',
'itemtype' => $validItemtype
]);
$instance1 = new PluginFormcreatorTargetTicket();
$instance1 = $this->newTestedInstance();
$instance1->add([
'name' => 'foo',
'target_name' => '',
Expand Down

0 comments on commit cee504c

Please sign in to comment.