Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(frontend): hide and block personal LLM/Condenser/Verification settings in team orgs (#14030)

Hiep Le3892ab2b677c
diff --git a/frontend/__tests__/hooks/use-settings-nav-items.test.tsx b/frontend/__tests__/hooks/use-settings-nav-items.test.tsx
index 7046506696..f7e39c5c22 100644
--- a/frontend/__tests__/hooks/use-settings-nav-items.test.tsx
+++ b/frontend/__tests__/hooks/use-settings-nav-items.test.tsx
@@ -436,6 +436,79 @@ describe("useSettingsNavItems", () => {
});
});
+ it("hides personal LLM/Condenser/Verification when org-defaults versions are visible (team-org admin)", async () => {
+ mockConfig("saas");
+ mockOrgTypeAndAccess.isTeamOrg = true;
+ mockOrgTypeAndAccess.isPersonalOrg = false;
+ mockOrgTypeAndAccess.organizationId = "org-123";
+ mockMe.data = { role: "admin" };
+
+ const { result } = renderHook(() => useSettingsNavItems(), { wrapper });
+
+ await waitFor(() => {
+ expect(
+ findItemByPath(result.current, "/settings/org-defaults"),
+ ).toBeDefined();
+ expect(
+ findItemByPath(result.current, "/settings/org-defaults/condenser"),
+ ).toBeDefined();
+ expect(
+ findItemByPath(result.current, "/settings/org-defaults/verification"),
+ ).toBeDefined();
+
+ expect(findItemByPath(result.current, "/settings")).toBeUndefined();
+ expect(
+ findItemByPath(result.current, "/settings/condenser"),
+ ).toBeUndefined();
+ expect(
+ findItemByPath(result.current, "/settings/verification"),
+ ).toBeUndefined();
+ });
+ });
+
+ it("hides personal LLM/Condenser/Verification for any user in a non-personal org (team-org member)", async () => {
+ mockConfig("saas");
+ mockOrgTypeAndAccess.isTeamOrg = true;
+ mockOrgTypeAndAccess.isPersonalOrg = false;
+ mockOrgTypeAndAccess.organizationId = "org-123";
+ mockMe.data = { role: "member" };
+
+ const { result } = renderHook(() => useSettingsNavItems(), { wrapper });
+
+ await waitFor(() => {
+ expect(
+ findItemByPath(result.current, "/settings/user"),
+ ).toBeDefined();
+ expect(findItemByPath(result.current, "/settings")).toBeUndefined();
+ expect(
+ findItemByPath(result.current, "/settings/condenser"),
+ ).toBeUndefined();
+ expect(
+ findItemByPath(result.current, "/settings/verification"),
+ ).toBeUndefined();
+ });
+ });
+
+ it("keeps personal LLM/Condenser/Verification visible in the personal workspace", async () => {
+ mockConfig("saas");
+ mockOrgTypeAndAccess.isTeamOrg = false;
+ mockOrgTypeAndAccess.isPersonalOrg = true;
+ mockOrgTypeAndAccess.organizationId = "org-personal";
+ mockMe.data = { role: "admin" };
+
+ const { result } = renderHook(() => useSettingsNavItems(), { wrapper });
+
+ await waitFor(() => {
+ expect(findItemByPath(result.current, "/settings")).toBeDefined();
+ expect(
+ findItemByPath(result.current, "/settings/condenser"),
+ ).toBeDefined();
+ expect(
+ findItemByPath(result.current, "/settings/verification"),
+ ).toBeDefined();
+ });
+ });
+
it("should filter out both LLM and integrations when both flags are true in OSS mode", async () => {
mockConfigWithFeatureFlags("oss", {
hide_llm_settings: true,
diff --git a/frontend/__tests__/utils/personal-workspace-guard.test.ts b/frontend/__tests__/utils/personal-workspace-guard.test.ts
new file mode 100644
index 0000000000..b1a8b2d482
--- /dev/null
+++ b/frontend/__tests__/utils/personal-workspace-guard.test.ts
@@ -0,0 +1,88 @@
+import { describe, expect, it, vi, beforeEach } from "vitest";
+
+vi.mock("react-router", () => ({
+ redirect: vi.fn((path: string) => ({ type: "redirect", path })),
+}));
+
+const mockConfig = {
+ app_mode: "saas" as "saas" | "oss",
+ feature_flags: {},
+};
+
+vi.mock("#/api/option-service/option-service.api", () => ({
+ default: { getConfig: vi.fn(async () => mockConfig) },
+}));
+
+const mockOrganizations = {
+ items: [
+ { id: "personal-org", name: "Personal", is_personal: true },
+ { id: "team-org", name: "Acme", is_personal: false },
+ ],
+ currentOrgId: "team-org" as string | null,
+};
+
+vi.mock("#/api/organization-service/organization-service.api", () => ({
+ organizationService: {
+ getOrganizations: vi.fn(async () => mockOrganizations),
+ },
+}));
+
+let storeOrgId: string | null = null;
+vi.mock("#/stores/selected-organization-store", () => ({
+ getSelectedOrganizationIdFromStore: () => storeOrgId,
+}));
+
+vi.mock("#/query-client-config", () => ({
+ queryClient: {
+ fetchQuery: vi.fn(async (opts: { queryFn: () => Promise<unknown> }) =>
+ opts.queryFn(),
+ ),
+ },
+}));
+
+import { redirect } from "react-router";
+import { requirePersonalWorkspaceLoader } from "#/utils/org/personal-workspace-guard";
+
+const createRequest = (pathname: string) => ({
+ request: new Request(`http://localhost${pathname}`),
+});
+
+describe("requirePersonalWorkspaceLoader", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mockConfig.app_mode = "saas";
+ mockOrganizations.currentOrgId = "team-org";
+ storeOrgId = null;
+ });
+
+ it("redirects to the org-defaults equivalent when the active org is a team workspace", async () => {
+ storeOrgId = "team-org";
+ const guard = requirePersonalWorkspaceLoader("/settings/org-defaults");
+
+ const result = await guard(createRequest("/settings"));
+
+ expect(redirect).toHaveBeenCalledWith("/settings/org-defaults");
+ expect(result).toEqual({ type: "redirect", path: "/settings/org-defaults" });
+ });
+
+ it("allows access when the active org is the personal workspace", async () => {
+ storeOrgId = "personal-org";
+ const guard = requirePersonalWorkspaceLoader("/settings/org-defaults");
+
+ const result = await guard(createRequest("/settings"));
+
+ expect(result).toBeNull();
+ expect(redirect).not.toHaveBeenCalled();
+ });
+
+ it("skips the guard entirely in OSS mode", async () => {
+ mockConfig.app_mode = "oss";
+ storeOrgId = "team-org";
+ const guard = requirePersonalWorkspaceLoader("/settings/org-defaults");
+
+ const result = await guard(createRequest("/settings"));
+
+ expect(result).toBeNull();
+ expect(redirect).not.toHaveBeenCalled();
+ });
+});
diff --git a/frontend/src/hooks/use-settings-nav-items.ts b/frontend/src/hooks/use-settings-nav-items.ts
index dbc84034e3..2e6f43996c 100644
--- a/frontend/src/hooks/use-settings-nav-items.ts
+++ b/frontend/src/hooks/use-settings-nav-items.ts
@@ -77,6 +77,15 @@ export function useSettingsNavItems(): SettingsNavRenderedItem[] {
);
}
+ const PERSONAL_LLM_PATHS = new Set([
+ "/settings",
+ "/settings/condenser",
+ "/settings/verification",
+ ]);
+ if (isTeamOrg) {
+ items = items.filter((item) => !PERSONAL_LLM_PATHS.has(item.to));
+ }
+
// For OSS mode or non-SaaS, return flat list without sections
if (!isSaasMode) {
return items.map((item) => ({ type: "item", item }));
diff --git a/frontend/src/routes/condenser-settings.tsx b/frontend/src/routes/condenser-settings.tsx
index ad0b3be6c8..4cef893712 100644
--- a/frontend/src/routes/condenser-settings.tsx
+++ b/frontend/src/routes/condenser-settings.tsx
@@ -1,5 +1,6 @@
import { SdkSectionPage } from "#/components/features/settings/sdk-settings/sdk-section-page";
import { createPermissionGuard } from "#/utils/org/permission-guard";
+import { requirePersonalWorkspaceLoader } from "#/utils/org/personal-workspace-guard";
function CondenserSettingsScreen() {
return (
@@ -10,6 +11,15 @@ function CondenserSettingsScreen() {
);
}
-export const clientLoader = createPermissionGuard("view_llm_settings");
+const personalWorkspaceGuard = requirePersonalWorkspaceLoader(
+ "/settings/org-defaults/condenser",
+);
+const condenserPermissionGuard = createPermissionGuard("view_llm_settings");
+
+export const clientLoader = async (args: { request: Request }) => {
+ const blocked = await personalWorkspaceGuard(args);
+ if (blocked) return blocked;
+ return condenserPermissionGuard(args);
+};
export default CondenserSettingsScreen;
diff --git a/frontend/src/routes/llm-settings.tsx b/frontend/src/routes/llm-settings.tsx
index 4a3680bc8e..e73b53691e 100644
--- a/frontend/src/routes/llm-settings.tsx
+++ b/frontend/src/routes/llm-settings.tsx
@@ -3,6 +3,7 @@ import { useSearchParams } from "react-router";
import { useTranslation } from "react-i18next";
import { ModelSelector } from "#/components/shared/modals/settings/model-selector";
import { createPermissionGuard } from "#/utils/org/permission-guard";
+import { requirePersonalWorkspaceLoader } from "#/utils/org/personal-workspace-guard";
import { useAgentSettingsSchema } from "#/hooks/query/use-agent-settings-schema";
import { useSettings } from "#/hooks/query/use-settings";
import { SettingsInput } from "#/components/features/settings/settings-input";
@@ -400,6 +401,15 @@ export function LlmSettingsScreen({
);
}
-export const clientLoader = createPermissionGuard("view_llm_settings");
+const personalWorkspaceGuard = requirePersonalWorkspaceLoader(
+ "/settings/org-defaults",
+);
+const llmPermissionGuard = createPermissionGuard("view_llm_settings");
+
+export const clientLoader = async (args: { request: Request }) => {
+ const blocked = await personalWorkspaceGuard(args);
+ if (blocked) return blocked;
+ return llmPermissionGuard(args);
+};
export default LlmSettingsScreen;
diff --git a/frontend/src/routes/verification-settings.tsx b/frontend/src/routes/verification-settings.tsx
index a5adbed2c3..4f953d119f 100644
--- a/frontend/src/routes/verification-settings.tsx
+++ b/frontend/src/routes/verification-settings.tsx
@@ -12,6 +12,7 @@ import { I18nKey } from "#/i18n/declaration";
import { DEFAULT_SETTINGS } from "#/services/settings";
import { SettingsScope } from "#/types/settings";
import { createPermissionGuard } from "#/utils/org/permission-guard";
+import { requirePersonalWorkspaceLoader } from "#/utils/org/personal-workspace-guard";
const VERIFICATION_SCHEMA_EXCLUDE_KEYS = new Set([
"confirmation_mode",
@@ -193,6 +194,15 @@ export function VerificationSettingsScreen({
);
}
-export const clientLoader = createPermissionGuard("view_llm_settings");
+const personalWorkspaceGuard = requirePersonalWorkspaceLoader(
+ "/settings/org-defaults/verification",
+);
+const verificationPermissionGuard = createPermissionGuard("view_llm_settings");
+
+export const clientLoader = async (args: { request: Request }) => {
+ const blocked = await personalWorkspaceGuard(args);
+ if (blocked) return blocked;
+ return verificationPermissionGuard(args);
+};
export default VerificationSettingsScreen;
diff --git a/frontend/src/utils/org/personal-workspace-guard.ts b/frontend/src/utils/org/personal-workspace-guard.ts
new file mode 100644
index 0000000000..ed177f435e
--- /dev/null
+++ b/frontend/src/utils/org/personal-workspace-guard.ts
@@ -0,0 +1,60 @@
+import { redirect } from "react-router";
+import { queryClient } from "#/query-client-config";
+import OptionService from "#/api/option-service/option-service.api";
+import { organizationService } from "#/api/organization-service/organization-service.api";
+import { CONFIG_CACHE_OPTIONS, QUERY_KEYS } from "#/hooks/query/query-keys";
+import { getSelectedOrganizationIdFromStore } from "#/stores/selected-organization-store";
+import { OrganizationsQueryData } from "#/types/org";
+
+const FALLBACK_REDIRECT_PATH = "/settings/user";
+
+const fetchConfig = () =>
+ queryClient.fetchQuery({
+ queryKey: QUERY_KEYS.WEB_CLIENT_CONFIG,
+ queryFn: OptionService.getConfig,
+ ...CONFIG_CACHE_OPTIONS,
+ });
+
+const fetchOrganizations = () =>
+ queryClient.fetchQuery<OrganizationsQueryData>({
+ queryKey: ["organizations"],
+ queryFn: organizationService.getOrganizations,
+ staleTime: 1000 * 60 * 5,
+ });
+
+// Fails open (returns null, allowing access) when org context cannot be
+// resolved β€” config fetch, org fetch, or active-org lookup. Backend permission
+// checks remain authoritative, so an outage degrades to "show the page" rather
+// than locking every user out of personal LLM settings.
+export const requirePersonalWorkspaceLoader =
+ (redirectPath: string = FALLBACK_REDIRECT_PATH) =>
+ async ({ request }: { request: Request }) => {
+ const config = await fetchConfig();
+
+ if (config?.app_mode !== "saas") return null;
+
+ let organizationsData: OrganizationsQueryData | undefined;
+ try {
+ organizationsData = await fetchOrganizations();
+ } catch {
+ return null;
+ }
+
+ const orgId =
+ getSelectedOrganizationIdFromStore() ??
+ organizationsData?.currentOrgId ??
+ organizationsData?.items?.[0]?.id ??
+ null;
+
+ if (!orgId) return null;
+
+ const activeOrg = organizationsData?.items.find((o) => o.id === orgId);
+ if (!activeOrg) return null;
+
+ if (activeOrg.is_personal === true) return null;
+
+ const currentPath = new URL(request.url).pathname;
+ if (currentPath === redirectPath) return null;
+
+ return redirect(redirectPath);
+ };