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

Fix validationresponse ticket close #18380

39 changes: 39 additions & 0 deletions front/ticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,45 @@
if (!$track::canUpdate()) {
Html::displayRightError();
}

cedric-anne marked this conversation as resolved.
Show resolved Hide resolved
if (isset($_POST['validation_percent'])) {
$nb = countElementsInTable(TicketValidation::getTable(), ['tickets_id' => $_POST['id']]);

$rejections = countElementsInTable(TicketValidation::getTable(), [
'tickets_id' => $_POST['id'],
'status' => CommonITILValidation::REFUSED
]);

$validations = countElementsInTable(TicketValidation::getTable(), [
'tickets_id' => $_POST['id'],
'status' => CommonITILValidation::ACCEPTED
]);

if ($rejections == $nb) {
$_POST['global_validation'] = CommonITILValidation::REFUSED;
} else if ($validations > 0) {
switch ($_POST['validation_percent']) {
case 0:
$_POST['global_validation'] = CommonITILValidation::ACCEPTED;
break;
case 100:
if ($rejections > 0) {
$_POST['global_validation'] = CommonITILValidation::REFUSED;
} else {
$_POST['global_validation'] = ($validations == $nb) ? CommonITILValidation::ACCEPTED : CommonITILValidation::WAITING;
}
break;
case 50:
if ($rejections >= $nb / 2) {
$_POST['global_validation'] = CommonITILValidation::REFUSED;
} else {
$_POST['global_validation'] = ($validations >= $nb / 2) ? CommonITILValidation::ACCEPTED : CommonITILValidation::WAITING;
}
break;
}
}
}

$track->update($_POST);

if (isset($_POST['kb_linked_id'])) {
Expand Down
3 changes: 2 additions & 1 deletion src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7191,7 +7191,8 @@ class_exists($validation_class) && $params['with_validations']

$canedit = $valitation_obj->can($validations_id, UPDATE);
$cananswer = ($validation_row['users_id_validate'] === Session::getLoginUserID() &&
$validation_row['status'] == CommonITILValidation::WAITING);
$validation_row['status'] == CommonITILValidation::WAITING &&
$this->fields['status'] != CommonITILObject::CLOSED);
$user = new User();
$user->getFromDB($validation_row['users_id_validate']);

Expand Down