Skip to content

Commit

Permalink
Allow validating only unsolved ITIL
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Jan 15, 2025
1 parent ec0e2a1 commit 3beb5c4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The present file will list all changes made to the project; according to the
- Notifications can now specify exclusions for recipients.
- Warranty expiration alerts no longer trigger for deleted items.
- New UI for searching for Ticket/Change/Problem solutions from the Knowledgebase.
- Validations are only allowed on Tickets and Changes that are not solved or closed.

### Deprecated
- Survey URL tags `TICKETCATEGORY_ID` and `TICKETCATEGORY_NAME` are deprecated and replaced by `ITILCATEGORY_ID` and `ITILCATEGORY_NAME` respectively.
Expand Down
19 changes: 15 additions & 4 deletions phpunit/functional/TicketValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,16 @@ public static function testgetNumberToValidateProvider(): array
'name' => 'Ticket_Closed_With_Validation_Request',
'content' => 'Ticket_Closed_With_Validation_Request',
],
'expected' => 1,
'expected' => true,
'user_id' => getItemByTypeName('User', 'glpi', true)
],
[
'input' => [
'name' => 'Ticket_With_Validation_Request',
'content' => 'Ticket_With_Validation_Request',
'status' => CommonITILObject::SOLVED
],
'expected' => false,
'user_id' => getItemByTypeName('User', 'glpi', true)
],
[
Expand All @@ -351,7 +360,7 @@ public static function testgetNumberToValidateProvider(): array
'content' => 'Ticket_With_Validation_Request',
'status' => CommonITILObject::CLOSED
],
'expected' => 0,
'expected' => false,
'user_id' => getItemByTypeName('User', 'glpi', true)
],
];
Expand All @@ -360,11 +369,13 @@ public static function testgetNumberToValidateProvider(): array
#[DataProvider('testgetNumberToValidateProvider')]
public function testgetNumberToValidate(
array $input,
int $expected,
bool $expected,
int $user_id
): void {
$this->login();

$initial_count = \TicketValidation::getNumberToValidate($user_id);

/** Create a ticket, approval requested */
$ticket = $this->createItem('Ticket', $input);

Expand All @@ -374,6 +385,6 @@ public function testgetNumberToValidate(
'items_id_target' => $user_id,
]);

$this->assertEquals($expected, \TicketValidation::getNumberToValidate($user_id));
$this->assertEquals($expected ? ($initial_count + 1) : $initial_count, \TicketValidation::getNumberToValidate($user_id));
}
}
2 changes: 1 addition & 1 deletion src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7737,7 +7737,7 @@ class_exists($validation_class) && $params['with_validations']
$canedit = $validation_obj->can($validations_id, UPDATE);
$cananswer = $validation_obj->canValidate($this->getID())
&& $validation_row['status'] == CommonITILValidation::WAITING
&& !in_array($this->fields['status'], $this->getClosedStatusArray());
&& !$this->isSolved(true);
$user = new User();
$user->getFromDB($validation_row['users_id_validate']);

Expand Down
8 changes: 4 additions & 4 deletions src/CommonITILValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ public static function getNumberToValidate($users_id)
/** @var \DBmysql $DB */
global $DB;

$row = $DB->request([
$it = $DB->request([
'FROM' => static::$itemtype::getTable(),
'COUNT' => 'cpt',
'WHERE' => [
Expand All @@ -726,12 +726,12 @@ public static function getNumberToValidate($users_id)
])
],
'NOT' => [
'status' => static::$itemtype::getClosedStatusArray(),
'status' => [...static::$itemtype::getSolvedStatusArray(), ...static::$itemtype::getClosedStatusArray()],
],
]
])->current();
]);

return $row['cpt'];
return $it->current()['cpt'];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -4207,8 +4207,8 @@ public static function showCentralList($start, $status = "process", bool $showgr

$options['criteria'][2]['field'] = 12; // validation aprobator
$options['criteria'][2]['searchtype'] = 'equals';
$options['criteria'][2]['value'] = 'old';
$options['criteria'][2]['link'] = 'AND NOT';
$options['criteria'][2]['value'] = 'notold';
$options['criteria'][2]['link'] = 'AND';

$options['criteria'][3]['field'] = 52; // global validation status
$options['criteria'][3]['searchtype'] = 'equals';
Expand Down Expand Up @@ -4658,8 +4658,8 @@ public static function showCentralCount(bool $foruser = false, bool $display = t

$opt['criteria'][2]['field'] = 12; // ticket status
$opt['criteria'][2]['searchtype'] = 'equals';
$opt['criteria'][2]['value'] = Ticket::CLOSED;
$opt['criteria'][2]['link'] = 'AND NOT';
$opt['criteria'][2]['value'] = 'notold';
$opt['criteria'][2]['link'] = 'AND';

$twig_params['items'][] = [
'link' => self::getSearchURL() . "?" . Toolbox::append_params($opt),
Expand Down

0 comments on commit 3beb5c4

Please sign in to comment.