Skip to content

Commit 46f23d0

Browse files
authored
Fix - Prevent from interfering with template mandatory field validation (#379)
* Fix - Prevent from interfering with template mandatory field validation * Add tests & update CHANGELOG * Fix tests * Fix tests * Fix tests * Fix Associate myself with mandatory field * Fix escalation by history with mandatory field * Fix escalation by history with mandatory field
1 parent 84da7a4 commit 46f23d0

3 files changed

Lines changed: 489 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Fixed
1111

12+
- Fix template mandatory field validation interference when adding solutions to tickets
1213
- Fix the relationship when cloning a ticket: if the `Close linked tickets at the same time` option is enabled, the relationship is `DUPLICATED_WITH` otherwise it's `LINK_TO`
1314
- Fix tech assignment should not trigger escalation behavior (as defined in the documentation)
1415

inc/ticket.class.php

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,73 @@ class PluginEscaladeTicket
4141

4242
public static function pre_item_update(CommonDBTM $item)
4343
{
44+
// Only process escalation logic if we're dealing with actor assignments
45+
// Don't interfere with other updates like solutions, status changes, etc.
46+
if (!isset($item->input['_actors']) && !isset($item->input['_itil_assign']) && !isset($item->input['actortype'])) {
47+
return $item;
48+
}
49+
50+
// Special case: If we have _itil_assign without actortype, we need to distinguish between:
51+
// 1. "Associate myself" button - many fields merged from ticket form
52+
// 2. History button escalation (climb_group) - specific structure with groups_id and _type = 'group'
53+
// 3. Other _itil_assign operations
54+
if (isset($item->input['_itil_assign']) && !isset($item->input['actortype']) && !isset($item->input['_actors'])) {
55+
$itil_assign = $item->input['_itil_assign'];
56+
57+
// Check if it's a history button escalation from climb_group
58+
if (isset($itil_assign['groups_id']) && isset($itil_assign['_type']) && $itil_assign['_type'] === 'group' && count($item->input) <= 3) {
59+
// This is a history button escalation - add required fields for template validation
60+
// but don't interfere with the escalation logic
61+
$item->input['_no_escalade_template_validation'] = true;
62+
}
63+
// Check if it's "Associate myself" (many fields merged)
64+
elseif (count($item->input) > 10) {
65+
// Associate myself - don't interfere
66+
return $item;
67+
}
68+
}
69+
4470
$input = $item->input;
4571
if ($item instanceof CommonITILObject) {
46-
$input = $item->prepareInputForUpdate($item->input);
72+
// Special handling for history button escalation to pass template validation
73+
if (isset($item->input['_no_escalade_template_validation'])) {
74+
// Add existing ticket fields temporarily for template validation
75+
$existing_fields = Toolbox::addslashes_deep($item->fields);
76+
$temp_input = array_merge($existing_fields, $item->input);
77+
78+
// Ensure required fields are not empty for template validation
79+
if (empty($temp_input['content'])) {
80+
$temp_input['content'] = 'Auto-generated content for escalation';
81+
}
82+
83+
// Add existing actors to pass mandatory field validation
84+
$ticket_user = new \Ticket_User();
85+
$ticket_group = new \Group_Ticket();
86+
87+
// Get existing requesters
88+
$requesters = $ticket_user->find([
89+
'tickets_id' => $item->getID(),
90+
'type' => CommonITILActor::REQUESTER,
91+
]);
92+
if (!empty($requesters)) {
93+
$temp_input['_users_id_requester'] = array_column($requesters, 'users_id');
94+
}
95+
96+
// Get existing requester groups
97+
$requester_groups = $ticket_group->find([
98+
'tickets_id' => $item->getID(),
99+
'type' => CommonITILActor::REQUESTER,
100+
]);
101+
if (!empty($requester_groups)) {
102+
$temp_input['_groups_id_requester'] = array_column($requester_groups, 'groups_id');
103+
}
104+
105+
$temp_input['_disablenotif'] = true; // Disable notifications for this validation
106+
$input = $item->prepareInputForUpdate($temp_input);
107+
unset($item->input['_no_escalade_template_validation']); // Clean up flag
108+
} else {
109+
$input = $item->prepareInputForUpdate($item->input);
110+
}
47111
if (!$input) {
48112
return false;
49113
}

0 commit comments

Comments
 (0)