-
Notifications
You must be signed in to change notification settings - Fork 3
Fixed a solution added even though the required fields were not filled in #7
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
510f955
cf79f68
a092f8b
0896b1f
a1cf3e8
3a7ecb3
4d84dfe
510bc56
6cf94f1
a4b74cc
fc91502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -48,6 +48,7 @@ | |||||
| use CommonITILObject; | ||||||
| use CommonITILValidation; | ||||||
| use Glpi\Form\Category; | ||||||
| use GlpiPlugin\Behaviors\Common; | ||||||
| use GlpiPlugin\Moreoptions\Config; | ||||||
| use Group_Item; | ||||||
| use Group_Problem; | ||||||
|
|
@@ -271,27 +272,60 @@ private static function addGroupsForActorType(CommonDBTM $item, Config $moconfig | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| public static function beforeCloseITILObject(CommonITILObject $item): void | ||||||
| public static function beforeCloseITILObject(CommonDBTM $item): void | ||||||
| { | ||||||
| if (!is_array($item->input)) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| $closed = true; | ||||||
|
|
||||||
| if ($item instanceof ITILSolution) { | ||||||
| $itemtype = $item->input['itemtype'] ?? null; | ||||||
|
|
||||||
| switch ($itemtype) { | ||||||
| case 'Ticket': | ||||||
| $parent_item = new Ticket(); | ||||||
| break; | ||||||
| case 'Change': | ||||||
| $parent_item = new Change(); | ||||||
| break; | ||||||
| case 'Problem': | ||||||
| $parent_item = new Problem(); | ||||||
| break; | ||||||
| default: | ||||||
| return; | ||||||
| } | ||||||
|
Lainow marked this conversation as resolved.
Outdated
|
||||||
|
|
||||||
| if (!$parent_item->getFromDB($item->input['items_id'])) { | ||||||
| return; | ||||||
| } | ||||||
| $closed = self::requireFieldsToClose($parent_item); | ||||||
| $closed = self::preventClosure($parent_item) && $closed; | ||||||
| } | ||||||
|
|
||||||
| if ( | ||||||
|
Lainow marked this conversation as resolved.
Outdated
|
||||||
| (isset($item->input['status']) && ($item->input['status'] == CommonITILObject::CLOSED || $item->input['status'] == CommonITILObject::SOLVED)) | ||||||
| || $item->fields['status'] == CommonITILObject::CLOSED | ||||||
| || $item->fields['status'] == CommonITILObject::SOLVED | ||||||
| $item instanceof CommonITILObject | ||||||
| && ( | ||||||
| (isset($item->input['status']) && ($item->input['status'] == CommonITILObject::CLOSED || $item->input['status'] == CommonITILObject::SOLVED)) | ||||||
| || $item->fields['status'] == CommonITILObject::CLOSED | ||||||
| || $item->fields['status'] == CommonITILObject::SOLVED | ||||||
| ) | ||||||
| ) { | ||||||
| self::requireFieldsToClose($item); | ||||||
| self::preventClosure($item); | ||||||
| $closed = self::requireFieldsToClose($item); | ||||||
| $closed = self::preventClosure($item) && $closed; | ||||||
| } | ||||||
|
|
||||||
| if (!$closed) { | ||||||
| $item->input = false; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public static function preventClosure(CommonDBTM $item): void | ||||||
| public static function preventClosure(CommonDBTM $item): bool | ||||||
| { | ||||||
| $conf = Config::getConfig(); | ||||||
| if ($conf->fields['is_active'] != 1) { | ||||||
| return; | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| $tasks = []; | ||||||
|
|
@@ -319,21 +353,24 @@ public static function preventClosure(CommonDBTM $item): void | |||||
| if (is_array($t) && isset($t['state']) && $t['state'] == Planning::TODO) { | ||||||
| Session::addMessageAfterRedirect(__s('The ticket you wish to close has tasks that need to be completed.', 'moreoptions'), false, ERROR); | ||||||
| $item->input = false; | ||||||
| return; | ||||||
| return false; | ||||||
| } | ||||||
| } | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| public static function requireFieldsToClose(CommonDBTM $item): void | ||||||
| public static function requireFieldsToClose(CommonDBTM $item, bool $is_solution = false): bool | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why add
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please respond to my comments instead of ignoring them!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| { | ||||||
| $conf = Config::getConfig(); | ||||||
| if ($conf->fields['is_active'] != 1) { | ||||||
| return; | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| $message = ''; | ||||||
| $itemtype = get_class($item); | ||||||
|
|
||||||
| $data = empty($item->input) ? $item->fields : $item->input; | ||||||
|
|
||||||
| // Determine the configuration suffix and actor classes based on item type | ||||||
| $configSuffix = '_' . strtolower($itemtype); | ||||||
| $userClass = $item->userlinkclass ?? ''; | ||||||
|
|
@@ -346,10 +383,10 @@ public static function requireFieldsToClose(CommonDBTM $item): void | |||||
| $tech = new $userClass(); | ||||||
| } else { | ||||||
| // If the user class is not valid, skip this check | ||||||
| return; | ||||||
| return false; | ||||||
| } | ||||||
| $techs = $tech->find([ | ||||||
| $itemIdField => $item->fields['id'], | ||||||
| $itemIdField => $data['id'], | ||||||
| 'type' => CommonITILActor::ASSIGN, | ||||||
| ]); | ||||||
| if (count($techs) == 0) { | ||||||
|
|
@@ -363,10 +400,10 @@ public static function requireFieldsToClose(CommonDBTM $item): void | |||||
| $group = new $groupClass(); | ||||||
| } else { | ||||||
| // If the group class is not valid, skip this check | ||||||
| return; | ||||||
| return false; | ||||||
| } | ||||||
| $groups = $group->find([ | ||||||
| $itemIdField => $item->fields['id'], | ||||||
| $itemIdField => $data['id'], | ||||||
| 'type' => CommonITILActor::ASSIGN, | ||||||
| ]); | ||||||
| if (count($groups) == 0) { | ||||||
|
|
@@ -376,27 +413,30 @@ public static function requireFieldsToClose(CommonDBTM $item): void | |||||
|
|
||||||
| // Check for required category | ||||||
| if ($conf->fields['require_category_to_close' . $configSuffix] == 1) { | ||||||
| if ((!isset($item->input['itilcategories_id']) || empty($item->input['itilcategories_id']))) { | ||||||
| if ((!isset($data['itilcategories_id']) || empty($data['itilcategories_id']))) { | ||||||
| $message .= '- ' . __s('Category') . '<br>'; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Check for required location | ||||||
| if ($conf->fields['require_location_to_close' . $configSuffix] == 1) { | ||||||
| if ((!isset($item->input['locations_id']) || empty($item->input['locations_id']))) { | ||||||
| if ((!isset($data['locations_id']) || empty($data['locations_id']))) { | ||||||
| $message .= '- ' . __s('Location') . '<br>'; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Check if solution exists before closing | ||||||
| if ($conf->fields['require_solution_to_close' . $configSuffix] == 1 | ||||||
| && is_array($item->input) | ||||||
| && isset($item->input['status']) | ||||||
| && $item->input['status'] == CommonITILObject::CLOSED) { | ||||||
| if ( | ||||||
| !$is_solution | ||||||
| && $conf->fields['require_solution_to_close' . $configSuffix] == 1 | ||||||
| && is_array($data) | ||||||
| && isset($data['status']) | ||||||
| && $data['status'] == CommonITILObject::CLOSED | ||||||
| ) { | ||||||
| $solution = new ITILSolution(); | ||||||
| $solutions = $solution->find([ | ||||||
| 'itemtype' => $itemtype, | ||||||
| 'items_id' => $item->fields['id'], | ||||||
| 'items_id' => $data['id'], | ||||||
| 'NOT' => [ | ||||||
| 'status' => CommonITILValidation::REFUSED, | ||||||
| ], | ||||||
|
|
@@ -411,9 +451,9 @@ public static function requireFieldsToClose(CommonDBTM $item): void | |||||
|
|
||||||
| $message = sprintf(__s('To close this %s, you must fill in the following fields:', 'moreoptions'), $itemTypeLabel) . '<br>' . $message; | ||||||
| Session::addMessageAfterRedirect($message, false, ERROR); | ||||||
| $item->input = false; | ||||||
| return; | ||||||
| return false; | ||||||
| } | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| public static function checkTaskRequirements(CommonDBTM $item): CommonDBTM | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.