Skip to content

Mount optional public routes by switch, staff-only customer guards, scheduler heartbeat - #194

Merged
mpge merged 5 commits into
mainfrom
fix/ecom-core-reported-bugs
Nov 25, 2026
Merged

mpge merged 5 commits into
mainfrom
fix/ecom-core-reported-bugs

Conversation

@mpge

@mpge mpge commented Nov 25, 2026

Copy link
Copy Markdown
Member

Fixes from the bug list an Escalated host (ecom-core) reported against escalated-laravel 1.9.17, mapped to this port.

B1. Ticket subjects on the ticket pages: already fixed

AgentUiPages#show already puts ticket.subjects from TicketSubjectService#serializeForTicket (src/main/java/dev/escalated/ui/AgentUiPages.java:177). The agent API resource uses the same serializer (TicketService.java:168), and the admin page builds on the agent page (AdminTicketUiPages.java:82). Added a regression test (AdminTicketInertiaPagesTest#bothTicketPagesCarryTheSubjectsAsTheApiSerialisesThem) that compares both pages with GET /escalated/api/agent/tickets/{id}.

B2. Optional public routes only when their feature is on: fixed

  • Widget: escalated.widget.enabled (default true, env ESCALATED_WIDGET_ENABLED) already existed but only refused each request with 403. With it false, no /escalated/api/widget/** route is registered at all now (WidgetRoutesCondition on every widget controller). WidgetAvailabilityInterceptor still answers 403 {"enabled": false} under the prefix, so clients see the same answer as before.
  • Guest portal: new escalated.guest.routes-enabled (default true, falls back to env ESCALATED_GUEST_ROUTES). False registers neither the guest pages (/escalated/guest/**) nor /escalated/api/guest/**. The runtime guest_tickets_enabled setting still works while they are mounted. The mobile guest API is a separate surface and is unaffected.
  • Verification and lookup used to be one controller for both prefixes. The widget prefix moves to WidgetVerificationController, and both controllers delegate to a new GuestVerificationEndpoints, which MobileGuestController now uses.
  • Slack inbound: N/A. This port has no Slack integration (no Slack routes or config; the only mention is a plugin slug in PluginSlugs.java).
  • Cloud webhook: N/A. This port has no cloud/hosted mode and no cloud-to-site webhook route.
  • The default route snapshot (src/test/resources/embed/default-routes.json) changes only for the two widget verification handler names and the new scheduler status route. Gates, chains and filters are unchanged.
  • Tests: PublicRouteSwitchesTest (defaults mounted; env fallback), GuestRoutesSwitchedOffTest, WidgetDisabledTest#noWidgetRouteIsRegistered (plus the bundle, verification and lookup added to its 403 list).

B3. Staff-only installs: fixed

New escalated.routes.customer-middleware (default empty). It is applied in the Spring Security chains to the customer pages, /escalated/api/customer/** and the customer knowledge base (/escalated/kb/**). Each entry is escalated-agent or escalated-admin (Escalated's gates), or the bean name of the host's AuthorizationManager<RequestAuthorizationContext>. A request must be signed in and pass every entry: a signed-in user who fails gets 403, and anyone else goes to the host's sign-in entry point. An unknown name fails at start-up. With the list empty the chains are exactly as before, which the route snapshot confirms. docs/getting-started.md has a "A staff-only install" section that combines it with the B2 switches. Tests: CustomerMiddlewareTest; PublicRouteSwitchesTest#anySignedInUserStillReachesTheCustomerRoutesByDefault.

B4. Recurring jobs: fixed (heartbeat and warning); auto-registration already present

  • The jobs already run in-process: @EnableScheduling on EscalatedAutoConfiguration (EscalatedAutoConfiguration.java:40) and @Scheduled on SlaScheduler#checkSlaBreaches, AutomationScheduler#runAutomations and #autoCloseResolvedTickets, and SnoozeScheduler#wakeUpSnoozedTickets. Nothing to add.
  • Heartbeat: each SlaScheduler#checkSlaBreaches run writes the scheduler_heartbeat_at setting, in the settings table this port already uses for runtime state.
  • Warning, following the shared contract: a scheduler prop {healthy, last_run_at, message, commands: [{command, interval}]} on Escalated/Admin/Settings, Escalated/Admin/Reports and Escalated/Admin/Reports/Dashboard. healthy is false when the heartbeat is missing or more than 15 minutes old, and the message and commands then name each job and its interval. API-only installs get the same object at GET /escalated/api/admin/settings/scheduler (admin, settings.view). A warning is logged once per outage, then at most every 15 minutes.
  • Docs: "Required: schedule the recurring jobs" in docs/getting-started.md, with a pointer in the README.
  • Tests: SchedulerHeartbeatTest (the scheduled run writes the heartbeat; missing, stale and recent heartbeats; the props on all three pages; the API; the log warning).

B5. Unclear failure when the host user is not set up: N/A

This port has no host user type to implement. The caller is Spring Security's Authentication, matched by principal name to escalated_agent_profiles or to the ROLE_ESCALATED_ADMIN/ROLE_ESCALATED_AGENT authorities (EscalatedAuthorization.java:69-98). Nothing casts the principal (no getPrincipal() in src/main). A user with neither a profile nor a role fails the gate with 403, not a type error. Staff actions with no profile resolve agentId to null and carry on (for example TicketWritesController.java:218,238). There is also no install or status command to add a setup check to.

Verification

./gradlew checkstyleMain checkstyleTest test locally (H2, JDK 21 compiling to 17): 1102 tests. The only failure before the snapshot update was the expected route-table diff, and DefaultRouteTableTest passes after it.

mpge added 5 commits November 25, 2026 00:00
escalated.widget.enabled=false (ESCALATED_WIDGET_ENABLED) now registers no
/escalated/api/widget/** route at all instead of mounting every route and
refusing each request; WidgetAvailabilityInterceptor still answers 403
{"enabled": false} under the prefix, so clients see the same answer.

escalated.guest.routes-enabled (default true, falling back to
ESCALATED_GUEST_ROUTES) does the same for the guest portal: the guest pages
under /escalated/guest and /escalated/api/guest/**. The guest_tickets_enabled
setting keeps switching guest tickets at runtime while they are mounted. The
mobile guest API is not part of the portal and is unaffected.

Verification and lookup were one controller serving both prefixes; the
widget prefix moves to WidgetVerificationController and both delegate to
GuestVerificationEndpoints, which the mobile guest API now uses too.

Also adds the escalated.routes.customer-middleware property, used by the
next commit.
The customer pages, /escalated/api/customer/** and the customer knowledge
base accepted any signed-in user, so on an install only staff use, someone
never given Escalated access could still list and raise tickets.

Each entry is escalated-agent or escalated-admin (Escalated's own gates) or
the bean name of the host's AuthorizationManager<RequestAuthorizationContext>;
a request must be signed in and pass every one. Applied in the security
chains, so a signed-in user who fails gets 403 and anyone else the host's
sign-in entry point. Empty by default, which leaves the chains as they were.
An unknown name fails at start-up.
The SLA sweep records a heartbeat (the scheduler_heartbeat_at setting) each
run. When it is missing or more than 15 minutes old, the scheduler prop
{healthy, last_run_at, message, commands: [{command, interval}]} on
Escalated/Admin/Settings, Escalated/Admin/Reports and
Escalated/Admin/Reports/Dashboard says so and names each job and its
interval; GET /escalated/api/admin/settings/scheduler returns the same object
for API-only installs, and a warning is logged once per outage, then at most
every 15 minutes.

The jobs themselves were already registered in-process with @scheduled.
Both show pages already carry ticket.subjects; the test compares them with
the agent API's ticket resource so they cannot drift.
@mpge
mpge merged commit 3dcb76e into main Nov 25, 2026
4 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