From bb196c55cd55523678652d1a4001ecfc35618dfe Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Sun, 22 Dec 2024 21:56:58 -0500 Subject: [PATCH 1/2] Ticket: Fix subscribe ticket creator and skip unsubscribed notifications - refs BT#22281 --- public/main/inc/lib/TicketManager.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/public/main/inc/lib/TicketManager.php b/public/main/inc/lib/TicketManager.php index 2b194588f1..5674e6939c 100644 --- a/public/main/inc/lib/TicketManager.php +++ b/public/main/inc/lib/TicketManager.php @@ -392,6 +392,7 @@ class TicketManager $ticketId = Database::insert($table_support_tickets, $params); if ($ticketId) { + self::subscribeUserToTicket($ticketId, $currentUserId); $ticket_code = 'A'.str_pad($ticketId, 11, '0', STR_PAD_LEFT); $titleCreated = sprintf( get_lang('Ticket %s created'), @@ -557,11 +558,11 @@ class TicketManager // Send notification to all users if (!empty($usersInCategory)) { foreach ($usersInCategory as $data) { - if ($data['user_id']) { + if ($data['user_id'] && $data['user_id'] !== $currentUserId) { self::sendNotification( $ticketId, - $subject, - $message, + $titleCreated, + $helpDeskMessage, $data['user_id'] ); } @@ -1375,6 +1376,7 @@ class TicketManager $ticketCode = $ticketInfo['ticket']['code']; $status = $ticketInfo['ticket']['status']; $priority = $ticketInfo['ticket']['priority']; + $creatorId = $ticketInfo['ticket']['sys_insert_user_id']; // Subject $titleEmail = "[$ticketCode] $title"; @@ -1394,7 +1396,11 @@ class TicketManager if (!empty($onlyToUserId) && $currentUserId != $onlyToUserId) { $recipients[$onlyToUserId] = $onlyToUserId; } else { - if ($requestUserInfo && $currentUserId != $requestUserInfo['id']) { + if ( + $requestUserInfo && + $currentUserId != $requestUserInfo['id'] && + self::isUserSubscribedToTicket($ticketId, $requestUserInfo['id']) + ) { $recipients[$requestUserInfo['id']] = $requestUserInfo['complete_name_with_username']; } @@ -1405,7 +1411,7 @@ class TicketManager $followers = self::getFollowers($ticketId); /* @var User $follower */ foreach ($followers as $follower) { - if ($currentUserId != $follower->getId()) { + if ($follower->getId() !== $creatorId || self::isUserSubscribedToTicket($ticketId, $follower->getId())) { $recipients[$follower->getId()] = $follower->getFullname(); } } From b95fc061fa2c9a6233ec111068e9d55f18d0153e Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Mon, 23 Dec 2024 19:11:48 -0500 Subject: [PATCH 2/2] Ticket: Exclude current user from ticket modification notifications - refs BT#22281 --- public/main/inc/lib/TicketManager.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/main/inc/lib/TicketManager.php b/public/main/inc/lib/TicketManager.php index 5674e6939c..6b97975569 100644 --- a/public/main/inc/lib/TicketManager.php +++ b/public/main/inc/lib/TicketManager.php @@ -1411,7 +1411,13 @@ class TicketManager $followers = self::getFollowers($ticketId); /* @var User $follower */ foreach ($followers as $follower) { - if ($follower->getId() !== $creatorId || self::isUserSubscribedToTicket($ticketId, $follower->getId())) { + if ( + $follower->getId() !== $currentUserId && + ( + $follower->getId() !== $creatorId || + self::isUserSubscribedToTicket($ticketId, $follower->getId()) + ) + ) { $recipients[$follower->getId()] = $follower->getFullname(); } }