Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(show-pages): honor resource access managers

Maxc5cca20b7625
diff --git a/tests/scenarios/auth_setup/catalog.yaml b/tests/scenarios/auth_setup/catalog.yaml
index 6dce75fe6..e3c3c5bba 100644
--- a/tests/scenarios/auth_setup/catalog.yaml
+++ b/tests/scenarios/auth_setup/catalog.yaml
@@ -190,12 +190,12 @@ scenarios:
backend: cloud_management
test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::OrganizationManagementAuthScenarioTests::test_unbound_loopback_requires_interactive_sign_in
- id: AUTH-SETUP-310
- name: Organization subject mismatch can re-enter explicit authorization with a clean return path
+ name: Organization subject mismatch can re-enter explicit authorization and return to the initiating workbench route
status: covered
kind: retry
layer: scenario
backend: cloud_management
- test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::OrganizationManagementAuthScenarioTests::test_subject_mismatch_can_reenter_with_clean_return_path
+ test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::OrganizationManagementAuthScenarioTests::test_subject_mismatch_can_reenter_with_workbench_return_path
- id: AUTH-SETUP-901
name: Codex setup success refreshes runtime before the next turn
status: covered
diff --git a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
index fad9b0036..bab005a73 100644
--- a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
+++ b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
@@ -245,7 +245,7 @@ class OrganizationManagementAuthScenarioTests(unittest.TestCase):
},
)
- def test_subject_mismatch_can_reenter_with_clean_return_path(self):
+ def test_subject_mismatch_can_reenter_with_workbench_return_path(self):
"""Scenario: AUTH-SETUP-310"""
client = self.harness.remote_client()
client.set_cookie(cloud_management.BROWSER_COOKIE_NAME, "browser-1", domain="alex.avibe.bot")
@@ -268,7 +268,7 @@ class OrganizationManagementAuthScenarioTests(unittest.TestCase):
mismatch.headers["location"],
)
- clean_next = "/admin/organization/overview"
+ clean_next = "/chat/session-1?tab=show-page"
with patch.object(
cloud_management,
"begin_authorization",
diff --git a/tests/test_cloud_management.py b/tests/test_cloud_management.py
index e08ee8155..a08d5812d 100644
--- a/tests/test_cloud_management.py
+++ b/tests/test_cloud_management.py
@@ -85,6 +85,25 @@ def _grant(browser_id: str = "browser-1", *, subject: str = "user-1") -> cloud_m
)
+ ("candidate", "expected"),
+ [
+ ("/chat/session-1?tab=show-page", "/chat/session-1?tab=show-page"),
+ ("/admin/organization/members?tab=access", "/admin/organization/members?tab=access"),
+ ("https://example.com/chat/session-1", "/admin/organization/overview"),
+ ("//example.com/chat/session-1", "/admin/organization/overview"),
+ ("/admin/organization-impersonation", "/admin/organization/overview"),
+ ("/chat/session-1/extra", "/admin/organization/overview"),
+ ("/api/show-pages/session-1/access", "/admin/organization/overview"),
+ ],
+)
+def test_management_return_path_allows_only_supported_same_origin_workflows(
+ candidate: str,
+ expected: str,
+) -> None:
+ assert cloud_management.validate_next_path(candidate) == expected
+
+
def test_local_start_uses_https_handoff_and_never_exposes_token(monkeypatch, tmp_path) -> None:
_save_config(monkeypatch, tmp_path)
captured: dict[str, object] = {}
diff --git a/tests/test_instance_authorization.py b/tests/test_instance_authorization.py
index 8439cd96b..2cee48303 100644
--- a/tests/test_instance_authorization.py
+++ b/tests/test_instance_authorization.py
@@ -93,6 +93,10 @@ def test_http_policy_defaults_unknown_api_to_owner() -> None:
assert required_instance_role("POST", "/api/vault/secrets") == "owner"
assert required_instance_role("POST", "/api/skills") == "owner"
assert required_instance_role("GET", "/api/show-pages") == "viewer"
+ assert required_instance_role("POST", "/api/show-pages/ses-1/visibility") == "viewer"
+ assert required_instance_role("POST", "/api/show-pages/ses-1/rotate-share") == "viewer"
+ assert required_instance_role("POST", "/api/show-pages/ses-1/share-id") == "viewer"
+ assert required_instance_role("POST", "/api/show-pages/ses-1/ensure") == "owner"
assert required_instance_role("GET", "/api/config") == "viewer"
assert required_instance_role("GET", "/api/workbench/prefs") == "viewer"
assert required_instance_role("PUT", "/api/workbench/prefs") == "owner"
diff --git a/tests/test_resource_acl_show_pages.py b/tests/test_resource_acl_show_pages.py
index c3d8c0598..4f4ec6cb2 100644
--- a/tests/test_resource_acl_show_pages.py
+++ b/tests/test_resource_acl_show_pages.py
@@ -272,8 +272,68 @@ def test_remote_show_page_owner_can_control_sharing_without_instance_owner_role(
store.close()
+def test_remote_show_page_owner_mutations_reach_resource_acl_as_viewer(monkeypatch, tmp_path) -> None:
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ store = ShowPageStore()
+ project_path = tmp_path / "project"
+ project_path.mkdir()
+ with store.engine.begin() as connection:
+ project = projects_service.create_project(connection, str(project_path))
+ session = sessions_service.create_session(
+ connection,
+ scope_id=project["scope_id"],
+ agent_backend="codex",
+ )
+ session_id = session["id"]
+ store.ensure(session_id)
+ with store.engine.begin() as connection:
+ resource_access_service.ensure_resource_policy(
+ connection,
+ resource_kind="show_page",
+ resource_id=session_id,
+ organization_id="org-1",
+ owner_user_id="owner-1",
+ access_level="private",
+ )
+ store.close()
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ _organization_cookie(config, subject="owner-1", groups=[], instance_role="viewer"),
+ domain="alex.avibe.bot",
+ )
+ request_options = {
+ "headers": csrf_headers(client, "https://alex.avibe.bot"),
+ "base_url": "https://alex.avibe.bot",
+ "environ_base": _remote_peer(),
+ }
+
+ published = client.post(
+ f"/api/show-pages/{session_id}/visibility",
+ json={"visibility": "public"},
+ **request_options,
+ )
+ rotated = client.post(
+ f"/api/show-pages/{session_id}/rotate-share",
+ json={},
+ **request_options,
+ )
+ customized = client.post(
+ f"/api/show-pages/{session_id}/share-id",
+ json={"share_id": "viewer-owner-link"},
+ **request_options,
+ )
+
+ assert published.status_code == 200
+ assert rotated.status_code == 200
+ assert customized.status_code == 200
+ assert customized.get_json()["share_id"] == "viewer-owner-link"
+
+
def test_organization_admin_can_read_show_page_access_metadata_without_use_access(monkeypatch, tmp_path) -> None:
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ _save_config(tmp_path)
store = _seed_show_pages_with_policies()
store.close()
admin = _organization_context(
@@ -287,6 +347,8 @@ def test_organization_admin_can_read_show_page_access_metadata_without_use_acces
payload = api.get_show_page_access("ses-scope")
assert payload["access_level"] == "scope"
+ assert payload["instance_id"] is None
+ assert payload["can_use"] is False
assert payload["can_manage"] is True
assert payload["can_publish_public"] is False
@@ -333,6 +395,7 @@ def test_show_page_access_api_distinguishes_personal_and_organization_modes(monk
"group_ids": [],
"policy_revision": None,
"last_applied_control_plane_revision": None,
+ "can_use": True,
"can_manage": True,
"can_publish_public": True,
"public_link_enabled": False,
@@ -356,6 +419,13 @@ def test_show_page_access_api_distinguishes_personal_and_organization_modes(monk
)
finally:
store.close()
+ local_organization = app.test_client().get(
+ "/api/show-pages/ses-organization/access",
+ base_url="http://127.0.0.1:15131",
+ )
+ assert local_organization.status_code == 200
+ assert local_organization.get_json()["instance_id"] == "inst_123"
+
client = app.test_client()
client.set_cookie(
remote_access.SESSION_COOKIE_NAME,
@@ -377,6 +447,7 @@ def test_show_page_access_api_distinguishes_personal_and_organization_modes(monk
"group_ids": ["group-engineering"],
"policy_revision": 4,
"last_applied_control_plane_revision": 4,
+ "can_use": True,
"can_manage": True,
"can_publish_public": True,
"public_link_enabled": False,
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index deb5650ff..035de5f90 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -17,6 +17,10 @@ import { isNotifyMessageType, isTerminalAgentMessage } from '../../lib/chatMessa
import { useIosKeyboardInset } from '../../lib/useIosKeyboardInset';
import { isProxyMediaUrl } from '../../lib/mediaProxy';
import { localPath, type ShowPageLinkInfo } from '../../lib/showPageLinks';
+import {
+ showPageHeaderAccess,
+ type ShowPageAccess,
+} from '../../lib/showPageAccess';
import { formatLocalDateTime, formatRelativeTime } from '../../lib/relativeTime';
import {
activityItemKind,
@@ -156,7 +160,18 @@ export const ChatPage: React.FC = () => {
const { capabilities } = useInstanceAuthorization();
const [sessionCanChat, setSessionCanChat] = useState(false);
const canChat = capabilities.can_chat && sessionCanChat;
- const canManageShowPage = capabilities.can_manage_instance;
+ const [showPageAccessResult, setShowPageAccessResult] = useState<{
+ sessionId: string;
+ access: ShowPageAccess | null;
+ } | null>(null);
+ const showPageAccess = capabilities.can_use_show_pages
+ && showPageAccessResult?.sessionId === sessionId
+ ? showPageAccessResult?.access ?? null
+ : null;
+ const { canOpen: canOpenShowPage, canManage: canManageShowPage } = showPageHeaderAccess(
+ capabilities.can_manage_instance,
+ showPageAccess,
+ );
const { unreadBySession, markRead: markInboxRead } = useWorkbenchInbox();
// The mobile chat surface is a fixed full-screen flex column; this keeps the
// composer glued to the iOS keyboard (settle-then-correct; see the hook).
@@ -202,6 +217,19 @@ export const ChatPage: React.FC = () => {
// show the stale enabled/mode and could send control messages to the freshly
// remounted overlay before it rebroadcasts. Re-points reset via the URL change.
const annotation = useShowPageAnnotation(showPageMode ? showPageUrl : null);
+ useEffect(() => {
+ let cancelled = false;
+ if (!sessionId || !capabilities.can_use_show_pages) return undefined;
+ void api.probeShowPageAccess(sessionId).then((nextAccess) => {
+ if (!cancelled) setShowPageAccessResult({ sessionId, access: nextAccess });
+ }).catch(() => {
+ if (!cancelled) setShowPageAccessResult({ sessionId, access: null });
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [api, capabilities.can_use_show_pages, sessionId]);
+
useEffect(() => {
// ChatPage is reused across :sessionId — clear all show-page state so the
// next chat starts in chat view with a live (not stuck-busy) toggle.
@@ -1334,7 +1362,7 @@ export const ChatPage: React.FC = () => {
setShowPageMode(false);
return;
}
- if (!canManageShowPage) return;
+ if (!canOpenShowPage) return;
setShowPageBusy(true);
try {
const res = await api.ensureShowPage(sid);
@@ -1370,7 +1398,7 @@ export const ChatPage: React.FC = () => {
// strand the shared busy flag on a session the user switched to).
setShowPageBusy(false);
}
- }, [sessionId, showPageMode, canManageShowPage, api, sendMessage, t]);
+ }, [sessionId, showPageMode, canOpenShowPage, api, sendMessage, t]);
// When the share control resolves the page (open) or flips its visibility, the
// serving route changes (private → /show/, public → /p/). Re-point the iframe
@@ -1859,6 +1887,8 @@ export const ChatPage: React.FC = () => {
annotation={annotation}
onAnnotateOpenChange={setAnnotateOpen}
readOnly={!canChat}
+ showPageAccess={showPageAccess}
+ canOpenShowPage={canOpenShowPage}
canManageShowPage={canManageShowPage}
/>
@@ -2338,10 +2368,12 @@ interface ChatHeaderBarProps {
annotation: AnnotationBridge;
onAnnotateOpenChange?: (open: boolean) => void;
readOnly: boolean;
+ showPageAccess: ShowPageAccess | null;
+ canOpenShowPage: boolean;
canManageShowPage: boolean;
}
-const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultAgentName, onPatch, onBack, working, showPageMode, showPageBusy, onToggleShowPage, onShowPageVisibilityChange, onShareOpenChange, annotation, onAnnotateOpenChange, readOnly, canManageShowPage }) => {
+const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultAgentName, onPatch, onBack, working, showPageMode, showPageBusy, onToggleShowPage, onShowPageVisibilityChange, onShareOpenChange, annotation, onAnnotateOpenChange, readOnly, showPageAccess, canOpenShowPage, canManageShowPage }) => {
const { t } = useTranslation();
const defaultAgent = defaultAgentName ? agents.find((agent) => agent.name === defaultAgentName) : null;
// Backend locks once a NATIVE conversation exists — a native can only be
@@ -2428,9 +2460,9 @@ const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultA
back-to-chat button. */}
{/* In Show Page mode the order is: annotation control · back-to-chat ·
Share. The annotation control sits immediately left of back-to-chat;
- the Share control stays rightmost. In chat mode only the Visualize
- toggle shows. */}
- {(showPageMode || canManageShowPage) && <div className="ml-auto flex items-center gap-1.5">
+ the Share control stays rightmost. In chat mode resource managers can
+ open Share without receiving access to the page content. */}
+ {(showPageMode || canOpenShowPage || canManageShowPage) && <div className="ml-auto flex items-center gap-1.5">
{showPageMode && !readOnly && (
<ShowPageAnnotateControl
state={annotation.state}
@@ -2440,7 +2472,7 @@ const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultA
onPopoverOpenChange={onAnnotateOpenChange}
/>
)}
- <Button
+ {(showPageMode || canOpenShowPage) && <Button
type="button"
variant={showPageMode ? 'secondary' : 'ghost'}
onClick={onToggleShowPage}
@@ -2459,10 +2491,11 @@ const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultA
<span className="hidden text-xs font-medium md:inline">
{showPageMode ? t('chat.showPage.backToChat') : t('chat.showPage.open')}
</span>
- </Button>
- {showPageMode && canManageShowPage && (
+ </Button>}
+ {canManageShowPage && (showPageMode || showPageAccess) && (
<ShowPageShareControl
sessionId={session.id}
+ initialAccess={showPageAccess}
onPayloadChange={onShowPageVisibilityChange}
onOpenChange={onShareOpenChange}
/>
diff --git a/ui/src/components/workbench/ShowPageShareControl.tsx b/ui/src/components/workbench/ShowPageShareControl.tsx
index 5b38ed3da..3f2b95728 100644
--- a/ui/src/components/workbench/ShowPageShareControl.tsx
+++ b/ui/src/components/workbench/ShowPageShareControl.tsx
@@ -28,11 +28,12 @@ type ShowPagePayload = ShowPageLinkInfo & {
title?: string | null;
};
-// Share affordance shown only while the Show Page is open (the in-chat view).
-// A popover with authenticated audience controls, an independent anonymous
-// public-link switch, and link actions for the current serving route.
+// Share affordance for the current session's Show Page. Resource managers may
+// open the audience controls without receiving access to the page content;
+// public-link and link actions render only when the caller can use the page.
export const ShowPageShareControl: React.FC<{
sessionId: string;
+ initialAccess?: ShowPageAccess | null;
// Lets the chat view re-point the iframe at the route that now serves the
// page when visibility flips (private↔public swap the serving route).
onPayloadChange?: (payload: ShowPageLinkInfo) => void;
@@ -40,7 +41,7 @@ export const ShowPageShareControl: React.FC<{
// inert while it is open so an outside tap there falls through to the parent
// document and Radix can dismiss (a tap inside an iframe never reaches us).
onOpenChange?: (open: boolean) => void;
-}> = ({ sessionId, onPayloadChange, onOpenChange }) => {
+}> = ({ sessionId, initialAccess = null, onPayloadChange, onOpenChange }) => {
const { t } = useTranslation();
const api = useApi();
const dock = useDock();
@@ -48,7 +49,7 @@ export const ShowPageShareControl: React.FC<{
const inventoryPage = pages.find((page) => page.session_id === sessionId);
const [open, setOpen] = useState(false);
const [localPayload, setLocalPayload] = useState<ShowPagePayload | null>(null);
- const payload = useMemo<ShowPagePayload | null>(() => {
+ const candidatePayload = useMemo<ShowPagePayload | null>(() => {
const local = localPayload?.session_id === sessionId ? localPayload : null;
if (!inventoryPage) return local;
if (!local) return inventoryPage as ShowPagePayload;
@@ -69,7 +70,8 @@ export const ShowPageShareControl: React.FC<{
}, [inventoryPage, localPayload, sessionId]);
const [loading, setLoading] = useState(false);
const [accessLoading, setAccessLoading] = useState(false);
- const [access, setAccess] = useState<ShowPageAccess | null>(null);
+ const [access, setAccess] = useState<ShowPageAccess | null>(initialAccess);
+ const payload = access?.can_use === false ? null : candidatePayload;
const [accessError, setAccessError] = useState(false);
const [busy, setBusy] = useState(false);
const [copied, setCopied] = useState(false);
@@ -104,9 +106,9 @@ export const ShowPageShareControl: React.FC<{
useEffect(() => () => onOpenChange?.(false), [onOpenChange]);
useEffect(() => {
- setAccess(null);
+ setAccess(initialAccess);
setAccessError(false);
- }, [sessionId]);
+ }, [initialAccess, sessionId]);
const offline = payload?.visibility === 'offline' || payload?.offline === true;
const isPublic = payload?.visibility === 'public';
@@ -129,19 +131,24 @@ export const ShowPageShareControl: React.FC<{
// refreshing so reopening doesn't flash a spinner.
const refresh = () => {
const seq = ++reqSeq.current;
- setLoading(!payload);
+ const canLoadPayload = access?.can_use !== false;
+ setLoading(canLoadPayload && !payload);
setAccessLoading(!access);
setAccessError(false);
void (async () => {
- try {
- const res: ShowPagePayload = await api.ensureShowPage(sessionId);
- if (seq !== reqSeq.current) return;
- applyPayload(res);
- if (!inventoryPage) reload();
- } catch {
- // An archived Show Page cannot be ensured, but its applied access
- // metadata is still useful and is loaded below.
- } finally {
+ if (canLoadPayload) {
+ try {
+ const res: ShowPagePayload = await api.ensureShowPage(sessionId);
+ if (seq !== reqSeq.current) return;
+ applyPayload(res);
+ if (!inventoryPage) reload();
+ } catch {
+ // An archived Show Page cannot be ensured, but its applied access
+ // metadata is still useful and is loaded below.
+ } finally {
+ setLoading(false);
+ }
+ } else {
setLoading(false);
}
@@ -228,14 +235,14 @@ export const ShowPageShareControl: React.FC<{
<PopoverContent align="end" className="w-80 space-y-3">
<div className="text-sm font-medium">{t('chat.showPage.shareTitle')}</div>
- {loading ? (
+ {loading && !access ? (
<div className="flex items-center gap-2 py-2 text-sm text-muted">
<Loader2 className="size-4 animate-spin" />
{t('common.loading')}
</div>
- ) : !payload ? (
+ ) : !payload && !access ? (
<p className="py-1 text-sm text-muted">{t('chat.showPage.loadError')}</p>
- ) : (
+ ) : payload ? (
<>
{offline ? (
<p className="py-1 text-sm text-muted">{t('chat.showPage.offlineNote')}</p>
@@ -291,19 +298,24 @@ export const ShowPageShareControl: React.FC<{
</div>
)}
- <div className="border-t border-border pt-3">
- <ShowPageWorkspaceAccessControl
- access={access}
- active={open}
- sessionId={sessionId}
- />
- {accessError ? (
- <p className="mt-2 text-[11px] leading-snug text-destructive">
- {t('chat.showPage.accessLoadError')}
- </p>
- ) : null}
- </div>
+ </>
+ ) : null}
+ <div className="border-t border-border pt-3">
+ <ShowPageWorkspaceAccessControl
+ access={access}
+ active={open}
+ sessionId={sessionId}
+ />
+ {accessError ? (
+ <p className="mt-2 text-[11px] leading-snug text-destructive">
+ {t('chat.showPage.accessLoadError')}
+ </p>
+ ) : null}
+ </div>
+
+ {payload ? (
+ <>
<div className="border-t border-border pt-3">
<div className="flex items-center justify-between gap-3">
<div className="min-w-0">
@@ -389,7 +401,7 @@ export const ShowPageShareControl: React.FC<{
</div>
) : null}
</>
- )}
+ ) : null}
{/* Pin to Dock — records the session's Show Page as a Dock app. Deliberately
OUTSIDE the visibility branches: pinning is independent of public/private
diff --git a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx
index 5415605cd..1e6ab0ce9 100644
--- a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx
+++ b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx
@@ -17,6 +17,7 @@ const access = (overrides: Partial<ShowPageAccess> = {}): ShowPageAccess => ({
group_ids: [],
policy_revision: 4,
last_applied_control_plane_revision: 4,
+ can_use: true,
can_manage: true,
can_publish_public: true,
public_link_enabled: false,
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsx
index 497f31ad5..06138609f 100644
--- a/ui/src/context/ApiContext.tsx
+++ b/ui/src/context/ApiContext.tsx
@@ -412,6 +412,7 @@ export type ApiContextType = {
removeUser: (userId: string, platform?: string) => Promise<any>;
getShowPages: () => Promise<any>;
getShowPageAccess: (sessionId: string) => Promise<ShowPageAccess>;
+ probeShowPageAccess: (sessionId: string) => Promise<ShowPageAccess | null>;
getWebPushStatus: (payload?: WebPushStatusPayload) => Promise<WebPushStatus>;
getWebPushVapidPublicKey: () => Promise<{ ok: boolean; public_key: string }>;
subscribeWebPush: (
@@ -2543,6 +2544,13 @@ export const ApiProvider: React.FC<{ children: React.ReactNode }> = ({ children
deleteJson(platform ? `/api/users/${encodeURIComponent(userId)}?platform=${encodeURIComponent(platform)}` : `/api/users/${encodeURIComponent(userId)}`),
getShowPages: () => getJson('/api/show-pages'),
getShowPageAccess: (sessionId) => getJson(`/api/show-pages/${encodeURIComponent(sessionId)}/access`),
+ probeShowPageAccess: async (sessionId) => {
+ const payload = await getJson(
+ `/api/show-pages/${encodeURIComponent(sessionId)}/access`,
+ { handleError: false },
+ );
+ return payload?.ok === true ? payload as ShowPageAccess : null;
+ },
getWebPushStatus: (payload) =>
payload ? postJson('/api/web-push/status', payload) : getJson('/api/web-push/status'),
getWebPushVapidPublicKey: () => getJson('/api/web-push/vapid-public-key'),
diff --git a/ui/src/lib/showPageAccess.test.ts b/ui/src/lib/showPageAccess.test.ts
index 2a534b12d..d0ac5db31 100644
--- a/ui/src/lib/showPageAccess.test.ts
+++ b/ui/src/lib/showPageAccess.test.ts
@@ -4,6 +4,7 @@ import { isRevisionConflict, OrganizationApiError } from '@/features/organizatio
import {
buildShowPageAccessPatch,
canChangeShowPagePublicLink,
+ showPageHeaderAccess,
showPageAudienceLabelKey,
showPageAudienceLevels,
showPageSyncPresentation,
@@ -19,6 +20,7 @@ const access = (overrides: Partial<ShowPageAccess> = {}): ShowPageAccess => ({
group_ids: [],
policy_revision: 4,
last_applied_control_plane_revision: 4,
+ can_use: true,
can_manage: true,
can_publish_public: true,
public_link_enabled: false,
@@ -65,6 +67,19 @@ describe('Show Page access policy helpers', () => {
expect(canChangeShowPagePublicLink(access(), true)).toBe(true);
});
+ it('separates page use from page-specific access management in the chat header', () => {
+ expect(showPageHeaderAccess(false, access({ can_use: true, can_manage: false }))).toEqual({
+ canOpen: true,
+ canManage: false,
+ });
+ expect(showPageHeaderAccess(false, access({ can_use: false, can_manage: true }))).toEqual({
+ canOpen: false,
+ canManage: true,
+ });
+ expect(showPageHeaderAccess(false, null)).toEqual({ canOpen: false, canManage: false });
+ expect(showPageHeaderAccess(true, null)).toEqual({ canOpen: true, canManage: true });
+ });
+
it('distinguishes pending, offline, and error sync states', () => {
expect(showPageSyncPresentation('pending')).toEqual({
key: 'chat.showPage.workspaceSync.pending',
diff --git a/ui/src/lib/showPageAccess.ts b/ui/src/lib/showPageAccess.ts
index 10e96f693..e9393598e 100644
--- a/ui/src/lib/showPageAccess.ts
+++ b/ui/src/lib/showPageAccess.ts
@@ -9,11 +9,22 @@ export type ShowPageAccess = {
group_ids: string[];
policy_revision: number | null;
last_applied_control_plane_revision: number | null;
+ can_use: boolean;
can_manage: boolean;
can_publish_public: boolean;
public_link_enabled: boolean;
};
+export function showPageHeaderAccess(
+ canManageInstance: boolean,
+ access: ShowPageAccess | null,
+): { canOpen: boolean; canManage: boolean } {
+ return {
+ canOpen: canManageInstance || access?.can_use === true,
+ canManage: canManageInstance || access?.can_manage === true,
+ };
+}
+
export type ShowPageAccessPatch = {
access_level: ResourceAccessLevel;
group_ids: string[];
diff --git a/vibe/api.py b/vibe/api.py
index 46b7e97b3..8876bed42 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -1270,10 +1270,13 @@ def get_show_page_access(session_id: str) -> dict:
store.close()
organization_id = policy.get("organization_id") if policy else None
+ instance_id = context.instance_id
+ if context.is_trusted_local and organization_id and not instance_id:
+ instance_id = V2Config.load().remote_access.vibe_cloud.instance_id or None
return {
"ok": True,
"mode": "organization" if organization_id else "personal",
- "instance_id": context.instance_id,
+ "instance_id": instance_id,
"organization_id": organization_id,
"access_level": policy.get("access_level", "private") if policy else "private",
"group_ids": list(policy.get("group_ids") or []) if policy else [],
@@ -1281,6 +1284,7 @@ def get_show_page_access(session_id: str) -> dict:
"last_applied_control_plane_revision": (
policy.get("last_applied_control_plane_revision") if policy else None
),
+ "can_use": can_use,
"can_manage": can_manage,
"can_publish_public": can_publish_public,
"public_link_enabled": page.visibility == "public",
diff --git a/vibe/authorization.py b/vibe/authorization.py
index 1068629ba..fdbbae73c 100644
--- a/vibe/authorization.py
+++ b/vibe/authorization.py
@@ -283,6 +283,15 @@ _VIEWER_HTTP_RULES = tuple(
)
)
+_VIEWER_HTTP_MUTATION_RULES = tuple(
+ (method, re.compile(pattern))
+ for method, pattern in (
+ ("POST", r"^/api/show-pages/[^/]+/visibility$"),
+ ("POST", r"^/api/show-pages/[^/]+/rotate-share$"),
+ ("POST", r"^/api/show-pages/[^/]+/share-id$"),
+ )
+)
+
_EDITOR_HTTP_RULES = tuple(
(method, re.compile(pattern))
for method, pattern in (
@@ -328,6 +337,12 @@ def required_instance_role(method: str, path: str) -> str | None:
return "viewer" if normalized_method in {"GET", "HEAD", "OPTIONS"} else "editor"
if not path.startswith("/api/"):
return None
+ # These routes enforce Show Page ownership and Organization authority in
+ # the resource service. The HTTP gate only admits an authenticated viewer
+ # so page-specific authorization can make the final decision.
+ for rule_method, pattern in _VIEWER_HTTP_MUTATION_RULES:
+ if normalized_method == rule_method and pattern.fullmatch(path):
+ return "viewer"
for rule_method, pattern in _EDITOR_HTTP_RULES:
if normalized_method == rule_method and pattern.fullmatch(path):
return "editor"
diff --git a/vibe/cloud_management.py b/vibe/cloud_management.py
index 079c525f2..bd1101989 100644
--- a/vibe/cloud_management.py
+++ b/vibe/cloud_management.py
@@ -12,6 +12,7 @@ import base64
import hashlib
import http.client
import json
+import re
import secrets
import threading
import time
@@ -144,7 +145,11 @@ def cloud_is_configured(config: V2Config | None) -> bool:
def validate_next_path(value: object) -> str:
path = str(value or "/admin/organization/overview")
parsed = urllib.parse.urlsplit(path)
- if parsed.scheme or parsed.netloc or not parsed.path.startswith("/admin/organization"):
+ is_organization_path = parsed.path == "/admin/organization" or parsed.path.startswith(
+ "/admin/organization/"
+ )
+ is_workbench_chat = re.fullmatch(r"/chat/[^/]+", parsed.path) is not None
+ if parsed.scheme or parsed.netloc or not (is_organization_path or is_workbench_chat):
return "/admin/organization/overview"
return urllib.parse.urlunsplit(("", "", parsed.path, parsed.query, ""))