Skip to content

Commit

Permalink
Ensure value is numeric searching in validation status
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher authored Apr 24, 2024
1 parent 0a6b28b commit 3321d01
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ public static function constructCriteriaSQL($criteria = [], $data = [], $searcho
}

/**
* Construct aditionnal SQL (select, joins, etc) for meta-criteria
* Construct additional SQL (select, joins, etc) for meta-criteria
*
* @since 9.4
*
Expand Down Expand Up @@ -5167,29 +5167,20 @@ public static function addWhere($link, $nott, $itemtype, $ID, $searchtype, $val,
case "glpi_ticketvalidations.status":
case "glpi_changes.global_validation":
case "glpi_changevalidations.status":
if ($val == 'all') {
if ($val != 'can' && !is_numeric($val)) {
return "";
}
$tocheck = [];
switch ($val) {
case 'can':
$tocheck = CommonITILValidation::getCanValidationStatusArray();
break;

case 'all':
$tocheck = CommonITILValidation::getAllValidationStatusArray();
break;
if ($val === 'can') {
$tocheck = CommonITILValidation::getCanValidationStatusArray();
}
if (count($tocheck) == 0) {
$tocheck = [$val];
}
if (count($tocheck)) {
if ($nott) {
return $link . " `$table`.`$field` NOT IN ('" . implode("','", $tocheck) . "')";
}
return $link . " `$table`.`$field` IN ('" . implode("','", $tocheck) . "')";
if ($nott) {
return $link . " `$table`.`$field` NOT IN ('" . implode("','", $tocheck) . "')";
}
break;
return $link . " `$table`.`$field` IN ('" . implode("','", $tocheck) . "')";

case "glpi_notifications.event":
if (in_array($searchtype, ['equals', 'notequals']) && strpos($val, self::SHORTSEP)) {
Expand Down
42 changes: 42 additions & 0 deletions tests/functional/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -5087,6 +5087,48 @@ public function testRichText(

$this->array($items)->isEqualTo($expected);
}

public function testTicketValidationStatus()
{
$search_params = [
'reset' => 'reset',
'is_deleted' => 0,
'start' => 0,
'search' => 'Search',
'criteria' => [
0 => [
'field' => 'view', // items seen
'searchtype' => 'contains',
'value' => 'any string'
]
]
];

$displaypref = new \DisplayPreference();
$input = [
'itemtype' => 'Ticket',
'users_id' => \Session::getLoginUserID(),
'num' => 55, //Ticket glpi_ticketvalidations.status
];
$this->integer((int)$displaypref->add($input))->isGreaterThan(0);


$data = $this->doSearch('Ticket', $search_params);

$this->string($data['sql']['search'])->notContains("`glpi_ticketvalidations`.`status` IN");

$search_params['criteria'][0]['value'] = 1;
$data = $this->doSearch('Ticket', $search_params);
$this->string($data['sql']['search'])->contains("`glpi_ticketvalidations`.`status` IN");

$search_params['criteria'][0]['value'] = 'all';
$data = $this->doSearch('Ticket', $search_params);
$this->string($data['sql']['search'])->notContains("`glpi_ticketvalidations`.`status` IN");

$search_params['criteria'][0]['value'] = 'can';
$data = $this->doSearch('Ticket', $search_params);
$this->string($data['sql']['search'])->contains("`glpi_ticketvalidations`.`status` IN");
}
}

// @codingStandardsIgnoreStart
Expand Down

0 comments on commit 3321d01

Please sign in to comment.