feat(tickets): wire team_id filter and team-scoped dashboard query #295
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/PMS-406-ticket-team-scope-filter"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Wire the existing but inert
tickets.team_idfilter into the WHERE builder so GET /api/v1/tickets?team_id= actually scopes the list, and add a team dimension to the operations dashboard so the full-screen TV-view (MAPPS-256) can request a single team's KPI set. The IT / HR / service-vendor split is modeled as distinctteamsrows, not a hardcoded enum.build_ticket_filter_sql now emits
t.team_id = $n(data and count queries) when TicketFilter.team_id is Some, and a "my teams" scope (my_teams flag) that restricts to the caller's team_members via a correlated subquery, so the frontend does not resolve team ids itself. The caller id is threaded into list_ticket_responses from RequireAuth; the portal path passes None.list_ticket_responses validates team_id belongs to the caller's tenant (validate_fk on teams) before binding, so a cross-tenant team id 4xx-rejects rather than silently returning a tenant-only list. The tenant predicate
t.tenant_id = $1stays the unconditional first condition; team scoping is additive only.ReportsService::dashboard takes an optional team_id and appends a parameterized
AND team_id = $nto all four aggregates (open_by_priority, sla_warnings, sla_breached, ticket_trend_30d); absent the param the output is unchanged. Surfaced as a query param on GET /reports/dashboard and the dashboard CSV export.Migration 054 adds idx_tickets_tenant_team on tickets(tenant_id, team_id) so the team-scoped list and dashboard queries stay fast. Integration test covers the team_id filter, cross-tenant rejection, and the my_teams union.
#PMS-406
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
2720fcae9e90e3717842