Skip to content

Route the ticket page's End Chat button to a working endpoint - #220

Merged
mpge merged 1 commit into
mainfrom
fix/chat-end-ui-route
Oct 23, 2026
Merged

mpge merged 1 commit into
mainfrom
fix/chat-end-ui-route

Conversation

@mpge

@mpge mpge commented Oct 23, 2026

Copy link
Copy Markdown
Member

The agent ticket page (escalated PR #215) resolves route('escalated.admin.chat.end', ticket.chat_session_id) and, when it resolves, posts {} as JSON there on End Chat. This backend had no such name, so the button did nothing.

What changed

  • POST support/admin/chat/{session}/end (AdminChatPageController), staff only (the escalated-agent policy, as the existing agent chat API). Ends the chat and resolves its ticket through ChatSessionService.EndAsync. Answers 200 {message: "Chat ended."}, 422 {message: "Chat is already ended."} (escalated-laravel's response), 404 for an unknown session.
  • escalated.admin.chat.end -> {prefix}/admin/chat/{session}/end in UiRoutes.Defaults (Laravel's path).
  • The new route follows Escalated:RoutePrefix through a small MVC convention ([EscalatedPrefixedRoute]) that only touches controllers that opt in; every other controller keeps its hardcoded support/... route.
  • POST support/agent/chat/{sessionId}/end is untouched (still 400 when already ended).

Auth and CSRF

The UI and the API share the host's authentication; the policy reads HttpContext.User, so the agent's browser session authorizes the post. No Escalated write (including the UI ticket form posts) validates antiforgery tokens, so the X-CSRF-TOKEN header the page sends is accepted and not required, matching the other UI writes.

Tests

ChatEndRouteTests runs through the real pipeline: reads the route map off the agent ticket page's HTML, posts {} with the page's headers, checks the session ended and the ticket resolved, the 422 on a second post, a helpdesk prefix, 401/403/404, and that the old agent API still ends chats with its own responses. Full suite green on SQLite and PostgreSQL 17 (1029 tests); dotnet format --verify-no-changes clean.

Add POST support/admin/chat/{session}/end, named escalated.admin.chat.end,
which the agent ticket page posts {} to from the agent's signed-in session.
It answers 422 for an already-ended chat, as escalated-laravel does, and
follows Escalated:RoutePrefix. The agent chat API route is unchanged.
@mpge
mpge merged commit 171bdc4 into main Oct 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant