Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: handle no ai setting in agent chat (#21560)

ecmadao7f5af46ea15a
diff --git a/frontend/src/modules/agent/components/AgentChat.test.tsx b/frontend/src/modules/agent/components/AgentChat.test.tsx
index 20ff953d5d..f1a64b828e 100644
--- a/frontend/src/modules/agent/components/AgentChat.test.tsx
+++ b/frontend/src/modules/agent/components/AgentChat.test.tsx
@@ -2,6 +2,7 @@ import type { ReactElement } from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { beforeEach, describe, expect, test, vi } from "vitest";
+import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";
import { createAgentStore, useAgentStore } from "../store/agent";
(
@@ -14,6 +15,7 @@ const mocks = vi.hoisted(() => ({
})),
hasWorkspacePermissionV2: vi.fn(() => true),
routerPush: vi.fn(),
+ getSettingByName: vi.fn(),
}));
let AgentChat: typeof import("./AgentChat").AgentChat;
@@ -59,6 +61,14 @@ vi.mock("@/utils", () => ({
hasWorkspacePermissionV2: mocks.hasWorkspacePermissionV2,
}));
+vi.mock("@/stores/app", () => {
+ const state = { getSettingByName: mocks.getSettingByName };
+ const useAppStore = <T,>(selector: (value: typeof state) => T) =>
+ selector(state);
+ useAppStore.getState = () => state;
+ return { useAppStore };
+});
+
const renderIntoContainer = (element: ReactElement) => {
const container = document.createElement("div");
const root = createRoot(container);
@@ -100,11 +110,63 @@ beforeEach(async () => {
mocks.hasWorkspacePermissionV2.mockReset();
mocks.hasWorkspacePermissionV2.mockReturnValue(true);
mocks.routerPush.mockReset();
+ mocks.getSettingByName.mockReset();
+ mocks.getSettingByName.mockReturnValue(undefined);
({ AgentChat } = await import("./AgentChat"));
});
describe("AgentChat", () => {
+ test("shows AI setup when the cached AI setting is disabled", () => {
+ mocks.getSettingByName.mockImplementation((name) => {
+ if (name !== Setting_SettingName.AI) return undefined;
+ return {
+ value: {
+ value: {
+ case: "ai",
+ value: { enabled: false },
+ },
+ },
+ };
+ });
+
+ const { container, render, unmount } = renderIntoContainer(<AgentChat />);
+
+ render();
+
+ expect(container.textContent).toContain("agent.ai-not-configured.title");
+
+ const dismissButton = Array.from(container.querySelectorAll("button")).find(
+ (button) => button.textContent === "common.dismiss"
+ );
+ act(() => {
+ dismissButton?.click();
+ });
+ expect(container.textContent).not.toContain(
+ "agent.ai-not-configured.title"
+ );
+
+ unmount();
+ });
+
+ test("keeps assistant links within the chat bubble", () => {
+ useAgentStore.getState().addMessage({
+ role: "assistant",
+ content:
+ "Configure billing at https://platform.openai.com/settings/organization/billing/.",
+ });
+
+ const { container, render, unmount } = renderIntoContainer(<AgentChat />);
+
+ render();
+
+ const link = container.querySelector("a");
+ expect(link).toBeInstanceOf(HTMLElement);
+ expect(link?.className).toContain("break-all");
+
+ unmount();
+ });
+
test("renders inline code with wrap-safe styling", () => {
useAgentStore.getState().addMessage({
role: "assistant",
@@ -210,6 +272,7 @@ describe("AgentChat", () => {
test("routes AI configuration recovery to general settings with intro", () => {
const chat = useAgentStore.getState().ensureCurrentChat();
useAgentStore.setState((state) => ({
+ visible: true,
chats: state.chats.map((item) =>
item.id === chat.id ? { ...item, requiresAIConfiguration: true } : item
),
@@ -234,6 +297,7 @@ describe("AgentChat", () => {
hash: "#ai-assistant",
query: { intro: "ai-assistant" },
});
+ expect(useAgentStore.getState().visible).toBe(false);
unmount();
});
diff --git a/frontend/src/modules/agent/components/AgentChat.tsx b/frontend/src/modules/agent/components/AgentChat.tsx
index 05936ec726..7be7d45f97 100644
--- a/frontend/src/modules/agent/components/AgentChat.tsx
+++ b/frontend/src/modules/agent/components/AgentChat.tsx
@@ -1,4 +1,4 @@
-import { useEffect, useMemo, useRef } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm";
@@ -10,7 +10,10 @@ import {
AI_ASSISTANT_PRODUCT_INTRO,
PRODUCT_INTRO_QUERY_KEY,
} from "@/lib/productIntro";
+import { useAppStore } from "@/stores/app";
+import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";
import { hasWorkspacePermissionV2 } from "@/utils";
+import { getAgentAIConfigurationEnabled } from "../logic/aiConfiguration";
import type { AgentMessage, ToolCall } from "../logic/types";
import {
selectCurrentChatRequiresAIConfiguration,
@@ -28,17 +31,28 @@ interface AgentChatProps {
export function AgentChat({ className }: AgentChatProps) {
const { t } = useTranslation();
const chatContainerRef = useRef<HTMLDivElement>(null);
+ const [
+ isAIConfigurationRecoveryDismissed,
+ setAIConfigurationRecoveryDismissed,
+ ] = useState(false);
const messages = useAgentStore(selectMessages);
const loading = useAgentStore(selectLoading);
const error = useAgentStore(selectError);
- const showAIConfigurationRecovery = useAgentStore(
+ const chatRequiresAIConfiguration = useAgentStore(
selectCurrentChatRequiresAIConfiguration
);
const currentChatId = useAgentStore((s) => s.currentChatId);
+ const aiConfigurationEnabled = useAppStore((s) =>
+ getAgentAIConfigurationEnabled(s.getSettingByName(Setting_SettingName.AI))
+ );
const allMessages = useAgentStore(selectMessages);
const clearError = useAgentStore((s) => s.clearError);
+ const showAIConfigurationRecovery =
+ chatRequiresAIConfiguration ||
+ (aiConfigurationEnabled === false && !isAIConfigurationRecoveryDismissed);
+
const allowConfigure = hasWorkspacePermissionV2("bb.settings.set");
const displayMessages = useMemo(
@@ -96,9 +110,11 @@ export function AgentChat({ className }: AgentChatProps) {
function goConfigure() {
clearError(currentChatId);
+ useAgentStore.getState().toggle();
}
function dismiss() {
+ setAIConfigurationRecoveryDismissed(true);
clearError(currentChatId);
}
@@ -109,6 +125,10 @@ export function AgentChat({ className }: AgentChatProps) {
}
}, [currentChatId, messages.length]);
+ useEffect(() => {
+ setAIConfigurationRecoveryDismissed(false);
+ }, [aiConfigurationEnabled, currentChatId]);
+
return (
<div
ref={chatContainerRef}
@@ -161,7 +181,7 @@ export function AgentChat({ className }: AgentChatProps) {
),
a: ({ children, href }) => (
<a
- className="text-accent underline"
+ className="break-all text-accent underline"
href={href}
target="_blank"
rel="noopener noreferrer"
diff --git a/frontend/src/modules/agent/components/AgentInput.test.tsx b/frontend/src/modules/agent/components/AgentInput.test.tsx
index 513e52320b..a04fe374eb 100644
--- a/frontend/src/modules/agent/components/AgentInput.test.tsx
+++ b/frontend/src/modules/agent/components/AgentInput.test.tsx
@@ -7,6 +7,7 @@ import esES from "@/locales/es-ES.json";
import jaJP from "@/locales/ja-JP.json";
import viVN from "@/locales/vi-VN.json";
import zhCN from "@/locales/zh-CN.json";
+import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";
import type { DomRefSuggestion } from "../dom";
import { createAgentStore, useAgentStore } from "../store/agent";
@@ -28,6 +29,7 @@ const mocks = vi.hoisted(() => ({
buildSystemPrompt: vi.fn(() => "system"),
createToolExecutor: vi.fn(() => ({})),
getToolDefinitions: vi.fn(() => []),
+ getOrFetchSettingByName: vi.fn(),
}));
let AgentInput: typeof import("./AgentInput").AgentInput;
@@ -72,6 +74,17 @@ vi.mock("@/app/router", async (importOriginal) => ({
},
}));
+vi.mock("@/stores/app", () => {
+ const state = {
+ getOrFetchSettingByName: mocks.getOrFetchSettingByName,
+ getSettingByName: () => undefined,
+ };
+ const useAppStore = <T,>(selector: (value: typeof state) => T) =>
+ selector(state);
+ useAppStore.getState = () => state;
+ return { useAppStore };
+});
+
vi.mock("../dom", () => ({
lazyExtractDomRefSuggestions: mocks.lazyExtractDomRefSuggestions,
}));
@@ -80,7 +93,8 @@ vi.mock("../logic/agentLoop", () => ({
runAgentLoop: mocks.runAgentLoop,
}));
-vi.mock("../logic/aiConfiguration", () => ({
+vi.mock("../logic/aiConfiguration", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("../logic/aiConfiguration")>()),
isAgentAIConfigurationError: mocks.isAgentAIConfigurationError,
}));
@@ -176,6 +190,8 @@ beforeEach(async () => {
mocks.createToolExecutor.mockReturnValue({});
mocks.getToolDefinitions.mockReset();
mocks.getToolDefinitions.mockReturnValue([]);
+ mocks.getOrFetchSettingByName.mockReset();
+ mocks.getOrFetchSettingByName.mockResolvedValue(undefined);
({ AgentInput } = await import("./AgentInput"));
});
@@ -185,6 +201,34 @@ afterEach(() => {
});
describe("AgentInput", () => {
+ test("shows AI setup before the first prompt when AI is disabled", async () => {
+ mocks.getOrFetchSettingByName.mockResolvedValue({
+ value: {
+ value: {
+ case: "ai",
+ value: { enabled: false },
+ },
+ },
+ });
+
+ const { container, render, unmount } = renderIntoContainer(<AgentInput />);
+
+ await act(async () => {
+ render();
+ await Promise.resolve();
+ });
+ const chatId = useAgentStore.getState().currentChatId!;
+ expect(mocks.getOrFetchSettingByName).toHaveBeenCalledWith(
+ Setting_SettingName.AI,
+ true
+ );
+ expect(useAgentStore.getState().getChat(chatId)).toMatchObject({
+ requiresAIConfiguration: true,
+ });
+
+ unmount();
+ });
+
test("React locale token usage labels include the token count", () => {
for (const locale of [enUS, esES, jaJP, viVN, zhCN]) {
expect(locale.agent["chat-total-tokens"]).toContain("{{count}}");
diff --git a/frontend/src/modules/agent/components/AgentInput.tsx b/frontend/src/modules/agent/components/AgentInput.tsx
index 780a1ef4c8..667ed2c354 100644
--- a/frontend/src/modules/agent/components/AgentInput.tsx
+++ b/frontend/src/modules/agent/components/AgentInput.tsx
@@ -14,10 +14,15 @@ import { router } from "@/app/router";
import { Button } from "@/components/ui/button";
import { getLayerRoot, LAYER_SURFACE_CLASS } from "@/components/ui/layer";
import { Textarea } from "@/components/ui/textarea";
+import { useAppStore } from "@/stores/app";
+import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";
import type { DomRefSuggestion } from "../dom";
import { lazyExtractDomRefSuggestions } from "../dom";
import { runAgentLoop } from "../logic/agentLoop";
-import { isAgentAIConfigurationError } from "../logic/aiConfiguration";
+import {
+ getAgentAIConfigurationEnabled,
+ isAgentAIConfigurationError,
+} from "../logic/aiConfiguration";
import { buildOutboundHistory } from "../logic/outboundHistory";
import { buildSystemPrompt } from "../logic/prompt";
import { createToolExecutor, getToolDefinitions } from "../logic/tools";
@@ -114,6 +119,10 @@ export function AgentInput() {
selectCurrentChatRequiresAIConfiguration
);
const currentChatId = useAgentStore((s) => s.currentChatId);
+ const getOrFetchSettingByName = useAppStore((s) => s.getOrFetchSettingByName);
+ const aiConfigurationEnabled = useAppStore((s) =>
+ getAgentAIConfigurationEnabled(s.getSettingByName(Setting_SettingName.AI))
+ );
// Local state
const [input, setInput] = useState("");
@@ -164,6 +173,44 @@ export function AgentInput() {
[currentChat?.totalTokensUsed, t]
);
+ const blockWhenAIIsNotConfigured = useCallback(
+ async (chatId: string) => {
+ const setting = await getOrFetchSettingByName(
+ Setting_SettingName.AI,
+ true
+ );
+ if (getAgentAIConfigurationEnabled(setting) !== false) return false;
+
+ useAgentStore.getState().setChatStatus(chatId, "error", {
+ requiresAIConfiguration: true,
+ });
+ return true;
+ },
+ [getOrFetchSettingByName]
+ );
+
+ useEffect(() => {
+ const chat = useAgentStore.getState().getChat(currentChatId);
+ if (!chat) return;
+
+ if (aiConfigurationEnabled === false) {
+ useAgentStore.getState().setChatStatus(chat.id, "error", {
+ requiresAIConfiguration: true,
+ });
+ return;
+ }
+
+ if (aiConfigurationEnabled === true && chat.requiresAIConfiguration) {
+ useAgentStore.getState().clearError(chat.id);
+ }
+ }, [aiConfigurationEnabled, currentChatId]);
+
+ useEffect(() => {
+ const chat = useAgentStore.getState().getChat(currentChatId);
+ if (!chat) return;
+ void blockWhenAIIsNotConfigured(chat.id);
+ }, [blockWhenAIIsNotConfigured, currentChatId]);
+
// @-mention autocomplete
const activeDomRefQuery = useMemo(
() => getDomRefQuery(input, selectionStart, selectionEnd),
@@ -503,6 +550,7 @@ export function AgentInput() {
const currentPage = getCurrentPageSnapshot();
const thread = store.ensureCurrentChat(currentPage);
const chatId = thread.id;
+ if (await blockWhenAIIsNotConfigured(chatId)) return;
store.clearError(chatId);
const pendingAsk = selectCurrentPendingAsk(store);
@@ -540,7 +588,7 @@ export function AgentInput() {
metadata: { route: currentPage.path },
});
await startChatRun(chatId, currentPage);
- }, [input, startChatRun]);
+ }, [blockWhenAIIsNotConfigured, input, startChatRun]);
const retryLastTurn = useCallback(async () => {
const store = useAgentStore.getState();
@@ -549,10 +597,11 @@ export function AgentInput() {
const chatId = chat.id;
const currentPage = getCurrentPageSnapshot();
+ if (await blockWhenAIIsNotConfigured(chatId)) return;
store.removeMessagesByRunId(chatId, chat.runId);
store.clearError(chatId);
await startChatRun(chatId, currentPage);
- }, [startChatRun]);
+ }, [blockWhenAIIsNotConfigured, startChatRun]);
const dismissInterrupted = useCallback(() => {
const store = useAgentStore.getState();
@@ -580,6 +629,7 @@ export function AgentInput() {
const chatId = thread.id;
const answer = confirmed ? confirmLabel : cancelLabel;
+ if (await blockWhenAIIsNotConfigured(chatId)) return;
store.clearError(chatId);
store.answerPendingAsk(
chatId,
@@ -588,7 +638,7 @@ export function AgentInput() {
);
await startChatRun(chatId, currentPage);
},
- [confirmLabel, cancelLabel, startChatRun]
+ [blockWhenAIIsNotConfigured, confirmLabel, cancelLabel, startChatRun]
);
const submitChoice = useCallback(
@@ -608,6 +658,7 @@ export function AgentInput() {
const thread = store.ensureCurrentChat(currentPage);
const chatId = thread.id;
+ if (await blockWhenAIIsNotConfigured(chatId)) return;
store.clearError(chatId);
store.answerPendingAsk(
chatId,
@@ -616,7 +667,7 @@ export function AgentInput() {
);
await startChatRun(chatId, currentPage);
},
- [startChatRun]
+ [blockWhenAIIsNotConfigured, startChatRun]
);
// Textarea keydown handler
diff --git a/frontend/src/modules/agent/components/AgentWindow.test.tsx b/frontend/src/modules/agent/components/AgentWindow.test.tsx
index 236634c3cf..b72893ba34 100644
--- a/frontend/src/modules/agent/components/AgentWindow.test.tsx
+++ b/frontend/src/modules/agent/components/AgentWindow.test.tsx
@@ -2,6 +2,7 @@ import type { ReactElement } from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
+import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";
import { createAgentStore, useAgentStore } from "../store/agent";
(
@@ -13,6 +14,7 @@ const mocks = vi.hoisted(() => ({
t: (key: string) => key,
i18n: { language: "en-US" },
})),
+ getOrFetchSettingByName: vi.fn(),
}));
function createMockStorage(): Storage {
@@ -44,6 +46,16 @@ vi.mock("react-i18next", () => ({
useTranslation: mocks.useTranslation,
}));
+vi.mock("@/stores/app", () => {
+ const state = {
+ getOrFetchSettingByName: mocks.getOrFetchSettingByName,
+ };
+ const useAppStore = <T,>(selector: (value: typeof state) => T) =>
+ selector(state);
+ useAppStore.getState = () => state;
+ return { useAppStore };
+});
+
vi.mock("./AgentChat", () => ({
AgentChat: () => <div data-testid="agent-chat" />,
}));
@@ -124,6 +136,8 @@ beforeEach(async () => {
t: (key: string) => key,
i18n: { language: "en-US" },
});
+ mocks.getOrFetchSettingByName.mockReset();
+ mocks.getOrFetchSettingByName.mockResolvedValue(undefined);
({ AgentWindow } = await import("./AgentWindow"));
});
@@ -135,6 +149,37 @@ afterEach(() => {
});
describe("AgentWindow", () => {
+ test("checks AI configuration when opening an existing chat", async () => {
+ const chatId = useAgentStore.getState().currentChatId!;
+ mocks.getOrFetchSettingByName.mockResolvedValue({
+ value: {
+ value: {
+ case: "ai",
+ value: { enabled: false },
+ },
+ },
+ });
+ useAgentStore.setState({ visible: false });
+
+ const { render, unmount } = renderIntoContainer(<AgentWindow />);
+
+ render();
+ await act(async () => {
+ useAgentStore.getState().toggle();
+ await Promise.resolve();
+ });
+
+ expect(mocks.getOrFetchSettingByName).toHaveBeenCalledWith(
+ Setting_SettingName.AI,
+ true
+ );
+ expect(useAgentStore.getState().getChat(chatId)).toMatchObject({
+ requiresAIConfiguration: true,
+ });
+
+ unmount();
+ });
+
test("uses an accessible panel separator for the chat sidebar", () => {
const { render, unmount } = renderIntoContainer(<AgentWindow />);
diff --git a/frontend/src/modules/agent/components/AgentWindow.tsx b/frontend/src/modules/agent/components/AgentWindow.tsx
index 914f112e78..bbd6caa535 100644
--- a/frontend/src/modules/agent/components/AgentWindow.tsx
+++ b/frontend/src/modules/agent/components/AgentWindow.tsx
@@ -20,7 +20,10 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { getLayerRoot } from "@/components/ui/layer";
import { cn } from "@/lib/utils";
+import { useAppStore } from "@/stores/app";
+import { Setting_SettingName } from "@/types/proto-es/v1/setting_service_pb";
import { formatAbsoluteDateTime } from "@/utils";
+import { getAgentAIConfigurationEnabled } from "../logic/aiConfiguration";
import type { AgentChat as AgentChatRecord } from "../logic/types";
import {
selectCurrentChat,
@@ -86,6 +89,7 @@ export function AgentWindow() {
const currentChat = useAgentStore(selectCurrentChat);
const currentChatId = useAgentStore((s) => s.currentChatId);
const hasRunningChat = useAgentStore(selectHasRunningChat);
+ const getOrFetchSettingByName = useAppStore((s) => s.getOrFetchSettingByName);
const windowRef = useRef<HTMLDivElement>(null);
const renameInputRef = useRef<HTMLInputElement>(null);
@@ -825,6 +829,26 @@ export function AgentWindow() {
useAgentStore.getState().loadWindowState();
}, []);
+ useEffect(() => {
+ if (!visible || !currentChatId) return;
+
+ let cancelled = false;
+ void getOrFetchSettingByName(Setting_SettingName.AI, true).then(
+ (setting) => {
+ if (cancelled || getAgentAIConfigurationEnabled(setting) !== false) {
+ return;
+ }
+ useAgentStore.getState().setChatStatus(currentChatId, "error", {
+ requiresAIConfiguration: true,
+ });
+ }
+ );
+
+ return () => {
+ cancelled = true;
+ };
+ }, [currentChatId, getOrFetchSettingByName, visible]);
+
// --- Render ---
if (!visible) return null;
diff --git a/frontend/src/modules/agent/logic/aiConfiguration.ts b/frontend/src/modules/agent/logic/aiConfiguration.ts
index 2edd6465f6..1685631463 100644
--- a/frontend/src/modules/agent/logic/aiConfiguration.ts
+++ b/frontend/src/modules/agent/logic/aiConfiguration.ts
@@ -1,4 +1,5 @@
import { Code, ConnectError } from "@connectrpc/connect";
+import type { Setting } from "@/types/proto-es/v1/setting_service_pb";
const AI_NOT_ENABLED_MESSAGE = "AI is not enabled";
@@ -10,3 +11,11 @@ export const isAgentAIConfigurationError = (error: unknown): boolean => {
error.message === AI_NOT_ENABLED_MESSAGE)
);
};
+
+export const getAgentAIConfigurationEnabled = (
+ setting: Setting | undefined
+): boolean | undefined => {
+ if (!setting) return undefined;
+ if (setting.value?.value.case !== "ai") return false;
+ return setting.value.value.value.enabled;
+};
diff --git a/frontend/src/routes/workspace/MembersPage.test.tsx b/frontend/src/routes/workspace/MembersPage.test.tsx
index 76e9f27198..0bde0e39ef 100644
--- a/frontend/src/routes/workspace/MembersPage.test.tsx
+++ b/frontend/src/routes/workspace/MembersPage.test.tsx
@@ -18,6 +18,7 @@ const {
maximumRoleExpirationSeconds,
maximumRequestExpirationSeconds,
accountSelectProps,
+ roleList,
} = vi.hoisted(() => ({
mockUseProductIntro: vi.fn(),
mockPushNotification: vi.fn(),
@@ -25,6 +26,12 @@ const {
maximumRoleExpirationSeconds: { value: undefined as number | undefined },
maximumRequestExpirationSeconds: { value: undefined as number | undefined },
accountSelectProps: { value: undefined as { accountParents: string[] } | undefined },
+ roleList: {
+ value: [{ name: "roles/sqlEditorUser", permissions: [] }] as Array<{
+ name: string;
+ permissions: string[];
+ }>,
+ },
}));
vi.mock("@/components/AccountMultiSelect", () => ({
@@ -325,7 +332,7 @@ vi.mock("@/hooks/useAppState", () => ({
vi.mock("@/stores/app", () => {
const buildState = () => ({
batchGetOrFetchUsers: vi.fn(async () => []),
- roleList: [{ name: "roles/sqlEditorUser", permissions: [] }],
+ roleList: roleList.value,
workspacePolicy: { bindings: [] },
patchWorkspaceIamPolicy: vi.fn(),
findWorkspaceRolesByMember: () => [],
@@ -394,6 +401,7 @@ beforeEach(() => {
maximumRoleExpirationSeconds.value = undefined;
maximumRequestExpirationSeconds.value = undefined;
accountSelectProps.value = undefined;
+ roleList.value = [{ name: "roles/sqlEditorUser", permissions: [] }];
projectIamPolicy.bindings = [];
container = document.createElement("div");
document.body.appendChild(container);
@@ -756,3 +764,35 @@ describe("MembersPage onboarding intro", () => {
);
});
});
+
+describe("MembersPage workspace role grant drawer", () => {
+ it("shows the selected roles' permissions", async () => {
+ roleList.value = [
+ {
+ name: "roles/workspaceDBA",
+ permissions: ["bb.instances.get", "bb.instances.list"],
+ },
+ ];
+ await renderWorkspacePage();
+
+ const grantButton = [...container.querySelectorAll("button")].find(
+ (button) => button.textContent === "settings.members.grant-access"
+ ) as HTMLButtonElement;
+ await act(async () => {
+ grantButton.click();
+ });
+ await flush();
+
+ const roleInput = container.querySelector(
+ "[data-testid='role-select']"
+ ) as HTMLInputElement;
+ await act(async () => {
+ nativeChange(roleInput, "roles/workspaceDBA");
+ });
+ await flush();
+
+ expect(container.textContent).toContain("common.permissions");
+ expect(container.textContent).toContain("bb.instances.get");
+ expect(container.textContent).toContain("bb.instances.list");
+ });
+});
diff --git a/frontend/src/routes/workspace/MembersPage.tsx b/frontend/src/routes/workspace/MembersPage.tsx
index a20a13c5c6..ddd5d4b424 100644
--- a/frontend/src/routes/workspace/MembersPage.tsx
+++ b/frontend/src/routes/workspace/MembersPage.tsx
@@ -157,6 +157,33 @@ import { getSetIamPolicyPermissionGuardConfig } from "./membersPageActions";
const EMPTY_ROLE_SET = new Set<string>();
+function RolePermissionPreview({
+ permissions,
+}: {
+ permissions: readonly string[];
+}) {
+ const { t } = useTranslation();
+
+ if (permissions.length === 0) return null;
+
+ return (
+ <FormField title={<>{t("common.permissions")}</>}>
+ <div className="max-h-32 overflow-auto rounded-sm border border-control-border bg-control-bg p-2">
+ <div className="flex flex-wrap gap-1">
+ {permissions.map((permission) => (
+ <Badge
+ key={permission}
+ className="bg-control-bg-hover text-control-light"
+ >
+ {permission}
+ </Badge>
+ ))}
+ </div>
+ </div>
+ </FormField>
+ );
+}
+
// ============================================================
// MemberTable (view by members)
// ============================================================
@@ -1156,23 +1183,7 @@ function ProjectRoleBindingForm({
<RoleDescription role={form.role} roleList={roleList} />
</FormField>
- {/* Permissions display */}
- {permissions.length > 0 && (
- <FormField title={<>{t("common.permissions")}</>}>
- <div className="max-h-32 overflow-auto border rounded-sm bg-control-bg p-2">
- <div className="flex flex-wrap gap-1">
- {permissions.map((perm) => (
- <span
- key={perm}
- className="inline-block rounded-xs bg-control-bg-hover px-1.5 py-0.5 text-xs text-control-light"
- >
- {perm}
- </span>
- ))}
- </div>
- </div>
- </FormField>
- )}
+ <RolePermissionPreview permissions={permissions} />
{/* Reason */}
<FormField
@@ -1398,6 +1409,17 @@ function EditMemberRoleDrawer({
if (projectName) return member.projectRoleBindings.map((b) => b.role);
return [...member.workspaceLevelRoles];
});
+ const selectedRolePermissions = useMemo(
+ () => [
+ ...new Set(
+ selectedRoles.flatMap(
+ (role) =>
+ roleList.find(({ name }) => name === role)?.permissions ?? []
+ )
+ ),
+ ],
+ [roleList, selectedRoles]
+ );
const [isRequesting, setIsRequesting] = useState(false);
const [showNestedGrant, setShowNestedGrant] = useState(false);
@@ -1964,24 +1986,31 @@ function EditMemberRoleDrawer({
/>
</div>
) : (
- <FormField
- title={<>{t("settings.members.select-role", { count: 2 })}</>}
- >
- <RoleSelect
- value={selectedRoles}
- onChange={setSelectedRoles}
- scope={projectName ? "project" : undefined}
- />
- {unscopedDirectExecutionKind && (
- <DirectExecutionCallout
- kind={unscopedDirectExecutionKind}
- lead="binding"
- scope={{ type: "all" }}
- environmentList={environmentList}
- hasEnvTierFeature={hasEnvTierFeature}
+ <>
+ <FormField
+ title={<>{t("settings.members.select-role", { count: 2 })}</>}
+ >
+ <RoleSelect
+ value={selectedRoles}
+ onChange={setSelectedRoles}
+ scope={projectName ? "project" : undefined}
+ />
+ {unscopedDirectExecutionKind && (
+ <DirectExecutionCallout
+ kind={unscopedDirectExecutionKind}
+ lead="binding"
+ scope={{ type: "all" }}
+ environmentList={environmentList}
+ hasEnvTierFeature={hasEnvTierFeature}
+ />
+ )}
+ </FormField>
+ {!projectName && (
+ <RolePermissionPreview
+ permissions={selectedRolePermissions}
/>
)}
- </FormField>
+ </>
)}
</div>
</SheetBody>