π OpenHands: AI-Driven Development
fix: Disable analytics toggle for cloud backends (#16098)
Rohit Malhotra200dba420ce1
diff --git a/__tests__/routes/app-settings.test.tsx b/__tests__/routes/app-settings.test.tsxindex b698a6a98c..dda0d14f9a 100644--- a/__tests__/routes/app-settings.test.tsx+++ b/__tests__/routes/app-settings.test.tsx@@ -8,6 +8,17 @@ import { MOCK_DEFAULT_USER_SETTINGS } from "#/mocks/handlers";import { Settings } from "#/types/settings";import ProfilesService from "#/api/profiles-service/profiles-service.api";+const activeBackendState = vi.hoisted(() => ({+ kind: "local" as "local" | "cloud",+}));++vi.mock("#/contexts/active-backend-context", () => ({+ useActiveBackend: () => ({+ backend: { kind: activeBackendState.kind },+ orgId: null,+ }),+}));+function buildSettings(overrides: Partial<Settings> = {}): Settings {return {...MOCK_DEFAULT_USER_SETTINGS,@@ -42,6 +53,7 @@ function renderAppSettingsScreen() {describe("AppSettingsScreen", () => {beforeEach(() => {vi.restoreAllMocks();+ activeBackendState.kind = "local";});it("renders the OSS application settings form", async () => {@@ -73,6 +85,52 @@ describe("AppSettingsScreen", () => {).toHaveValue("SETTINGS$TITLE_GENERATION_AUTOMATIC");});+ it("renders the analytics toggle as checked and disabled for cloud backends", async () => {+ activeBackendState.kind = "cloud";+ vi.spyOn(SettingsService, "getSettings").mockResolvedValue(+ buildSettings({ user_consents_to_analytics: false }),+ );++ renderAppSettingsScreen();++ const analyticsSwitch = await screen.findByTestId(+ "enable-analytics-switch",+ );+ const submitButton = screen.getByTestId("submit-button");++ expect(analyticsSwitch).toBeChecked();+ expect(analyticsSwitch).toBeDisabled();++ await userEvent.click(analyticsSwitch);+ expect(submitButton).toBeDisabled();+ });++ it("does not submit analytics consent for cloud backends", async () => {+ activeBackendState.kind = "cloud";+ const saveSettingsSpy = vi+ .spyOn(SettingsService, "saveSettings")+ .mockResolvedValue(true);+ vi.spyOn(SettingsService, "getSettings").mockResolvedValue(+ buildSettings({ user_consents_to_analytics: false }),+ );++ renderAppSettingsScreen();++ const user = userEvent.setup();+ await user.click(+ await screen.findByTestId("enable-sound-notifications-switch"),+ );+ await user.click(screen.getByTestId("submit-button"));++ await waitFor(() => {+ expect(saveSettingsSpy).toHaveBeenCalledWith(+ expect.not.objectContaining({+ user_consents_to_analytics: expect.anything(),+ }),+ );+ });+ });+it("saves updated git author details in OSS mode", async () => {const saveSettingsSpy = vi.spyOn(SettingsService, "saveSettings")diff --git a/src/routes/app-settings.tsx b/src/routes/app-settings.tsxindex 0dd361410e..cfb3e57349 100644--- a/src/routes/app-settings.tsx+++ b/src/routes/app-settings.tsx@@ -20,6 +20,7 @@ import { AppSettingsInputsSkeleton } from "#/components/features/settings/app-seimport { SettingsDropdownInput } from "#/components/features/settings/settings-dropdown-input";import { NavigationLink } from "#/components/shared/navigation-link";import { useLlmProfiles } from "#/hooks/query/use-llm-profiles";+import { useActiveBackend } from "#/contexts/active-backend-context";const AUTOMATIC_TITLE_LLM_PROFILE_KEY = "__automatic__";@@ -28,6 +29,8 @@ export function AppSettingsScreen() {const { mutate: saveSettings, isPending } = useSaveSettings();const { data: settings, isLoading } = useSettings();+ const activeBackend = useActiveBackend();+ const isCloudBackend = activeBackend.backend.kind === "cloud";const { data: llmProfiles, isLoading: areLlmProfilesLoading } =useLlmProfiles();@@ -84,8 +87,9 @@ export function AppSettingsScreen() {)?.value;const language = languageValue || DEFAULT_SETTINGS.language;- const enableAnalytics =- formData.get("enable-analytics-switch")?.toString() === "on";+ const enableAnalytics = isCloudBackend+ ? true+ : formData.get("enable-analytics-switch")?.toString() === "on";const enableSoundNotifications =formData.get("enable-sound-notifications-switch")?.toString() === "on";@@ -99,7 +103,7 @@ export function AppSettingsScreen() {saveSettings({language,- user_consents_to_analytics: enableAnalytics,+ ...(!isCloudBackend && { user_consents_to_analytics: enableAnalytics }),enable_sound_notifications: enableSoundNotifications,git_user_name: gitUserName,git_user_email: gitUserEmail,@@ -190,9 +194,17 @@ export function AppSettingsScreen() {<SettingsSwitchtestId="enable-analytics-switch"- name="enable-analytics-switch"- defaultIsToggled={settings.user_consents_to_analytics ?? true}- onToggle={checkIfAnalyticsSwitchHasChanged}+ name={isCloudBackend ? undefined : "enable-analytics-switch"}+ defaultIsToggled={+ isCloudBackend+ ? true+ : (settings.user_consents_to_analytics ?? true)+ }+ isToggled={isCloudBackend ? true : undefined}+ isDisabled={isCloudBackend}+ onToggle={+ isCloudBackend ? undefined : checkIfAnalyticsSwitchHasChanged+ }>{t(I18nKey.ANALYTICS$SEND_ANONYMOUS_DATA)}</SettingsSwitch>