diff --git a/CHANGELOG.md b/CHANGELOG.md index 1effe76..4f0b883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [unrelease] - +### Added + +- Add config option for default assignation + ### Fixed +- Fix rules execution before escalation +- Set assign as observer unchecked by default +- Fixed ```blocking of user deletion``` - Fix ```use technician group``` option ## [2.9.6] - 2024-05-17 diff --git a/front/ticket.form.php b/front/ticket.form.php index ad7823e..c144c55 100644 --- a/front/ticket.form.php +++ b/front/ticket.form.php @@ -59,6 +59,22 @@ ]); } + // Update the ticket with actor data in order to execute the necessary rules + $_form_object = [ + '_do_not_compute_status' => true, + ]; + if ($_SESSION['plugins']['escalade']['config']['ticket_last_status'] != -1) { + $_form_object['status'] = $_SESSION['plugins']['escalade']['config']['ticket_last_status']; + } + $updates_ticket = new Ticket(); + $updates_ticket->update($_POST['ticket_details'] + [ + '_actors' => PluginEscaladeTicket::getTicketFieldsWithActors($tickets_id, $group_id), + '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added + 'actortype' => CommonITILActor::ASSIGN, + 'groups_id' => $group_id, + '_form_object' => $_form_object, + ]); + $task = new TicketTask(); $task->add([ 'tickets_id' => $tickets_id, @@ -69,22 +85,6 @@ '

' . sprintf(__('Escalation to the group %s.', 'escalade'), Sanitizer::unsanitize($group->getName())) . '


' ) . $_POST['comment'] ]); - - $group_ticket_input = [ - 'type' => CommonITILActor::ASSIGN, - 'groups_id' => $group_id, - 'tickets_id' => $tickets_id, - '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added - ]; - - //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']; - } - $group_ticket_input['_from_object']['_do_not_compute_status'] = true; - - $group_ticket = new Group_Ticket(); - $group_ticket->add($group_ticket_input); } } diff --git a/hook.php b/hook.php index 917dfdb..e709085 100644 --- a/hook.php +++ b/hook.php @@ -449,7 +449,6 @@ function plugin_escalade_item_update($item) return true; } - /** * Summary of plugin_escalade_item_add_user * @param mixed $item @@ -506,19 +505,6 @@ function plugin_escalade_item_add_ticket($item) } } -function plugin_escalade_pre_item_add_group_ticket($item) -{ - if ( - $item instanceof Group_Ticket - && $item->input['type'] == CommonITILActor::ASSIGN - ) { - //disable notification to prevent notification for old AND new group - $item->input['_disablenotif'] = true; - return PluginEscaladeTicket::addHistoryOnAddGroup($item); - } - return $item; -} - function plugin_escalade_item_add_group_ticket($item) { if ( diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 07d44a8..1598b4e 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -102,6 +102,24 @@ function ($carry, $type) use ($item) { } } } + if (!isset($item->input['actortype'])) { + $groups = new Group_Ticket(); + $groups = $groups->find(['tickets_id' => $item->getID(), 'type' => CommonITILActor::ASSIGN]); + foreach ($item->input['_actors']['assign'] as $actors) { + if ($actors['itemtype'] == 'Group' && !in_array($actors['items_id'], $groups)) { + $item->input['groups_id'] = $actors['items_id']; + $item->input['actortype'] = CommonITILActor::ASSIGN; + } + } + } + if ( + (isset($item->input['actortype']) && $item->input['actortype'] == CommonITILActor::ASSIGN) + ) { + //disable notification to prevent notification for old AND new group + $item->input['_disablenotif'] = true; + return PluginEscaladeTicket::addHistoryOnAddGroup($item); + } + return $item; } /** @@ -299,25 +317,13 @@ public static function addHistoryOnAddGroup(CommonDBTM $item) } //if group sent is not an assign group, return - if ($item->input['type'] != CommonITILActor::ASSIGN) { + if ($item->input['actortype'] != CommonITILActor::ASSIGN) { return; } - $tickets_id = $item->input['tickets_id']; + $tickets_id = $item->input['id']; $groups_id = $item->input['groups_id']; - //if group already assigned, return - $group_ticket = new Group_Ticket(); - $condition = [ - 'tickets_id' => $tickets_id, - 'groups_id' => $groups_id, - 'type' => CommonITILActor::ASSIGN - ]; - if ($group_ticket->find($condition)) { - unset($_SESSION['plugin_escalade']['keep_users']); - return; - } - $item->fields['status'] = CommonITILObject::ASSIGNED; //add line in history table @@ -498,23 +504,24 @@ public static function climb_group($tickets_id, $groups_id, $full_history = fals 'type' => CommonITILActor::ASSIGN ]; if (!$group_ticket->find($condition)) { - // add group to ticket - $group_ticket_input = [ - 'type' => CommonITILActor::ASSIGN, - 'groups_id' => $groups_id, - 'tickets_id' => $tickets_id, - '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added - ]; + $ticket = new Ticket(); + $ticket->getFromDB($tickets_id); - //handle status behavior + // Update the ticket with actor data in order to execute the necessary rules + $_form_object = [ + '_do_not_compute_status' => true, + ]; if ($_SESSION['plugins']['escalade']['config']['ticket_last_status'] != -1) { - $group_ticket_input['_from_object']['status'] = $_SESSION['plugins']['escalade']['config']['ticket_last_status']; + $_form_object['status'] = $_SESSION['plugins']['escalade']['config']['ticket_last_status']; } - - $group_ticket_input['_from_object']['_do_not_compute_status'] = true; - - $group_ticket = new Group_Ticket(); - $group_ticket->add($group_ticket_input); + $updates_ticket = new Ticket(); + $updates_ticket->update($_POST['ticket_details'] + [ + '_actors' => PluginEscaladeTicket::getTicketFieldsWithActors($tickets_id, $groups_id), + '_plugin_escalade_no_history' => true, // Prevent a duplicated task to be added + 'actortype' => CommonITILActor::ASSIGN, + 'groups_id' => $groups_id, + '_form_object' => $_form_object, + ]); } if (!$full_history) { @@ -1018,6 +1025,69 @@ public static function addToTimeline($options) return $itemtypes; } + /** + * Get ticket field with actors inputs + * + * @param int $tickets_id + * @param int $group_id + * + * @return array + */ + public static function getTicketFieldsWithActors($tickets_id, $group_id) + { + $ticket = new Ticket(); + $link_class = [ + 'User' => new $ticket->userlinkclass(), + 'Group' => new $ticket->grouplinkclass(), + 'Supplier' => new $ticket->supplierlinkclass(), + ]; + $ticket_actors = []; + $actor_types = [ + CommonITILActor::ASSIGN => 'assign', + CommonITILActor::OBSERVER => 'observer', + CommonITILActor::REQUESTER => 'requester', + ]; + + foreach ($link_class as $itemtype => $class) { + $ticket_actor = $class->getActors($tickets_id); + foreach ($ticket_actor as $type => $value) { + $actors_input = []; + foreach ($value as $val) { + $actors_input[] = [ + 'itemtype' => $itemtype, + 'items_id' => $val[strtolower($itemtype . 's_id')], + ]; + } + $actortype = $actor_types[$type] ?? ''; + if ($actortype) { + $ticket_actors[$itemtype][$actortype] = $actors_input; + } + } + } + $ticket_actors['Group']['assign'][] = [ + 'itemtype' => 'Group', + 'items_id' => $group_id, + ]; + + $_actors['assign'] = array_merge( + $ticket_actors['User']['assign'] ?? [], + $ticket_actors['Group']['assign'] ?? [], + $ticket_actors['Supplier']['assign'] ?? [] + ); + $_actors['observer'] = array_merge( + $ticket_actors['User']['observer'] ?? [], + $ticket_actors['Group']['observer'] ?? [], + $ticket_actors['Supplier']['observer'] ?? [] + ); + $_actors['requester'] = array_merge( + $ticket_actors['User']['requester'] ?? [], + $ticket_actors['Group']['requester'] ?? [], + $ticket_actors['Supplier']['requester'] ?? [] + ); + + return $_actors; + } + public function showForm($ID, $options = []) { $tickets_id = $options["parent"]->getID(); diff --git a/templates/escalade_form.html.twig b/templates/escalade_form.html.twig index 171020e..b22e62a 100644 --- a/templates/escalade_form.html.twig +++ b/templates/escalade_form.html.twig @@ -31,7 +31,7 @@ {% block timeline_card %}
-
@@ -100,4 +100,19 @@
+ {% endblock %}