Skip to content

Commit

Permalink
Fix rules execution before escalation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lainow authored Jul 4, 2024
1 parent 20d35ab commit d469aff
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 59 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions front/ticket.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -69,22 +85,6 @@
'<p><i>' . sprintf(__('Escalation to the group %s.', 'escalade'), Sanitizer::unsanitize($group->getName())) . '</i></p><hr />'
) . $_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);
}
}

Expand Down
14 changes: 0 additions & 14 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ function plugin_escalade_item_update($item)
return true;
}


/**
* Summary of plugin_escalade_item_add_user
* @param mixed $item
Expand Down Expand Up @@ -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 (
Expand Down
126 changes: 98 additions & 28 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 16 additions & 1 deletion templates/escalade_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

{% block timeline_card %}
<div class="escalation card mt-4 ">
<form name="asset_form" class="d-flex flex-column escalation-form bg-white" method="post"
<form name="asset_form" id="asset_form" class="d-flex flex-column escalation-form bg-white" method="post"
action="{{ action }}"
enctype="multipart/form-data"
data-track-changes="true" data-submit-once>
Expand Down Expand Up @@ -100,4 +100,19 @@
</div>
</form>
</div>
<script>
$(document).ready(function () {
var form = $('#itil-form');
var inputs = form.serializeArray();
var asset_form = $('#asset_form');
if (asset_form.length > 0) {
$.each(inputs, function(i, input) {
if (input.name != '_actors') {
asset_form.append('<input type="hidden" name="ticket_details[' + input.name + ']" value="' + input.value + '">');
}
});
}
});
</script>
{% endblock %}

0 comments on commit d469aff

Please sign in to comment.