-
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
Open
Lainow
wants to merge
5
commits into
main
Choose a base branch
from
fix-added-solution-when-requiredfield-is-undefined
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−59
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
510f955
Fixed a solution added even though the required fields were not fille…
Lainow cf79f68
Fix PHP CS
Lainow a092f8b
Fixed a solution added even though the required fields were not fille…
Lainow 0896b1f
Fix PHPStan
Lainow a1cf3e8
Fix is solution
Lainow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if (!$parent_item->getFromDB($item->input['items_id'])) { | ||||||||||
| return; | ||||||||||
| } | ||||||||||
| $closed = self::requireFieldsToClose($parent_item, true); | ||||||||||
| $closed = self::preventClosure($parent_item) && $closed; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if ( | ||||||||||
|
Comment on lines
+305
to
307
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.
Suggested change
|
||||||||||
| (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 | ||||||||||
Lainow marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| { | ||||||||||
| $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 | ||||||||||
|
|
||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???