Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow validating only unsolved ITIL #18604

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ The present file will list all changes made to the project; according to the
- `Group` and `Group in charge` fields for assets may now contain multiple groups.
- "If software are no longer used" transfer option is now taken into account rather than always preserving.
- Notifications can now specify exclusions for recipients.
- 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 @@ -7738,7 +7738,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());
&& !in_array($this->fields['status'], static::getSolvedStatusArray() + static::getClosedStatusArray());
$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 @@ -4208,8 +4208,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 @@ -4659,8 +4659,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
Loading