From c98ea0e686cefa2306e370a91cb44d0f8c585cc0 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Mon, 30 Nov 2026 14:12:08 -0500 Subject: [PATCH] Ticket CCs in the API: ticket_ccs read, create and delete endpoints scoped through the ticket's client, adding one address or several with an optional email to each new CC, removing by id or by address at Modify as on the ticket page, closed tickets left as they are, ticket history and audit lines; tickets/create takes ticket_ccs before its first email goes out and tickets/read returns each ticket's CCs; 26.12.3 changelog --- CHANGELOG.md | 2 + api/v1/enforce_api_rbac.php | 9 ++- api/v1/read_output.php | 5 ++ api/v1/ticket_ccs/create.php | 83 ++++++++++++++++++++++++++++ api/v1/ticket_ccs/delete.php | 58 +++++++++++++++++++ api/v1/ticket_ccs/read.php | 34 ++++++++++++ api/v1/ticket_ccs/ticket_cc_find.php | 29 ++++++++++ api/v1/tickets/create.php | 22 +++++++- api/v1/tickets/read.php | 1 + functions/ticket.php | 40 ++++++++++++++ 10 files changed, 280 insertions(+), 3 deletions(-) create mode 100644 api/v1/ticket_ccs/create.php create mode 100644 api/v1/ticket_ccs/delete.php create mode 100644 api/v1/ticket_ccs/read.php create mode 100644 api/v1/ticket_ccs/ticket_cc_find.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c3a2495ea..996b06fd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Update from Maintenance > Update as usual - this release has seven database chan - Invoicing a ticket on a new invoice gives the invoice the ticket's number and subject as its scope, without asking - change it on the invoice. Making a quote from a ticket has a smaller description box. - A ticket's emails stay together as one conversation in the client's inbox. Each has the same subject from the first to the last - its number in brackets, then its subject: [TCK-123] Printer offline - where it used to change with each email ("Ticket update - ...", "Ticket resolved - ... | (pending closure)"), and each carries the headers mail programs keep a conversation together by. A reply finds its ticket by those headers first, so one whose subject was changed still lands on it, and so does a reply to all on the client's first email, sent before anyone had the ticket's number. - Watchers are called CCs, as that is what they are now: on every email about the ticket, and their replies count as the client's. On a ticket it's the CC list on the Linked card and Add CC on its +, and New Ticket has a CC field. +- API: a ticket's CCs can be read, added and taken off, and a ticket raised through the API can have CCs from the start, copied in on its first email. New CCs can be emailed a link to the ticket, as Add CC does. Tickets read through the API come with their CCs. - One email, with the CCs copied in: an email about a ticket goes to its contact with the CCs, and the colleagues who asked for every update, copied in (Cc), so they see who else has it and a reply to all reaches everyone. The To line on an email reply works the same way - the contact in To, everyone else copied in. Switch it off under Admin > Settings > Tickets, Emails about a ticket, for an email each as before. - A client's reply goes on to the CCs: when the client replies by email, text or in the portal, the people an agent's reply would go to get it too, with its files - not anyone it was already to or copied to. By email, only a reply to one of the ticket's emails is passed on, as anyone can put a ticket number in a subject. It can be switched off in the same place. - Whoever the client also emails, or copies in, follows the ticket: the other people in To and Cc on the email that raises a ticket, and on a reply from the client or a CC, become its CCs - never your own addresses, anyone else at your domain or your agents. The ticket's history says who. @@ -126,6 +127,7 @@ Update from Maintenance > Update as usual - this release has seven database chan - Database 4.2.7: ticket_replies.ticket_reply_from_name and ticket_reply_from_email, set on a client reply from a CC (ticketReplyFromReady()). ticketReplyAuthorSql() selects COALESCE(contact_name, ticket_reply_from_name, ticket_reply_from_email) AS contact_name in every reply query that names a client reply - the ticket page, quick look, split, pulse, project and email history, AI summaries, the portal and the guest page. Try an Email (functions/ticket_mail_try.php) follows: a bounce address first, automatic replies as a note or set aside, CCs as client replies, closed tickets as notes, and near-same subjects from someone else linked. - Watchers are CCs in every page, email, ticket history line, log and message, and in the code. Database 4.2.8 renames ticket_watchers to ticket_ccs and its watcher_id, watcher_name, watcher_email and watcher_ticket_id to ticket_cc_id, ticket_cc_name, ticket_cc_email and ticket_cc_ticket_id, with its index. ticketWatcherEmails(), ticketAddWatchers(), ticketMailWatchersAdded() and ticketMailCopiedWatchers() are ticketCcEmails(), ticketAddCcs(), ticketMailCcsAdded() and ticketMailCopiedCcs(); ticketMailSend()'s to_watchers and ticketMailCreated()'s $to_watchers are to_ccs; the watcher group, email kind and sender are cc; the posts add_ticket_watcher (watcher_email, watcher_notify), delete_ticket_watcher and New Ticket's watchers[] are add_ticket_cc (cc_email, cc_notify), delete_ticket_cc and ccs[]; agent/modals/ticket/ticket_add_watcher.php is ticket_add_cc.php; the email preview ticket_watcher is ticket_cc. - The ticket email parser waits while a database update is pending, rather than flag email it can't take - a flagged email is left in the mailbox for good. +- API ticket CCs: api/v1/ticket_ccs/ has read.php (ticket_id or ticket_cc_id), create.php (ticket_cc_email - one address, or several as a list or separated by commas - and ticket_cc_notify) and delete.php (ticket_cc_id, or ticket_id and ticket_cc_email), each finding the ticket through ticket_cc_find.php, and is mapped to module_support in enforce_api_rbac.php. Its delete.php needs Modify, as the ticket page does, through the new $resource_operation_level, which sets one resource's file apart from $operation_level. A closed ticket's CCs aren't changed. tickets/create.php takes ticket_ccs and answers with those added, and tickets/read.php attaches each ticket's ticket_ccs (ticketCcsApiAttach(), when $api_ticket_ccs is set for read_output.php). ticketCcEmailsValid() is ticketCcEmails() naming the first entry that isn't an email address, for the API to refuse. ## [26.12.2] diff --git a/api/v1/enforce_api_rbac.php b/api/v1/enforce_api_rbac.php index ac8721ac4..46b6ab438 100644 --- a/api/v1/enforce_api_rbac.php +++ b/api/v1/enforce_api_rbac.php @@ -157,6 +157,7 @@ $resource_module = [ 'files' => 'module_support', 'folders' => 'module_support', 'ticket_replies' => 'module_support', + 'ticket_ccs' => 'module_support', 'technicians' => 'module_support', 'projects' => 'module_support', 'tasks' => 'module_support', @@ -248,7 +249,13 @@ if (!isset($resource_module[$resource])) { apiDeny("This API resource is not mapped to a permission module."); } -$required_level = $operation_level[$operation_file] ?? 2; +// Where a resource's page asks less than its file's name says - a CC comes off a ticket as an edit of the +// ticket, at Modify, as the x beside them on its page does, not a delete at Full +$resource_operation_level = [ + 'ticket_ccs' => ['delete.php' => 2], +]; + +$required_level = $resource_operation_level[$resource][$operation_file] ?? $operation_level[$operation_file] ?? 2; if ($resource_module[$resource] !== '' && lookupUserPermission($resource_module[$resource]) < $required_level) { apiDeny(apiPermissionText($resource_module[$resource], $required_level)); } diff --git a/api/v1/read_output.php b/api/v1/read_output.php index 113f330b0..71ebe558f 100644 --- a/api/v1/read_output.php +++ b/api/v1/read_output.php @@ -30,6 +30,11 @@ if ($sql && mysqli_num_rows($sql) > 0) { $return_arr['data'] = rmmApiAttach($return_arr['data']); } + // Each ticket's CCs, as ticket_ccs ($api_ticket_ccs, set by api/v1/tickets/read.php) + if (!empty($api_ticket_ccs)) { + $return_arr['data'] = ticketCcsApiAttach($return_arr['data']); + } + echo json_encode($return_arr); exit(); } diff --git a/api/v1/ticket_ccs/create.php b/api/v1/ticket_ccs/create.php new file mode 100644 index 000000000..dedd61d10 --- /dev/null +++ b/api/v1/ticket_ccs/create.php @@ -0,0 +1,83 @@ + intval($row['ticket_cc_id']), 'ticket_cc_email' => $row['ticket_cc_email']]; + } + $insert_id = $added_rows[0]['ticket_cc_id'] ?? false; + $return_arr['added'] = $added_rows; + + // Each told, when asked and ITFlow sends email - as the box on Add CC, shown only then + $notified = 0; + if (intval($_POST['ticket_cc_notify'] ?? 0) === 1 && !empty($config_smtp_provider)) { + $notified = ticketMailCcsAdded($ticket_id, $added, stripslashes($session_name)); + } + $return_arr['notified'] = $notified; + + $reference_sql = escapeSql($reference); + foreach ($added as $cc_email) { + $cc_email_sql = escapeSql($cc_email); + logTicketHistory($ticket_id, "$session_name added $cc_email_sql as a CC via the API ($api_key_name)"); + logAudit("Ticket", "Edit", "Added $cc_email_sql as a CC on ticket $reference_sql via API ($api_key_name)", $client_id, $ticket_id); + } + logAudit("API", "Success", "Added " . count($added) . " CC(s) to ticket $reference_sql via API ($api_key_name)", $client_id); +} + +// Output +require_once '../create_output.php'; diff --git a/api/v1/ticket_ccs/delete.php b/api/v1/ticket_ccs/delete.php new file mode 100644 index 000000000..7268611b9 --- /dev/null +++ b/api/v1/ticket_ccs/delete.php @@ -0,0 +1,58 @@ + 0) { + $cc_email_sql = escapeSql($cc_row['ticket_cc_email']); + $reference_sql = escapeSql(ticketReference($ticket)); + logTicketHistory($ticket_id, "$session_name removed $cc_email_sql as a CC via the API ($api_key_name)"); + logAudit("Ticket", "Edit", "Removed $cc_email_sql as a CC on ticket $reference_sql via API ($api_key_name)", $client_id, $ticket_id); + logAudit("API", "Success", "Removed $cc_email_sql as a CC on ticket $reference_sql via API ($api_key_name)", $client_id); + } +} + +// Output +require_once '../delete_output.php'; diff --git a/api/v1/ticket_ccs/read.php b/api/v1/ticket_ccs/read.php new file mode 100644 index 000000000..a934483a7 --- /dev/null +++ b/api/v1/ticket_ccs/read.php @@ -0,0 +1,34 @@ + intval($cc['ticket_cc_id']), 'ticket_cc_name' => $cc['ticket_cc_name'], 'ticket_cc_email' => $cc['ticket_cc_email']]; + } + } + foreach ($rows as &$row) { + $row['ticket_ccs'] = $ccs[intval($row['ticket_id'] ?? 0)] ?? []; + } + unset($row); + return $rows; +} + /** Add CCs a ticket doesn't have already - the ones added. Never one of ITFlow's own addresses (emailOwnAddresses()). */ function ticketAddCcs($ticket_id, array $emails) { global $mysqli;