Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto deletion of actors to a ticket #192

Merged
merged 2 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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