Phase 3.3 — Session Topic Sensitivity (complete): - Backend: topic_sensitivity column + session_sensitivity_log, sensitivity service (flip with one-way-latch + audit), PATCH /api/shared/chat/sessions/:id/topic, topic carried in pairing + extension WS payloads, CC filter + sensitive stats + per-mitra sensitive columns on activity page - client_app: TopicSelectionBottomSheet before pricing, topic flows through pairing request, silent WS handler for session_topic_updated - mitra_app: SensitivityBadge + SensitivityTheme + sensitivityConfigProvider, overlay badge + yellow accent, chat screen app-bar toggle with configurable confirmation + latch, extension card shows current flag, history + transcript yellow theme - control_center: Sensitivitas Topik settings section, topic filter + column with inline audit log, sensitive stats dashboard card, mitra activity sensitive columns with QC flag Phase 3.4 — Self-Managed Auth (foundation only): - Migration: auth_sessions + otp_requests tables, social identity columns on customers, password_hash + lockout on control_center_users, OTP + CC lockout app_config keys - New services: password (bcrypt + complexity), token (JWT HS256 + refresh rotation, session_id claim pre-wires future Valkey revocation), social-identity (Google + Apple JWKS), OTP (Fazpass stub — real API TBD) - Constants: AuthProvider + OtpChannel - Middleware, auth route rewrites, WS auth update, Firebase → FCM isolation still pending (next chunk); Fazpass docs + Apple Developer setup still required before E2E testing Docs: - requirement/phase3.3.md, phase3.3-plan.md, phase3.3-testing.md - requirement/phase3.4.md, phase3.4-plan.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
56 lines
2.4 KiB
JavaScript
56 lines
2.4 KiB
JavaScript
import { authenticate, requirePermission } from '../../plugins/auth.js'
|
|
import { getCcUserByFirebaseUid } from '../../services/cc-user.service.js'
|
|
import { listSessions, getSessionById, rerouteSession } from '../../services/session.service.js'
|
|
import { getSessionSensitivityLog } from '../../services/sensitivity.service.js'
|
|
import { getDashboardStats } from '../../services/dashboard.service.js'
|
|
|
|
const attachCcUser = async (request, reply) => {
|
|
const user = await getCcUserByFirebaseUid(request.firebaseUser.uid)
|
|
if (!user) return reply.code(403).send({ success: false, error: { code: 'FORBIDDEN', message: 'Not a control center user' } })
|
|
request.ccUser = user
|
|
}
|
|
|
|
export const sessionManagementRoutes = async (app) => {
|
|
app.get('/dashboard/stats', {
|
|
preHandler: [authenticate, attachCcUser, requirePermission('config', 'read')],
|
|
}, async (request, reply) => {
|
|
const stats = await getDashboardStats()
|
|
return reply.send({ success: true, data: stats })
|
|
})
|
|
|
|
app.get('/', {
|
|
preHandler: [authenticate, attachCcUser, requirePermission('config', 'read')],
|
|
}, async (request, reply) => {
|
|
const { page = 1, limit = 20, status, topic_sensitivity } = request.query
|
|
const result = await listSessions({
|
|
page: Number(page),
|
|
limit: Number(limit),
|
|
status,
|
|
topic_sensitivity: topic_sensitivity && topic_sensitivity !== 'all' ? topic_sensitivity : undefined,
|
|
})
|
|
return reply.send({ success: true, data: result })
|
|
})
|
|
|
|
app.get('/:sessionId', {
|
|
preHandler: [authenticate, attachCcUser, requirePermission('config', 'read')],
|
|
}, async (request, reply) => {
|
|
const session = await getSessionById(request.params.sessionId)
|
|
if (!session) {
|
|
return reply.code(404).send({ success: false, error: { code: 'NOT_FOUND', message: 'Session not found' } })
|
|
}
|
|
const sensitivity_log = await getSessionSensitivityLog(request.params.sessionId)
|
|
return reply.send({ success: true, data: { ...session, sensitivity_log } })
|
|
})
|
|
|
|
app.post('/:sessionId/reroute', {
|
|
preHandler: [authenticate, attachCcUser, requirePermission('config', 'update')],
|
|
}, async (request, reply) => {
|
|
const { new_mitra_id } = request.body ?? {}
|
|
if (!new_mitra_id) {
|
|
return reply.code(422).send({ success: false, error: { code: 'VALIDATION_ERROR', message: 'new_mitra_id is required' } })
|
|
}
|
|
const session = await rerouteSession(request.params.sessionId, new_mitra_id)
|
|
return reply.send({ success: true, data: session })
|
|
})
|
|
}
|