diff --git a/CHANGELOG.md b/CHANGELOG.md index 85d757ba0d3..da3d28f22e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/phpunit/functional/TicketValidationTest.php b/phpunit/functional/TicketValidationTest.php index 3ad5d53d9cf..8ae8c0dc3ea 100644 --- a/phpunit/functional/TicketValidationTest.php +++ b/phpunit/functional/TicketValidationTest.php @@ -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) ], [ @@ -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) ], ]; @@ -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); @@ -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)); } } diff --git a/src/CommonITILObject.php b/src/CommonITILObject.php index 3bf0eef7d15..e26890cd4bd 100644 --- a/src/CommonITILObject.php +++ b/src/CommonITILObject.php @@ -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']); diff --git a/src/CommonITILValidation.php b/src/CommonITILValidation.php index 171d25d7a3f..090911b21f4 100644 --- a/src/CommonITILValidation.php +++ b/src/CommonITILValidation.php @@ -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' => [ @@ -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']; } /** diff --git a/src/Ticket.php b/src/Ticket.php index 6ea234758ce..def199eef48 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -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'; @@ -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),