diff --git a/README.md b/README.md index 32420b1..d03e7da 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,8 @@ claude mcp login tinker # add --no-browser on a headless machine, the | `find_similar_tickets` | `tickets:read` | Open tickets with similar titles, by title text or an existing ticket (same finder as the ticket page's possible-duplicates list) | | `create_ticket` | `tickets:write` | Create a ticket (title, description, priority, category, type, visibility, assignee) | | `add_comment` | `tickets:write` | Comment (markdown, @mentions, replies) | +| `edit_comment` | `tickets:write` | Replace a comment's text (your own comments; admins any) | +| `delete_comment` | `tickets:write` | Delete a comment and its replies (your own comments; admins any); reports `replies_removed` | | `update_status` | `tickets:write` | Workflow-validated status change; `comment` required when the transition requires one | | `assign_ticket` | `tickets:write` | Assign / unassign (admin, creator, or current assignee only) | | `link_tickets` | `tickets:write` | Add a `blocks` / `blocked_by` / `relates_to` / `duplicates` link ("A duplicates B" = A is the duplicate; links only, never closes anything) | @@ -282,6 +284,7 @@ Content-Type: application/json - **Deduplication**: Generates a SHA-256 hash from the issue category, hostname, and device (no time window). A repeat alert matching an existing **open** ticket updates its title/description and escalates the priority if the condition worsened; if the matching ticket was already **closed**, it is reopened instead of creating a new one - Cluster-wide issues (Ceph health, etc.) deduplicate across all nodes (hostname excluded from hash) - Automated network tickets are keyed per problem, not just per host: on the optional `check_code` payload field when sent (it must name the instance, e.g. `iface_down:enp3s0`), otherwise on the title text outside the `[tags]`. After deploying this change (#116), run `php scripts/rehash_network_tickets.php --dry-run`, then without `--dry-run`, so open network tickets keep matching their alerts. The hash logic lives in `helpers/TicketHash.php` +- `description` is rendered as markdown on the ticket page, the same as markdown comments (#114). Reporters should send markdown: `##` sections, tables for key/value data and fenced code blocks for raw command output. Fixed-width box layouts lose their alignment. - Matrix notification sent automatically on ticket creation, priority escalation, and reopen - API key must be generated at `/admin/api-keys`; the key goes in hwmonDaemon's `/etc/hwmonDaemon/.env` as `TICKET_API_KEY` @@ -503,7 +506,7 @@ tinker_tickets/ │ └── cleanup_orphan_uploads.php # Delete orphaned upload files past grace period (cron) ├── services/ │ ├── AssignmentService.php # Assign/unassign (shared by assign_ticket.php + MCP) -│ ├── CommentService.php # Add comment + mentions/notifications (shared by add_comment.php + MCP) +│ ├── CommentService.php # Add/edit/delete comments (shared by the comment endpoints + MCP) │ ├── DependencyService.php # List/add/remove ticket links (shared by ticket_dependencies.php + MCP) │ ├── SimilarTicketService.php # Similar-title finder (shared by check_duplicates.php + MCP) │ └── TicketCreationService.php # Create ticket (shared by TicketController + MCP) diff --git a/api/delete_comment.php b/api/delete_comment.php index 7888df3..fb2d7af 100644 --- a/api/delete_comment.php +++ b/api/delete_comment.php @@ -18,9 +18,7 @@ ob_start(); try { require_once dirname(__DIR__) . '/config/config.php'; require_once dirname(__DIR__) . '/helpers/Database.php'; - require_once dirname(__DIR__) . '/models/CommentModel.php'; - require_once dirname(__DIR__) . '/models/TicketModel.php'; - require_once dirname(__DIR__) . '/models/AuditLogModel.php'; + require_once dirname(__DIR__) . '/services/CommentService.php'; // Only allow POST or DELETE — reject GET to prevent CSRF bypass $method = $_SERVER['REQUEST_METHOD']; @@ -54,8 +52,6 @@ try { } $currentUser = $_SESSION['user']; - $userId = $currentUser['user_id']; - $isAdmin = $currentUser['is_admin'] ?? false; // Use centralized database connection $conn = Database::getConnection(); @@ -76,43 +72,10 @@ try { } } - $commentId = (int)$data['comment_id']; - - // Initialize models - $commentModel = new CommentModel($conn); - $auditLog = new AuditLogModel($conn); - - // Get comment before deletion for audit log and access check - $comment = $commentModel->getCommentById($commentId); - - // Verify user can access the parent ticket - if ($comment) { - $ticketModel = new TicketModel($conn); - $ticket = $ticketModel->getTicketById($comment['ticket_id']); - if (!$ticket || !$ticketModel->canUserAccessTicket($ticket, $currentUser)) { - ob_end_clean(); - http_response_code(403); - header('Content-Type: application/json'); - echo json_encode(['success' => false, 'error' => 'Access denied']); - exit; - } - } - - // Delete comment - $result = $commentModel->deleteComment($commentId, $userId, $isAdmin); - - // Log the deletion if successful - if ($result['success'] && $comment) { - $auditLog->log( - $userId, - 'delete', - 'comment', - (string)$commentId, - [ - 'ticket_id' => $comment['ticket_id'], - 'comment_text_preview' => substr($comment['comment_text'], 0, 100) - ] - ); + $result = CommentService::deleteComment($conn, $currentUser, $data); + if (isset($result['http_status'])) { + http_response_code($result['http_status']); + unset($result['http_status']); } // Discard any unexpected output diff --git a/api/update_comment.php b/api/update_comment.php index e29c040..6118faa 100644 --- a/api/update_comment.php +++ b/api/update_comment.php @@ -18,9 +18,7 @@ ob_start(); try { require_once dirname(__DIR__) . '/config/config.php'; require_once dirname(__DIR__) . '/helpers/Database.php'; - require_once dirname(__DIR__) . '/models/CommentModel.php'; - require_once dirname(__DIR__) . '/models/TicketModel.php'; - require_once dirname(__DIR__) . '/models/AuditLogModel.php'; + require_once dirname(__DIR__) . '/services/CommentService.php'; // Check authentication via session if (session_status() === PHP_SESSION_NONE) { @@ -47,8 +45,6 @@ try { } $currentUser = $_SESSION['user']; - $userId = $currentUser['user_id']; - $isAdmin = $currentUser['is_admin'] ?? false; // Use centralized database connection $conn = Database::getConnection(); @@ -64,51 +60,10 @@ try { exit; } - $commentId = (int)$data['comment_id']; - $commentText = trim($data['comment_text']); - $markdownEnabled = isset($data['markdown_enabled']) && $data['markdown_enabled']; - - if (empty($commentText)) { - ob_end_clean(); - http_response_code(400); - header('Content-Type: application/json'); - echo json_encode(['success' => false, 'error' => 'Comment text cannot be empty']); - exit; - } - - // Initialize models - $commentModel = new CommentModel($conn); - $auditLog = new AuditLogModel($conn); - - // Verify user can access the parent ticket - $comment = $commentModel->getCommentById($commentId); - if ($comment) { - $ticketModel = new TicketModel($conn); - $ticket = $ticketModel->getTicketById($comment['ticket_id']); - if (!$ticket || !$ticketModel->canUserAccessTicket($ticket, $currentUser)) { - ob_end_clean(); - http_response_code(403); - header('Content-Type: application/json'); - echo json_encode(['success' => false, 'error' => 'Access denied']); - exit; - } - } - - // Update comment - $result = $commentModel->updateComment($commentId, $commentText, $markdownEnabled, $userId, $isAdmin); - - // Log the update if successful - if ($result['success']) { - $auditLog->log( - $userId, - 'update', - 'comment', - (string)$commentId, - [ - 'ticket_id' => $comment['ticket_id'] ?? null, - 'comment_text_preview' => substr($commentText, 0, 100), - ] - ); + $result = CommentService::updateComment($conn, $currentUser, $data); + if (isset($result['http_status'])) { + http_response_code($result['http_status']); + unset($result['http_status']); } // Discard any unexpected output diff --git a/assets/css/ticket.css b/assets/css/ticket.css index 0ef17bd..b4f08c2 100644 --- a/assets/css/ticket.css +++ b/assets/css/ticket.css @@ -360,9 +360,9 @@ kbd { padding: 0.5rem 0.25rem; line-height: 1.75; color: var(--text-primary); - /* pre-wrap preserves newlines and multiple spaces so ASCII art aligns correctly. - font-mono is inherited from body, so box-drawing characters line up. */ - white-space: pre-wrap; + /* Rendered markdown (#114): the parser's
/
control line breaks,
+ as for markdown comments (.comment-text[data-markdown]). */
+ white-space: normal;
word-break: break-word;
}
.ticket-description-view p {
diff --git a/assets/js/markdown.js b/assets/js/markdown.js
index 172ff9a..0deca20 100644
--- a/assets/js/markdown.js
+++ b/assets/js/markdown.js
@@ -80,11 +80,13 @@ function parseMarkdown(markdown) {
// Bold (**text** or __text__)
html = html.replace(/\*\*(.+?)\*\*/g, '$1');
- html = html.replace(/__(.+?)__/g, '$1');
+ // Underscores only count when not inside a word (as in CommonMark), so
+ // identifiers like node_network_up or __init__.py stay literal.
+ html = html.replace(/(?$1');
// Italic (*text* or _text_)
html = html.replace(/\*(.+?)\*/g, '$1');
- html = html.replace(/_(.+?)_/g, '$1');
+ html = html.replace(/(?$1');
// Strikethrough (~~text~~) — must run before subscript (~)
html = html.replace(/~~(.+?)~~/g, '$1');
diff --git a/assets/js/ticket.js b/assets/js/ticket.js
index 52cbdbd..75330ae 100644
--- a/assets/js/ticket.js
+++ b/assets/js/ticket.js
@@ -89,9 +89,9 @@ function renderDescriptionView() {
if (!raw.trim()) {
viewDiv.innerHTML = '
No description provided.
'; } else { - // Ticket descriptions are plain text. CSS white-space:pre-wrap handles - // line breaks and multiple spaces (ASCII art) — no