MCP: edit_comment and delete_comment tools
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 35s
Lint / PHP requirements (version + extensions) (push) Successful in 34s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m0s
Security / PHP Security (semgrep) (push) Successful in 2m44s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 1m9s
Lint / JS (eslint) (pull_request) Successful in 14s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (pull_request) Successful in 1m44s
Lint / JS (eslint) (push) Successful in 14s
Lint / PHP (phpcs PSR-12) (push) Successful in 35s
Lint / PHP requirements (version + extensions) (push) Successful in 34s
Lint / Deploy (push) Skipped
Lint / Notify on failure (push) Skipped
Lint / PHP (phpcs PSR-12) (pull_request) Successful in 1m0s
Security / PHP Security (semgrep) (push) Successful in 2m44s
Lint / PHP requirements (version + extensions) (pull_request) Successful in 1m9s
Lint / JS (eslint) (pull_request) Successful in 14s
Lint / Deploy (pull_request) Skipped
Lint / Notify on failure (pull_request) Skipped
Security / PHP Security (semgrep) (pull_request) Successful in 1m44s
Two new tickets:write tools, on the same code path as the web UI's comment edit/delete. The access check, owner-or-admin rule and audit entry moved out of api/update_comment.php and api/delete_comment.php into CommentService::updateComment/deleteComment (as add_comment did in #111), and both endpoints now call it; their responses and status codes are unchanged apart from extra ticket_id/replies_removed fields. - edit_comment: replace a comment's text (own comments; admins any). - delete_comment: delete a comment; replies go with it (fk_parent_comment ON DELETE CASCADE), so the result and the audit entry report replies_removed. - A comment on a ticket the user can't see reads as "Comment N not found", like a missing one, so restricted tickets stay hidden. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bdc6028572
commit
450b2fac3b
6 files changed
+209
-102
No files matched your search
+5
-50
@@ -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
|
||||
|
||||
Reference in new issue
Block a user