From d1b1a34823aa9f696e4131a54be4921ba92dec0b Mon Sep 17 00:00:00 2001 From: LAUNAY Samuel <107540223+Lainow@users.noreply.github.com> Date: Fri, 17 May 2024 12:07:08 +0200 Subject: [PATCH] Fix auto deletion of actors to a ticket (#192) * Fix auto deletion of actors to a ticket * Fix actors deletion --- inc/ticket.class.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 3c253d1..3313e16 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -73,9 +73,6 @@ function ($carry, $type) use ($item) { [] ); - // Get updated actors - $actors_update = $item->input['_actors'] ?? []; - // Get deletion rights for each type of actor $deletion_rights = [ User::getType() => [ @@ -93,21 +90,16 @@ function ($carry, $type) use ($item) { ], ]; - // Iteration through actor types and verification of deletion rights - foreach ($ticket_actors as $type => $actors) { - $updatedActors = array_map( - function ($a) { - return [$a['items_id'], $a['itemtype']]; - }, - $actors_update[$type] ?? [] - ); - - foreach ($actors as $actor) { - $actorKey = [$actor['items_id'], $actor['itemtype']]; - - // If the actor has been deleted and deletion is forbidden, it is readjusted to simulate a non-deletion - if (!in_array($actorKey, $updatedActors) && empty($deletion_rights[$actor['itemtype']][$type])) { - $item->input['_actors'][$type][] = $actor; + if (!isset($item->input['_actors'])) { + $item->input['_actors'] = $item->fields['_actors']; + } else { + // Iteration through actor types and verification of deletion rights + foreach ($ticket_actors as $type => $actors) { + foreach ($actors as $actor) { + // If the actor has been deleted and deletion is forbidden, it is readjusted to simulate a non-deletion + if ($deletion_rights[$actor['itemtype']][$type] == 0) { + $item->input['_actors'][$type][] = $actor; + } } } }