Skip to content

Commit

Permalink
Fix auto deletion of actors to a ticket (#192)
Browse files Browse the repository at this point in the history
* Fix auto deletion of actors to a ticket

* Fix actors deletion
  • Loading branch information
Lainow authored May 17, 2024
1 parent c225ae2 commit d1b1a34
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() => [
Expand All @@ -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;
}
}
}
}
Expand Down

0 comments on commit d1b1a34

Please # to comment.