Repository navigation
feat(frontend): org conversation review screen over the gated, audited sessions API (#17832) #20547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2bd8741
e6f0903
fb282b5
04df9fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Copyright 2025-2026 mrveiss | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # AutoBot - AI-Powered Automation Platform | ||
| # Author: mrveiss | ||
| """Org conversation review audits every transcript open and stops at the org boundary (#17832). | ||
|
|
||
| The org-review screen only calls ``GET /chat/sessions/{id}``; the gate and the audit trail | ||
| are ``SessionOwnershipValidator``'s. These pin the two claims the screen relies on instead of | ||
| assuming them: an org admin opening a session in their own org writes a | ||
| ``conversation_accessed`` audit record naming them, and a session in another org is not | ||
| served and writes no success record. | ||
| """ | ||
|
|
||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from security.session_ownership import SessionOwnershipValidator | ||
|
|
||
| SESSION_ID = "0123456789abcdef0123456789abcdef" | ||
|
|
||
|
|
||
| def _validator(session_org: str) -> SessionOwnershipValidator: | ||
| validator = SessionOwnershipValidator.__new__(SessionOwnershipValidator) | ||
| validator.get_session_context = AsyncMock(return_value={"org_id": session_org}) | ||
| validator.is_shared_with_user = AsyncMock(return_value=False) | ||
| validator._handle_unauthorized_access = AsyncMock(return_value={"authorized": False}) | ||
| return validator | ||
|
|
||
|
|
||
| async def _open(validator: SessionOwnershipValidator, role: str, org_id: str): | ||
| audit = MagicMock() | ||
| middleware = MagicMock() | ||
| middleware.security_layer.audit_log = audit | ||
| request = MagicMock() | ||
| request.client.host = "203.0.113.7" | ||
| enforcement = MagicMock(mode="enforced") | ||
| user = {"username": "reviewer", "user_id": "u-1", "role": role, "org_id": org_id} | ||
| with patch("security.session_ownership.get_auth_middleware", return_value=middleware): | ||
| result = await validator._check_ownership_mismatch( | ||
| "reviewer", SESSION_ID, "someone-else", user, request, enforcement | ||
| ) | ||
| return result, audit | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.parametrize("role", ["admin", "org_admin"]) | ||
| async def test_org_admin_open_is_audit_logged_with_the_reviewer(role): | ||
| result, audit = await _open(_validator("org-1"), role, "org-1") | ||
|
|
||
| assert result["authorized"] is True | ||
| assert result["reason"] == "org_admin" | ||
| audit.assert_called_once() | ||
| kwargs = audit.call_args.kwargs | ||
| assert kwargs["action"] == "conversation_accessed" | ||
| assert kwargs["user"] == "reviewer" | ||
| assert kwargs["outcome"] == "success" | ||
| assert kwargs["details"]["session_id"].startswith(SESSION_ID[:16]) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_a_session_in_another_org_is_not_served_and_not_logged_as_a_success(): | ||
| validator = _validator("org-2") | ||
| result, audit = await _open(validator, "admin", "org-1") | ||
|
|
||
| assert result == {"authorized": False} | ||
| validator._handle_unauthorized_access.assert_awaited_once() | ||
| assert all(call.kwargs.get("action") != "conversation_accessed" for call in audit.call_args_list) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_a_non_admin_role_is_not_served_even_inside_its_own_org(): | ||
| validator = _validator("org-1") | ||
| result, audit = await _open(validator, "user", "org-1") | ||
|
|
||
| assert result == {"authorized": False} | ||
| assert all(call.kwargs.get("action") != "conversation_accessed" for call in audit.call_args_list) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright 2025-2026 mrveiss | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // AutoBot - AI-Powered Automation Platform | ||
| // Author: mrveiss | ||
| /** | ||
| * Org-scoped conversation review (#17832). | ||
| * | ||
| * Two existing, server-gated reads, typed from the generated contract (`paths`): | ||
| * - `GET /api/chat/sessions?scope=org` the caller's own organization's sessions | ||
| * - `GET /api/chat/sessions/{session_id}` one transcript, page by page | ||
| * The server is the authority for both: the list refuses a caller without an | ||
| * administrative role, a transcript is served only when the session's org matches | ||
| * the caller's, and every transcript open is written to the audit trail by | ||
| * `SessionOwnershipValidator`. This module adds no access of its own. | ||
| */ | ||
| import type { paths } from '@/types/generated/api' | ||
| import { useApiClient } from '@/plugins/api' | ||
| import { getApiBase } from '@/config/ssot-config' | ||
|
|
||
| type Body<P extends keyof paths> = paths[P] extends { | ||
| get: { responses: { 200: { content: { 'application/json': infer J } } } } | ||
| } | ||
| ? J | ||
| : never | ||
|
|
||
| const SESSIONS_PATH = '/api/chat/sessions' as const | ||
| const SESSION_PATH = '/api/chat/sessions/{session_id}' as const | ||
|
|
||
| /** The contract path, rebased on the configured API base (the SSOT, never a literal). */ | ||
| const url = (contractPath: string): string => `${getApiBase()}${contractPath.slice('/api'.length)}` | ||
|
|
||
| export type OrgSessionsResponse = Body<typeof SESSIONS_PATH> | ||
| export type TranscriptResponse = Body<typeof SESSION_PATH> | ||
| export type OrgSessionsData = NonNullable<OrgSessionsResponse['data']> | ||
| export type OrgSession = OrgSessionsData['sessions'][number] | ||
| export type TranscriptData = NonNullable<TranscriptResponse['data']> | ||
| export type TranscriptMessage = TranscriptData['messages'][number] | ||
|
|
||
| /** Messages per transcript page; the backend accepts a caller-chosen size. */ | ||
| export const TRANSCRIPT_PAGE_SIZE = 50 | ||
|
|
||
| export function useOrgConversationReview() { | ||
| const api = useApiClient() | ||
|
|
||
| async function listOrgSessions(): Promise<OrgSessionsData | null> { | ||
| const body = (await api.get(`${url(SESSIONS_PATH)}?scope=org`)) as OrgSessionsResponse | ||
| return body?.data ?? null | ||
| } | ||
|
|
||
| async function openTranscript(sessionId: string, page: number): Promise<TranscriptData | null> { | ||
| const path = SESSION_PATH.replace('{session_id}', encodeURIComponent(sessionId)) | ||
| const query = `page=${page}&per_page=${TRANSCRIPT_PAGE_SIZE}` | ||
| const body = (await api.get(`${url(path)}?${query}`)) as TranscriptResponse | ||
| return body?.data ?? null | ||
| } | ||
|
|
||
| return { listOrgSessions, openTranscript } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,14 @@ export const adminChildren: RouteRecordRaw[] = [ | |
| component: () => import('@/views/AdminMcpServersView.vue'), | ||
| meta: adminMeta('MCP Servers'), | ||
| }, | ||
| { | ||
| path: 'conversations', // Issue #17832: org-scoped conversation review (server-gated, audited) | ||
| name: 'admin-conversations', | ||
| component: () => import('@/views/AdminConversationsView.vue'), | ||
| meta: adminMeta('Conversation Review', { | ||
| description: 'Review conversations in your organization', | ||
|
Comment on lines
+105
to
+106
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }), | ||
| }, | ||
| { | ||
| path: 'permission-scopes', // Issue #16825: "coming later" panel | ||
| name: 'admin-permission-scopes', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not state that a transcript open is recorded during loading or after a failed read.
The notice at
AdminConversationsView.vue:185renders outside every condition. It appears while the transcript loads and after refused, failed, and missing reads. Some of these reads can end before any audit call. For example, the authentication check that returns 401 runs before the audit call. The notice still says the open was recorded. A successful read also does not confirm a durable record, so the wording must not promise one in any state.Replace the string with wording that does not claim a completed record:
Suggested fix
Committable suggestion