From a50fe20c14300e397fefbddaf64485de2290abfa Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Fri, 17 May 2024 14:29:27 +0200 Subject: [PATCH] Fix(Core): Fix behavior of "Display delete button" option --- CHANGELOG.md | 6 + inc/ticket.class.php | 317 ++++++++++++++++++++++--------------------- js/remove_btn.js.php | 98 +++++++++++++ 3 files changed, 263 insertions(+), 158 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e00eeb3..9eb9075 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [unreleased] + +### Fixed + +- Fix ```Display delete button``` option + ## [2.9.5] - 2024-05-06 ### Fixed diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 3313e16..653fa48 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -38,18 +38,17 @@ class PluginEscaladeTicket { public static function pre_item_update(CommonDBTM $item) { - //only if update is related to Group assign operation and _from_assignment + //only if update is related to Group assign operation and _from_assignment if ( !empty(array_filter( $item->input['_actors']['assign'] ?? [], fn ($actor) => $actor['itemtype'] == 'Group' - )) - && ( + )) && ( isset($item->input['_from_assignment']) && $item->input['_from_assignment'] ) ) { - //handle status behavior + //handle status behavior if ($_SESSION['plugins']['escalade']['config']['ticket_last_status'] != -1) { $item->input['status'] = $_SESSION['plugins']['escalade']['config']['ticket_last_status']; } @@ -58,7 +57,6 @@ public static function pre_item_update(CommonDBTM $item) if (isset($input['_itil_assign'])) { $item->input['_do_not_compute_status'] = true; } - $config = $_SESSION['plugins']['escalade']['config']; // Get actual actors for the ticket @@ -106,16 +104,16 @@ function ($carry, $type) use ($item) { } } - /** - * Provide a redirection to other functions - * @param CommonDBTM $item - * @return void - */ + /** + * Provide a redirection to other functions + * @param CommonDBTM $item + * @return void + */ public static function item_update(CommonDBTM $item) { if ($_SESSION['plugins']['escalade']['config']['remove_group']) { - //solve ticket + //solve ticket if (isset($item->input['status']) && $item->input['status'] == CommonITILObject::SOLVED) { self::AssignFirstGroupOnSolve($item); @@ -128,9 +126,9 @@ public static function item_update(CommonDBTM $item) } } - //close ticket + //close ticket if (isset($item->input['status']) && $item->input['status'] == CommonITILObject::CLOSED) { - //close linked tickets + //close linked tickets self::linkedTickets($item, CommonITILObject::CLOSED); } else if ( isset($item->input['status']) @@ -138,27 +136,27 @@ public static function item_update(CommonDBTM $item) && isset($item->oldvalues['status']) && $item->oldvalues['status'] == CommonITILObject::SOLVED ) { - //solution rejected + //solution rejected self::AssignLastGroupOnRejectedSolution($item); } } - //ticket qualification on cat change + //ticket qualification on cat change if (isset($item->input['itilcategories_id'])) { self::qualification($item); } - // notification on solve date modification + // notification on solve date modification if (in_array('solvedate', $item->updates)) { NotificationEvent::raiseEvent('update_solvedate', $item); } } - /** - * When a ticket is solved, if group histories exists, assign the first group on the ticket - * @param CommonDBTM $item the ticket object - */ + /** + * When a ticket is solved, if group histories exists, assign the first group on the ticket + * @param CommonDBTM $item the ticket object + */ public static function AssignFirstGroupOnSolve(CommonDBTM $item) { if ( @@ -170,11 +168,11 @@ public static function AssignFirstGroupOnSolve(CommonDBTM $item) $first_history = PluginEscaladeHistory::getFirstLineForTicket($tickets_id); $last_history = PluginEscaladeHistory::getLastLineForTicket($tickets_id); - //if no history + //if no history if ($first_history === false) { return; } - //if first history group == last history group + //if first history group == last history group if ($first_history['id'] == $last_history['id']) { return; } @@ -182,10 +180,10 @@ public static function AssignFirstGroupOnSolve(CommonDBTM $item) self::removeAssignGroups($tickets_id, $first_history['groups_id']); self::removeAssignUsers($tickets_id); - //set session var to prevent double task message + //set session var to prevent double task message $_SESSION['plugin_escalade']['solution'] = true; - //add the first history group (if not already exist) + //add the first history group (if not already exist) $group_ticket = new Group_Ticket(); $condition = [ 'tickets_id' => $tickets_id, @@ -196,7 +194,7 @@ public static function AssignFirstGroupOnSolve(CommonDBTM $item) $group_ticket->add($condition); } - //add a task to inform the escalation + //add a task to inform the escalation if ($_SESSION['plugins']['escalade']['config']['task_history']) { $group = new Group(); $group->getFromDB($first_history['groups_id']); @@ -207,18 +205,18 @@ public static function AssignFirstGroupOnSolve(CommonDBTM $item) '_no_reopen' => true, //prevent reopening ticket 'state' => Planning::INFO, 'content' => __("Solution provided, back to the group", "escalade") . " " . - $group->getName() + $group->getName() ]); } } } - /** - * When a ticket solution is rejected, if group histories exists, - * assign the last group on the ticket - * @param CommonDBTM $item the ticket object - */ + /** + * When a ticket solution is rejected, if group histories exists, + * assign the last group on the ticket + * @param CommonDBTM $item the ticket object + */ public static function AssignLastGroupOnRejectedSolution(CommonDBTM $item) { if (!isset($_POST['add_reopen'])) { @@ -239,21 +237,21 @@ public static function AssignLastGroupOnRejectedSolution(CommonDBTM $item) array_shift($full_history); //remove current group in history $rejected_history = array_shift($full_history); // get previous group - //if no history + //if no history if ($last_history === false) { return; } - //if first history group == last history group + //if first history group == last history group if ($rejected_history['id'] == $last_history['id']) { return; } self::removeAssignGroups($tickets_id, $rejected_history['groups_id']); - //set session var to prevent double task message + //set session var to prevent double task message $_SESSION['plugin_escalade']['solution'] = true; - //add the first history group + //add the first history group $group_ticket = new Group_Ticket(); $group_ticket->add([ 'tickets_id' => $tickets_id, @@ -261,7 +259,7 @@ public static function AssignLastGroupOnRejectedSolution(CommonDBTM $item) 'type' => CommonITILActor::ASSIGN ]); - //add a task to inform the escalation + //add a task to inform the escalation if ($_SESSION['plugins']['escalade']['config']['task_history']) { $group = new Group(); $group->getFromDB($rejected_history['groups_id']); @@ -271,11 +269,11 @@ public static function AssignLastGroupOnRejectedSolution(CommonDBTM $item) 'is_private' => true, 'state' => Planning::INFO, 'content' => __("Solution rejected, return to the group", "escalade") . " " . - $group->getName() + $group->getName() ]); } - //update status + //update status if ($_SESSION['plugins']['escalade']['config']['ticket_last_status'] != -1) { $item->update([ 'id' => $tickets_id, @@ -286,11 +284,11 @@ public static function AssignLastGroupOnRejectedSolution(CommonDBTM $item) } - /** - * remove old groups to a ticket when a new group assigned - * called by "pre_item_add" hook on Group_Ticket object - * @param CommonDBTM $item the ticket object - */ + /** + * remove old groups to a ticket when a new group assigned + * called by "pre_item_add" hook on Group_Ticket object + * @param CommonDBTM $item the ticket object + */ public static function addHistoryOnAddGroup(CommonDBTM $item) { /** @var DBmysql $DB */ @@ -300,7 +298,7 @@ public static function addHistoryOnAddGroup(CommonDBTM $item) return true; } - //if group sent is not an assign group, return + //if group sent is not an assign group, return if ($item->input['type'] != CommonITILActor::ASSIGN) { return; } @@ -308,7 +306,7 @@ public static function addHistoryOnAddGroup(CommonDBTM $item) $tickets_id = $item->input['tickets_id']; $groups_id = $item->input['groups_id']; - //if group already assigned, return + //if group already assigned, return $group_ticket = new Group_Ticket(); $condition = [ 'tickets_id' => $tickets_id, @@ -322,11 +320,12 @@ public static function addHistoryOnAddGroup(CommonDBTM $item) $item->fields['status'] = CommonITILObject::ASSIGNED; - //add line in history table + //add line in history table $history = new PluginEscaladeHistory(); $group_ticket = new Group_Ticket(); - $group_ticket->getFromDBByRequest(['ORDER' => 'id DESC', + $group_ticket->getFromDBByRequest([ + 'ORDER' => 'id DESC', 'LIMIT' => 1, 'tickets_id' => $tickets_id, 'type' => 2 @@ -352,8 +351,8 @@ public static function addHistoryOnAddGroup(CommonDBTM $item) 'counter' => $counter ]); - // check if group assignment is made during ticket creation - // in this case, skip following steps as it cannot be considered as a group escalation + // check if group assignment is made during ticket creation + // in this case, skip following steps as it cannot be considered as a group escalation $backtraces = debug_backtrace(); foreach ($backtraces as $backtrace) { if ( @@ -365,10 +364,10 @@ public static function addHistoryOnAddGroup(CommonDBTM $item) } } - //remove old user(s) (pass if user added by new ticket) + //remove old user(s) (pass if user added by new ticket) self::removeAssignUsers($tickets_id); - //add a task to inform the escalation (pass if solution) + //add a task to inform the escalation (pass if solution) if (isset($_SESSION['plugin_escalade']['solution'])) { unset($_SESSION['plugin_escalade']['solution']); return $item; @@ -419,18 +418,18 @@ public static function processAfterAddGroup(CommonDBTM $item) } - /** - * @param Ticket $ticket - * @return bool - */ + /** + * @param Ticket $ticket + * @return bool + */ public static function assignUserGroup(Ticket $ticket) { if (!is_array($ticket->input) || !count($ticket->input)) { - // Already cancel by another plugin + // Already cancel by another plugin return false; } - //check plugin behaviors (for avoid conflict) + //check plugin behaviors (for avoid conflict) if (Plugin::isPluginActive('behaviors')) { // @phpstan-ignore-next-line $behavior_config = PluginBehaviorsConfig::getInstance(); @@ -439,7 +438,7 @@ public static function assignUserGroup(Ticket $ticket) } } - //check this plugin config + //check this plugin config if ( $_SESSION['plugins']['escalade']['config']['use_assign_user_group'] == 0 || $_SESSION['plugins']['escalade']['config']['use_assign_user_group_creation'] == 0 @@ -451,29 +450,29 @@ public static function assignUserGroup(Ticket $ticket) isset($ticket->input['_users_id_assign']) && $ticket->input['_users_id_assign'] > 0 && (!isset($ticket->input['_groups_id_assign']) - || $ticket->input['_groups_id_assign'] <= 0) + || $ticket->input['_groups_id_assign'] <= 0) ) { if ($_SESSION['plugins']['escalade']['config']['use_assign_user_group'] == 1) { - // First group + // First group $ticket->input['_groups_id_assign'] - = PluginEscaladeUser::getTechnicianGroup( - $ticket->input['entities_id'], - $ticket->input['_users_id_assign'], - true - ); - //prevent adding empty group + = PluginEscaladeUser::getTechnicianGroup( + $ticket->input['entities_id'], + $ticket->input['_users_id_assign'], + true + ); + //prevent adding empty group if (empty($ticket->input['_groups_id_assign'])) { - unset($ticket->input['_groups_id_assign']); + unset($ticket->input['_groups_id_assign']); } } else { - // All groups + // All groups $ticket->input['_additional_groups_assigns'] - = PluginEscaladeUser::getTechnicianGroup( - $ticket->input['entities_id'], - $ticket->input['_users_id_assign'], - false - ); - //prevent adding empty group + = PluginEscaladeUser::getTechnicianGroup( + $ticket->input['entities_id'], + $ticket->input['_users_id_assign'], + false + ); + //prevent adding empty group if (empty($ticket->input['_additional_groups_assigns'])) { unset($ticket->input['_additional_groups_assigns']); } @@ -483,23 +482,23 @@ public static function assignUserGroup(Ticket $ticket) return true; } - /** - * assign a previous group to the ticket - * @param int $tickets_id the ticket to change - * @param int $groups_id the group to assign - * @return void - */ + /** + * assign a previous group to the ticket + * @param int $tickets_id the ticket to change + * @param int $groups_id the group to assign + * @return void + */ public static function climb_group($tickets_id, $groups_id, $full_history = false) { - //don't add group if already exist for this ticket + //don't add group if already exist for this ticket $group_ticket = new Group_Ticket(); $condition = [ 'tickets_id' => $tickets_id, 'groups_id' => $groups_id, 'type' => CommonITILActor::ASSIGN ]; - if (! $group_ticket->find($condition)) { - // add group to ticket + if (!$group_ticket->find($condition)) { + // add group to ticket $group_ticket_input = [ 'type' => CommonITILActor::ASSIGN, 'groups_id' => $groups_id, @@ -507,7 +506,7 @@ public static function climb_group($tickets_id, $groups_id, $full_history = fals '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added ]; - //handle status behavior + //handle status behavior if ($_SESSION['plugins']['escalade']['config']['ticket_last_status'] != -1) { $group_ticket_input['_from_object']['status'] = $_SESSION['plugins']['escalade']['config']['ticket_last_status']; } @@ -518,10 +517,10 @@ public static function climb_group($tickets_id, $groups_id, $full_history = fals $group_ticket->add($group_ticket_input); } - if (! $full_history) { + if (!$full_history) { Html::back(); } else { - //reload parent window and close popup + //reload parent window and close popup echo "