Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat: add hide_personal_workspaces flag for org-only OHE installs (#14741)

Alona287efaf6f65c
diff --git a/enterprise/storage/default_org_service.py b/enterprise/storage/default_org_service.py
index e1da07468f..4d7899988d 100644
--- a/enterprise/storage/default_org_service.py
+++ b/enterprise/storage/default_org_service.py
@@ -38,6 +38,7 @@ class DefaultOrgConfig:
org_name: str
owner_emails: frozenset[str]
auto_add_users: bool
+ hide_personal_workspaces: bool
def _env_value(name: str, *aliases: str, default: str = '') -> str:
@@ -80,6 +81,10 @@ def get_default_org_config() -> DefaultOrgConfig:
'OPENHANDS_DEFAULT_ORG_AUTO_ADD_USERS',
'OH_DEFAULT_ORG_AUTO_ADD_USERS',
),
+ # Same env var the web client config injector reads to hide personal
+ # workspaces in the UI; here it additionally moves users out of a
+ # personal current org on login (there is no visible way to be there).
+ hide_personal_workspaces=_env_truthy('HIDE_PERSONAL_WORKSPACES'),
)
@@ -144,6 +149,20 @@ class DefaultOrgBootstrapService:
(is_new_user or org_created_by_user)
and await OrgMemberStore.get_org_member(org.id, user.id) is not None
)
+
+ # When personal workspaces are hidden there is no visible way to be
+ # in one, so members parked on their personal org (e.g. from before
+ # the flag was enabled) are moved on every login.
+ if (
+ not should_set_current_org
+ and config.hide_personal_workspaces
+ and user.current_org_id == user.id
+ ):
+ should_set_current_org = (
+ outcome is MembershipOutcome.PROMOTED
+ or await OrgMemberStore.get_org_member(org.id, user.id) is not None
+ )
+
if should_set_current_org:
updated_user = await UserStore.update_current_org(str(user.id), org.id)
if updated_user:
diff --git a/enterprise/tests/unit/test_default_org_service.py b/enterprise/tests/unit/test_default_org_service.py
index 43730a4c19..6fc5e5d9e7 100644
--- a/enterprise/tests/unit/test_default_org_service.py
+++ b/enterprise/tests/unit/test_default_org_service.py
@@ -52,6 +52,15 @@ def test_default_org_config_accepts_one_as_truthy(monkeypatch):
)
assert config.auto_add_users is True
+ assert config.hide_personal_workspaces is False
+
+
+def test_default_org_config_reads_hide_personal_workspaces(monkeypatch):
+ monkeypatch.setenv('HIDE_PERSONAL_WORKSPACES', 'true')
+
+ config = get_default_org_config()
+
+ assert config.hide_personal_workspaces is True
@pytest.mark.asyncio
@@ -454,6 +463,126 @@ async def test_existing_owner_creating_org_is_moved_into_it(monkeypatch):
mock_update_current_org.assert_awaited_once_with(str(owner.id), org.id)
+async def test_hide_personal_workspaces_moves_member_parked_on_personal(monkeypatch):
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_ENABLED', 'true')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_NAME', 'Acme')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_OWNER_EMAILS', '[email protected]')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_AUTO_ADD_USERS', 'true')
+ monkeypatch.setenv('HIDE_PERSONAL_WORKSPACES', 'true')
+ # _user() parks the user on their personal org (current_org_id == id)
+ member = _user('[email protected]')
+ org = _org()
+ existing_membership = SimpleNamespace(role_id=3)
+
+ with (
+ patch(
+ 'storage.default_org_service.OrgStore.get_org_by_name',
+ new_callable=AsyncMock,
+ return_value=org,
+ ),
+ patch(
+ 'storage.default_org_service.OrgMemberStore.get_org_member',
+ new_callable=AsyncMock,
+ return_value=existing_membership,
+ ),
+ patch(
+ 'storage.default_org_service.UserStore.update_current_org',
+ new_callable=AsyncMock,
+ return_value=member,
+ ) as mock_update_current_org,
+ patch(
+ 'storage.default_org_service.UserStore.get_user_by_id',
+ new_callable=AsyncMock,
+ return_value=member,
+ ),
+ ):
+ await DefaultOrgBootstrapService.apply_for_user(member, is_new_user=False)
+
+ # Personal workspaces are hidden, so a member parked on their personal
+ # org is moved into the default org on every login.
+ mock_update_current_org.assert_awaited_once_with(str(member.id), org.id)
+
+
+async def test_hide_personal_workspaces_does_not_move_user_in_another_team_org(
+ monkeypatch,
+):
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_ENABLED', 'true')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_NAME', 'Acme')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_OWNER_EMAILS', '[email protected]')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_AUTO_ADD_USERS', 'true')
+ monkeypatch.setenv('HIDE_PERSONAL_WORKSPACES', 'true')
+ member = _user('[email protected]')
+ # The user works in some other (team) org β€” not their personal workspace.
+ member.current_org_id = uuid.uuid4()
+ org = _org()
+ existing_membership = SimpleNamespace(role_id=3)
+
+ with (
+ patch(
+ 'storage.default_org_service.OrgStore.get_org_by_name',
+ new_callable=AsyncMock,
+ return_value=org,
+ ),
+ patch(
+ 'storage.default_org_service.OrgMemberStore.get_org_member',
+ new_callable=AsyncMock,
+ return_value=existing_membership,
+ ),
+ patch(
+ 'storage.default_org_service.UserStore.update_current_org',
+ new_callable=AsyncMock,
+ ) as mock_update_current_org,
+ patch(
+ 'storage.default_org_service.UserStore.get_user_by_id',
+ new_callable=AsyncMock,
+ return_value=member,
+ ),
+ ):
+ await DefaultOrgBootstrapService.apply_for_user(member, is_new_user=False)
+
+ mock_update_current_org.assert_not_called()
+
+
+async def test_hide_personal_workspaces_leaves_non_member_on_personal(monkeypatch):
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_ENABLED', 'true')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_NAME', 'Acme')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_OWNER_EMAILS', '[email protected]')
+ monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_AUTO_ADD_USERS', 'false')
+ monkeypatch.setenv('HIDE_PERSONAL_WORKSPACES', 'true')
+ member = _user('[email protected]')
+ org = _org()
+
+ with (
+ patch(
+ 'storage.default_org_service.OrgStore.get_org_by_name',
+ new_callable=AsyncMock,
+ return_value=org,
+ ),
+ patch(
+ 'storage.default_org_service.OrgMemberStore.get_org_member',
+ new_callable=AsyncMock,
+ return_value=None,
+ ),
+ patch(
+ 'storage.default_org_service.UserStore.update_current_org',
+ new_callable=AsyncMock,
+ ) as mock_update_current_org,
+ patch(
+ 'storage.default_org_service.UserStore.get_user_by_id',
+ new_callable=AsyncMock,
+ return_value=member,
+ ),
+ ):
+ await DefaultOrgBootstrapService.apply_for_user(member, is_new_user=False)
+
+ # Not a member of the default org (auto-add off): never strand the user
+ # with zero workspaces β€” they stay on personal and the UI keeps showing it.
+ mock_update_current_org.assert_not_called()
+
+
@pytest.mark.asyncio
async def test_existing_personal_workspace_org_is_not_adopted(monkeypatch):
monkeypatch.setenv('OPENHANDS_DEFAULT_ORG_ENABLED', 'true')
diff --git a/frontend/__tests__/hooks/query/use-organizations.test.tsx b/frontend/__tests__/hooks/query/use-organizations.test.tsx
index 56530a4a15..6932eadfb8 100644
--- a/frontend/__tests__/hooks/query/use-organizations.test.tsx
+++ b/frontend/__tests__/hooks/query/use-organizations.test.tsx
@@ -16,9 +16,13 @@ vi.mock("#/hooks/query/use-is-authed", () => ({
useIsAuthed: () => ({ data: true }),
}));
-// Mock useConfig to return SaaS mode (organizations are a SaaS-only feature)
+// Mock useConfig to return SaaS mode (organizations are a SaaS-only feature).
+// Tests can override mockConfig.data to exercise feature flags.
+const mockConfig = vi.hoisted(() => ({
+ data: { app_mode: "saas" } as Record<string, unknown>,
+}));
vi.mock("#/hooks/query/use-config", () => ({
- useConfig: () => ({ data: { app_mode: "saas" } }),
+ useConfig: () => mockConfig,
}));
const mockGetOrganizations = vi.mocked(organizationService.getOrganizations);
@@ -65,6 +69,7 @@ describe("useOrganizations", () => {
},
});
vi.clearAllMocks();
+ mockConfig.data = { app_mode: "saas" };
});
it("sorts personal workspace first, then non-personal alphabetically by name", async () => {
@@ -163,4 +168,70 @@ describe("useOrganizations", () => {
expect(result.current.data!.organizations[0].id).toBe("1");
expect(result.current.data!.organizations[1].id).toBe("2");
});
+
+ it("filters out personal workspaces when hide_personal_workspaces is on", async () => {
+ mockConfig.data = {
+ app_mode: "saas",
+ feature_flags: { hide_personal_workspaces: true },
+ };
+ mockGetOrganizations.mockResolvedValue({
+ items: [
+ createMinimalOrg("1", "Personal Workspace", true),
+ createMinimalOrg("2", "Acme Corp", false),
+ ],
+ currentOrgId: "1",
+ });
+
+ const { result } = renderHook(() => useOrganizations(), { wrapper });
+
+ await waitFor(() => {
+ expect(result.current.isSuccess).toBe(true);
+ });
+
+ const { organizations } = result.current.data!;
+ expect(organizations).toHaveLength(1);
+ expect(organizations[0].id).toBe("2");
+ expect(organizations[0].is_personal).toBe(false);
+ });
+
+ it("keeps the personal workspace when it is the user's only org even with hide_personal_workspaces on", async () => {
+ mockConfig.data = {
+ app_mode: "saas",
+ feature_flags: { hide_personal_workspaces: true },
+ };
+ mockGetOrganizations.mockResolvedValue({
+ items: [createMinimalOrg("1", "Personal Workspace", true)],
+ currentOrgId: "1",
+ });
+
+ const { result } = renderHook(() => useOrganizations(), { wrapper });
+
+ await waitFor(() => {
+ expect(result.current.isSuccess).toBe(true);
+ });
+
+ // Never leave the user with zero workspaces (e.g. the default org has
+ // not been created yet, or the user is not a member of any team org).
+ const { organizations } = result.current.data!;
+ expect(organizations).toHaveLength(1);
+ expect(organizations[0].id).toBe("1");
+ });
+
+ it("does not filter personal workspaces when the flag is off", async () => {
+ mockGetOrganizations.mockResolvedValue({
+ items: [
+ createMinimalOrg("1", "Personal Workspace", true),
+ createMinimalOrg("2", "Acme Corp", false),
+ ],
+ currentOrgId: "1",
+ });
+
+ const { result } = renderHook(() => useOrganizations(), { wrapper });
+
+ await waitFor(() => {
+ expect(result.current.isSuccess).toBe(true);
+ });
+
+ expect(result.current.data!.organizations).toHaveLength(2);
+ });
});
diff --git a/frontend/__tests__/routes/manage-org.test.tsx b/frontend/__tests__/routes/manage-org.test.tsx
index 4e00aa3a9a..2b4dff1cad 100644
--- a/frontend/__tests__/routes/manage-org.test.tsx
+++ b/frontend/__tests__/routes/manage-org.test.tsx
@@ -173,7 +173,7 @@ describe("Manage Org Route", () => {
hide_users_page: false,
hide_billing_page: false,
hide_integrations_page: false,
- enable_onboarding: false,
+ enable_onboarding: false,
},
}),
);
@@ -533,7 +533,7 @@ describe("Manage Org Route", () => {
hide_users_page: false,
hide_billing_page: false,
hide_integrations_page: false,
- enable_onboarding: false,
+ enable_onboarding: false,
},
}),
);
@@ -566,7 +566,7 @@ describe("Manage Org Route", () => {
hide_users_page: false,
hide_billing_page: false,
hide_integrations_page: false,
- enable_onboarding: false,
+ enable_onboarding: false,
},
}),
);
@@ -599,7 +599,7 @@ describe("Manage Org Route", () => {
hide_users_page: false,
hide_billing_page: false,
hide_integrations_page: false,
- enable_onboarding: false,
+ enable_onboarding: false,
},
}),
);
@@ -633,7 +633,7 @@ describe("Manage Org Route", () => {
hide_users_page: false,
hide_billing_page: false,
hide_integrations_page: false,
- enable_onboarding: false,
+ enable_onboarding: false,
},
}),
);
@@ -654,4 +654,51 @@ describe("Manage Org Route", () => {
getConfigSpy.mockRestore();
});
});
+
+ describe("Git conversation routing visibility", () => {
+ it("should show the section by default for owners", async () => {
+ renderManageOrg();
+ await screen.findByTestId("manage-org-screen");
+
+ await waitFor(() => {
+ expect(
+ screen.getByTestId("git-conversation-routing"),
+ ).toBeInTheDocument();
+ });
+ });
+
+ it("should hide the section in org-only installs with a single team org", async () => {
+ vi.spyOn(OptionService, "getConfig").mockResolvedValue(
+ createMockWebClientConfig({
+ app_mode: "saas",
+ feature_flags: {
+ enable_billing: true,
+ hide_llm_settings: false,
+ enable_jira: false,
+ enable_jira_dc: false,
+ enable_linear: false,
+ hide_users_page: false,
+ hide_billing_page: false,
+ hide_integrations_page: false,
+ enable_onboarding: false,
+ hide_personal_workspaces: true,
+ },
+ }),
+ );
+ queryClient.setQueryData(["organizations"], {
+ items: [MOCK_TEAM_ORG_ACME],
+ currentOrgId: MOCK_TEAM_ORG_ACME.id,
+ });
+
+ renderManageOrg();
+ await screen.findByTestId("manage-org-screen");
+
+ await waitFor(() => {
+ expect(screen.getByTestId("org-name")).toBeInTheDocument();
+ });
+ expect(
+ screen.queryByTestId("git-conversation-routing"),
+ ).not.toBeInTheDocument();
+ });
+ });
});
diff --git a/frontend/src/api/option-service/option.types.ts b/frontend/src/api/option-service/option.types.ts
index cad91a5ac8..e99556d526 100644
--- a/frontend/src/api/option-service/option.types.ts
+++ b/frontend/src/api/option-service/option.types.ts
@@ -28,6 +28,9 @@ export interface WebClientFeatureFlags {
hide_users_page: boolean;
hide_billing_page: boolean;
hide_integrations_page: boolean;
+ /** Hide personal workspaces from the org list/selector for users who
+ * belong to at least one team org (OHE "org-only" installs). */
+ hide_personal_workspaces?: boolean;
enable_acp?: boolean;
deployment_mode?: DeploymentMode;
enable_onboarding: boolean;
diff --git a/frontend/src/hooks/query/use-organizations.ts b/frontend/src/hooks/query/use-organizations.ts
index 33d2b82e1f..f93f8c3373 100644
--- a/frontend/src/hooks/query/use-organizations.ts
+++ b/frontend/src/hooks/query/use-organizations.ts
@@ -9,15 +9,27 @@ export const useOrganizations = () => {
// Organizations are a SaaS-only feature - disable in OSS mode
const isOssMode = config?.app_mode === "oss";
+ const hidePersonalWorkspaces =
+ config?.feature_flags?.hide_personal_workspaces === true;
return useQuery({
queryKey: ["organizations"],
queryFn: organizationService.getOrganizations,
staleTime: 1000 * 60 * 5, // 5 minutes
enabled: !!userIsAuthenticated && !isOssMode,
- select: (data) => ({
+ select: (data) => {
+ // In org-only installs, hide personal workspaces β€” but only when the
+ // user belongs to at least one team org, so a user whose only
+ // workspace is personal (e.g. the default org isn't created yet) is
+ // never left with zero workspaces.
+ const hasTeamOrg = data.items.some((org) => !(org.is_personal ?? false));
+ const visible =
+ hidePersonalWorkspaces && hasTeamOrg
+ ? data.items.filter((org) => !(org.is_personal ?? false))
+ : data.items;
+
// Sort organizations with personal workspace first, then alphabetically by name
- organizations: [...data.items].sort((a, b) => {
+ const organizations = [...visible].sort((a, b) => {
const aIsPersonal = a.is_personal ?? false;
const bIsPersonal = b.is_personal ?? false;
if (aIsPersonal && !bIsPersonal) return -1;
@@ -25,8 +37,12 @@ export const useOrganizations = () => {
return (a.name ?? "").localeCompare(b.name ?? "", undefined, {
sensitivity: "base",
});
- }),
- currentOrgId: data.currentOrgId,
- }),
+ });
+
+ return {
+ organizations,
+ currentOrgId: data.currentOrgId,
+ };
+ },
});
};
diff --git a/frontend/src/hooks/use-auto-select-organization.ts b/frontend/src/hooks/use-auto-select-organization.ts
index 3fe867aae7..cfe27321a5 100644
--- a/frontend/src/hooks/use-auto-select-organization.ts
+++ b/frontend/src/hooks/use-auto-select-organization.ts
@@ -23,8 +23,15 @@ export function useAutoSelectOrganization() {
React.useEffect(() => {
if (!organizationId && organizations && organizations.length > 0) {
- // Prefer backend's current_org_id (last selected org), fall back to first org
- const initialOrgId = currentOrgId ?? organizations[0].id;
+ // Prefer backend's current_org_id (last selected org), fall back to
+ // first org. Ignore a current_org_id that isn't in the visible list β€”
+ // e.g. a personal workspace while hide_personal_workspaces is on.
+ const visibleCurrentOrgId = organizations.some(
+ (org) => org.id === currentOrgId,
+ )
+ ? currentOrgId
+ : undefined;
+ const initialOrgId = visibleCurrentOrgId ?? organizations[0].id;
// Skip revalidation for initial auto-selection to avoid duplicate API calls.
// Revalidation is only needed when user explicitly switches organizations
// to redirect away from admin-only pages they may no longer have access to.
diff --git a/frontend/src/hooks/use-should-hide-org-selector.ts b/frontend/src/hooks/use-should-hide-org-selector.ts
index 27a5c6009c..a97bb30a7a 100644
--- a/frontend/src/hooks/use-should-hide-org-selector.ts
+++ b/frontend/src/hooks/use-should-hide-org-selector.ts
@@ -12,5 +12,14 @@ export function useShouldHideOrgSelector() {
}
// In SaaS mode, hide if user only has one personal org
- return organizations?.length === 1 && organizations[0]?.is_personal === true;
+ if (organizations?.length === 1 && organizations[0]?.is_personal === true) {
+ return true;
+ }
+
+ // When personal workspaces are hidden and only one org is visible,
+ // there is nothing to switch between.
+ return (
+ config?.feature_flags?.hide_personal_workspaces === true &&
+ organizations?.length === 1
+ );
}
diff --git a/frontend/src/routes/manage-org.tsx b/frontend/src/routes/manage-org.tsx
index fb42393c1f..b489c1885d 100644
--- a/frontend/src/routes/manage-org.tsx
+++ b/frontend/src/routes/manage-org.tsx
@@ -14,6 +14,7 @@ import { GitConversationRouting } from "#/components/features/org/git-conversati
import { ChangeOrgNameModal } from "#/components/features/org/change-org-name-modal";
import { AddCreditsModal } from "#/components/features/org/add-credits-modal";
import { useBalance } from "#/hooks/query/use-balance";
+import { useOrganizations } from "#/hooks/query/use-organizations";
import { cn } from "#/utils/utils";
export const clientLoader = createPermissionGuard("view_billing");
@@ -24,6 +25,7 @@ function ManageOrg() {
const { data: organization } = useOrganization();
const { data: balance } = useBalance();
const { data: config } = useConfig();
+ const { data: orgsData } = useOrganizations();
const role = me?.role ?? "member";
const { hasPermission } = usePermission(role);
@@ -39,6 +41,15 @@ function ManageOrg() {
const canDeleteOrg = !!me && hasPermission("delete_organization");
const canAddCredits = !!me && hasPermission("add_credits");
const canManageOrgClaims = !!me && hasPermission("manage_org_claims");
+ // In org-only installs with a single visible org, git claims are not
+ // needed: resolver conversations follow the user's current org and
+ // unclaimed automation events fall back to the default org. The section
+ // reappears as soon as a second org exists, when claims become the
+ // routing mechanism again.
+ const hideGitConversationRouting =
+ config?.feature_flags?.hide_personal_workspaces === true &&
+ orgsData?.organizations?.length === 1 &&
+ orgsData.organizations[0]?.is_personal !== true;
const shouldHideBilling = isBillingHidden(
config,
hasPermission("view_billing"),
@@ -116,7 +127,9 @@ function ManageOrg() {
</button>
)}
- {canManageOrgClaims && <GitConversationRouting />}
+ {canManageOrgClaims && !hideGitConversationRouting && (
+ <GitConversationRouting />
+ )}
</div>
);
}
diff --git a/openhands/app_server/web_client/default_web_client_config_injector.py b/openhands/app_server/web_client/default_web_client_config_injector.py
index 84dbdd9d7c..90590c8d2c 100644
--- a/openhands/app_server/web_client/default_web_client_config_injector.py
+++ b/openhands/app_server/web_client/default_web_client_config_injector.py
@@ -159,8 +159,9 @@ def _get_feature_flags() -> WebClientFeatureFlags:
Reads ENABLE_BILLING, HIDE_LLM_SETTINGS, ENABLE_JIRA, ENABLE_JIRA_DC,
ENABLE_LINEAR, HIDE_USERS_PAGE, HIDE_BILLING_PAGE, HIDE_INTEGRATIONS_PAGE,
- ENABLE_ACP, and OH_ENABLE_ONBOARDING from environment. Each flag is True
- only if the corresponding env var is exactly 'true', otherwise False.
+ HIDE_PERSONAL_WORKSPACES, ENABLE_ACP, and OH_ENABLE_ONBOARDING from
+ environment. Each flag is True only if the corresponding env var is
+ exactly 'true', otherwise False.
"""
return WebClientFeatureFlags(
enable_billing=os.getenv('ENABLE_BILLING', 'false') == 'true',
@@ -171,6 +172,8 @@ def _get_feature_flags() -> WebClientFeatureFlags:
hide_users_page=os.getenv('HIDE_USERS_PAGE', 'false') == 'true',
hide_billing_page=os.getenv('HIDE_BILLING_PAGE', 'false') == 'true',
hide_integrations_page=os.getenv('HIDE_INTEGRATIONS_PAGE', 'false') == 'true',
+ hide_personal_workspaces=os.getenv('HIDE_PERSONAL_WORKSPACES', 'false')
+ == 'true',
enable_acp=os.getenv('ENABLE_ACP', 'false') == 'true',
enable_onboarding=os.getenv('OH_ENABLE_ONBOARDING', 'false') == 'true',
)
diff --git a/openhands/app_server/web_client/web_client_models.py b/openhands/app_server/web_client/web_client_models.py
index 816b9317b5..8f3ba9c8d6 100644
--- a/openhands/app_server/web_client/web_client_models.py
+++ b/openhands/app_server/web_client/web_client_models.py
@@ -20,6 +20,12 @@ class WebClientFeatureFlags(BaseModel):
hide_users_page: bool = False
hide_billing_page: bool = False
hide_integrations_page: bool = False
+ # When true, the web client hides personal workspaces from the org list
+ # and selector for users who belong to at least one team org. Used by
+ # OHE installs that bootstrap a default org and want it to be the only
+ # workspace users see. UI-level only β€” the orgs API still returns
+ # personal orgs, and disabling the flag restores them.
+ hide_personal_workspaces: bool = False
enable_acp: bool = False
deployment_mode: DeploymentMode | None = None
enable_onboarding: bool = False