Ticket contract for automated reporters: dedup_key, source, links, reopen window (#123)
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 44s
Lint / PHP requirements (version + extensions) (push) Successful in 42s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m15s
Lint / JS (eslint) (pull_request) Successful in 34s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 42s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 4m13s
Security / PHP Security (semgrep) (pull_request) Successful in 3m25s
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 44s
Lint / PHP requirements (version + extensions) (push) Successful in 42s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m15s
Lint / JS (eslint) (pull_request) Successful in 34s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 42s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (push) Successful in 4m13s
Security / PHP Security (semgrep) (pull_request) Successful in 3m25s
From the thor#1 plan: each reporter (gandalf, hwmonDaemon, thor) decides
what "the same problem" is, and Tinker enforces it.
- dedup_key on create_ticket_api.php (scope:subject:kind, A-Za-z0-9_.:-,
case-sensitive). The hash becomes sha256("key:" + key) and the title is
not looked at; an invalid key is a 400. Keyless callers hash exactly as
before (checked over every prod title).
- Recurrence window for every reporter, keyed or not: a match on a ticket
closed under AUTO_REOPEN_WINDOW_DAYS (7) ago reopens it as before
(subject to the Workflow Designer); an older one gets a new ticket that
takes over the dedup slot (tickets.hash stays UNIQUE, the old ticket
gives it up), carries the key, records recurrence_of, is linked
relates_to, and gets a history comment. action: new_recurrence.
- GET api/tickets_api.php?dedup_key= returns the newest ticket with that
key plus its recurrence chain; ?source= filters the list.
- New api/ticket_link_api.php (link/unlink, read_write) through
DependencyService::link()/unlink(), now shared with MCP
link_tickets/unlink_tickets; audit rows record the key name.
- tickets.source records the API key name. Shown as the creator instead of
"System" on the dashboard and ticket page, a Source filter in the
sidebar, source in MCP results and a search_tickets filter. Comments the
create API writes name the reporter instead of a hard-coded
"hwmonDaemon", and system-linked comments display that name.
- Migration 008 (dedup_key, source, recurrence_of). Scripts:
backfill_ticket_source.php (pre-#123 tickets, where certain) and
backfill_dedup_keys.php (mapping file supplied by the app).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13ffc51cb7
commit
7061c40d4d
20 files changed
+1025
-206
No files matched your search
+51
-3
@@ -10,8 +10,11 @@
|
||||
* (API Key Management) when it genuinely needs the full queue.
|
||||
*
|
||||
* GET ?ticket_id=NNN -> {success, ticket, comments}
|
||||
* GET ?dedup_key=K -> {success, ticket, comments, recurrences}
|
||||
* the newest ticket carrying that key, in any status (#123);
|
||||
* recurrences lists the earlier tickets of its recurrence chain
|
||||
* GET ?status=&priority=&host= -> {success, tickets, page, total, pages}
|
||||
* &page=&limit=
|
||||
* &source=&page=&limit=
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json');
|
||||
@@ -28,6 +31,8 @@ require_once dirname(__DIR__) . '/helpers/Database.php';
|
||||
require_once dirname(__DIR__) . '/middleware/ApiKeyAuth.php';
|
||||
require_once dirname(__DIR__) . '/models/TicketModel.php';
|
||||
require_once dirname(__DIR__) . '/models/CommentModel.php';
|
||||
require_once dirname(__DIR__) . '/helpers/TicketHash.php';
|
||||
require_once dirname(__DIR__) . '/services/AutoTicketService.php';
|
||||
|
||||
try {
|
||||
$conn = Database::getConnection();
|
||||
@@ -72,6 +77,33 @@ if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
|
||||
$ticketModel = new TicketModel($conn);
|
||||
|
||||
// ── LOOKUP BY DEDUP KEY (#123) ────────────────────────────────────────────
|
||||
// Resolved to a ticket_id here, then answered by the read-one code below, so
|
||||
// visibility and the response shape are the same.
|
||||
$recurrences = null;
|
||||
if (isset($_GET['dedup_key']) && trim((string)$_GET['dedup_key']) !== '') {
|
||||
$dedupKey = trim((string)$_GET['dedup_key']);
|
||||
if (!TicketHash::isValidKey($dedupKey)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'Invalid dedup_key']);
|
||||
exit;
|
||||
}
|
||||
$keyStmt = $conn->prepare(
|
||||
"SELECT ticket_id FROM tickets WHERE dedup_key = ? ORDER BY created_at DESC, ticket_id DESC LIMIT 1"
|
||||
);
|
||||
$keyStmt->bind_param('s', $dedupKey);
|
||||
$keyStmt->execute();
|
||||
$keyRow = $keyStmt->get_result()->fetch_assoc();
|
||||
$keyStmt->close();
|
||||
if (!$keyRow) {
|
||||
http_response_code(404);
|
||||
echo json_encode(['success' => false, 'error' => 'No ticket with that dedup_key']);
|
||||
exit;
|
||||
}
|
||||
$_GET['ticket_id'] = $keyRow['ticket_id'];
|
||||
$recurrences = array_slice(AutoTicketService::chain($conn, $keyRow['ticket_id']), 1);
|
||||
}
|
||||
|
||||
// ── READ ONE ──────────────────────────────────────────────────────────────
|
||||
if (isset($_GET['ticket_id']) && trim((string)$_GET['ticket_id']) !== '') {
|
||||
$ticketId = trim((string)$_GET['ticket_id']);
|
||||
@@ -96,11 +128,22 @@ if (isset($_GET['ticket_id']) && trim((string)$_GET['ticket_id']) !== '') {
|
||||
$commentModel = new CommentModel($conn);
|
||||
$comments = $commentModel->getCommentsByTicketId($ticketId, false);
|
||||
|
||||
echo json_encode([
|
||||
$response = [
|
||||
'success' => true,
|
||||
'ticket' => $ticket,
|
||||
'comments' => $comments,
|
||||
]);
|
||||
];
|
||||
if ($recurrences !== null) {
|
||||
// A public-only key only learns the ids of earlier occurrences it may see.
|
||||
$response['recurrences'] = array_values(array_filter($recurrences, function ($id) use ($ticketModel, $visibilityUser) {
|
||||
if ($visibilityUser === null) {
|
||||
return true;
|
||||
}
|
||||
$t = $ticketModel->getTicketById($id);
|
||||
return $t && $ticketModel->canUserAccessTicket($t, $visibilityUser);
|
||||
}));
|
||||
}
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -132,6 +175,11 @@ if (isset($_GET['priority']) && trim((string)$_GET['priority']) !== '') {
|
||||
}
|
||||
}
|
||||
|
||||
// Reporter (API key name) that created the ticket, comma-separated (#123).
|
||||
if (isset($_GET['source']) && trim((string)$_GET['source']) !== '') {
|
||||
$filters['source'] = explode(',', (string)$_GET['source']);
|
||||
}
|
||||
|
||||
// hwmon puts the host in the title (e.g. "[hostname] ..."), so a host filter is a
|
||||
// title substring match — served by getAllTickets's `search` param (title search).
|
||||
$search = null;
|
||||
|
||||
Reference in new issue
Block a user