Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions frontend/__tests__/routes/accept-tos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import AcceptTOS from "#/routes/accept-tos";
import * as CaptureConsent from "#/utils/handle-capture-consent";
import { openHands } from "#/api/open-hands-axios";
import OptionService from "#/api/option-service/option-service.api";
import type { DeploymentMode } from "#/api/option-service/option.types";
import { createMockWebClientConfig } from "#/mocks/settings-handlers";
import { useSelectedOrganizationStore } from "#/stores/selected-organization-store";

// Mock the react-router hooks
Expand All @@ -31,11 +34,31 @@ vi.mock("#/api/open-hands-axios", () => ({
},
}));

// The global mock of `t` drops interpolation values. Keep them, so a test can
// check which product the heading names.
vi.mock("react-i18next", async (importOriginal) => ({
...(await importOriginal<typeof import("react-i18next")>()),
useTranslation: () => ({
t: (key: string, options?: Record<string, string>) =>
options ? `${key} ${JSON.stringify(options)}` : key,
i18n: { language: "en", exists: () => false },
}),
}));

// Mock the toast handlers
vi.mock("#/utils/custom-toast-handlers", () => ({
displayErrorToast: vi.fn(),
}));

// Web-client config of an enterprise install with the given deployment mode
const createSaasConfig = (deploymentMode?: DeploymentMode) => {
const config = createMockWebClientConfig({ app_mode: "saas" });
return {
...config,
feature_flags: { ...config.feature_flags, deployment_mode: deploymentMode },
};
};

// Create a wrapper with QueryClientProvider
const createWrapper = () => {
const queryClient = new QueryClient({
Expand Down Expand Up @@ -143,4 +166,56 @@ describe("AcceptTOS", () => {

expect(window.location.href).toBe(externalUrl);
});

it("should name OpenHands Enterprise and link its terms on a self-hosted install", async () => {
vi.spyOn(OptionService, "getConfig").mockResolvedValue(
createSaasConfig("self_hosted"),
);

render(<AcceptTOS />, { wrapper: createWrapper() });

expect(
await screen.findByRole("heading", {
name: 'TOS$ACCEPT_PRODUCT_TERMS_OF_SERVICE {"product":"OpenHands Enterprise"}',
}),
).toBeInTheDocument();
expect(screen.getByRole("link", { name: "TOS$TERMS" })).toHaveAttribute(
"href",
"https://www.openhands.dev/enterprise-tos",
);
});

it("should name OpenHands Cloud and link its terms on the managed cloud", async () => {
vi.spyOn(OptionService, "getConfig").mockResolvedValue(
createSaasConfig("cloud"),
);

render(<AcceptTOS />, { wrapper: createWrapper() });

expect(
await screen.findByRole("heading", {
name: 'TOS$ACCEPT_PRODUCT_TERMS_OF_SERVICE {"product":"OpenHands Cloud"}',
}),
).toBeInTheDocument();
expect(screen.getByRole("link", { name: "TOS$TERMS" })).toHaveAttribute(
"href",
"https://www.openhands.dev/tos",
);
});

it("should keep the generic terms wording when the deployment mode is unknown", async () => {
vi.spyOn(OptionService, "getConfig").mockResolvedValue(createSaasConfig());

render(<AcceptTOS />, { wrapper: createWrapper() });

expect(
await screen.findByRole("heading", {
name: "TOS$ACCEPT_TERMS_OF_SERVICE",
}),
).toBeInTheDocument();
expect(screen.getByRole("link", { name: "TOS$TERMS" })).toHaveAttribute(
"href",
"https://www.openhands.dev/tos",
);
});
});
6 changes: 3 additions & 3 deletions frontend/src/components/features/waitlist/tos-checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useTranslation } from "react-i18next";
import { TERMS_OF_SERVICE_URL } from "#/constants/legal-links";
import { I18nKey } from "#/i18n/declaration";

interface TOSCheckboxProps {
termsUrl: string;
onChange: () => void;
}

export function TOSCheckbox({ onChange }: TOSCheckboxProps) {
export function TOSCheckbox({ termsUrl, onChange }: TOSCheckboxProps) {
const { t } = useTranslation();
return (
<label className="flex items-center gap-2">
<input type="checkbox" onChange={onChange} />
<span>
{t(I18nKey.TOS$ACCEPT)}{" "}
<a
href={TERMS_OF_SERVICE_URL}
href={termsUrl}
target="_blank"
rel="noopener noreferrer"
className="underline underline-offset-2 text-blue-500 hover:text-blue-700"
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/constants/legal-links.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** OpenHands' legal pages, linked wherever the app shows Terms or Privacy. */
export const TERMS_OF_SERVICE_URL = "https://www.openhands.dev/tos";
export const PRIVACY_POLICY_URL = "https://www.openhands.dev/privacy";
/** Terms for self-hosted OpenHands Enterprise installs (OHE-3865). */
export const ENTERPRISE_TERMS_OF_SERVICE_URL =
"https://www.openhands.dev/enterprise-tos";
2 changes: 2 additions & 0 deletions frontend/src/i18n/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@ export enum I18nKey {
SYSTEM_MESSAGE_MODAL$NO_TOOLS = "SYSTEM_MESSAGE_MODAL$NO_TOOLS",
TOS$ACCEPT_TERMS_OF_SERVICE = "TOS$ACCEPT_TERMS_OF_SERVICE",
TOS$ACCEPT_TERMS_DESCRIPTION = "TOS$ACCEPT_TERMS_DESCRIPTION",
TOS$ACCEPT_PRODUCT_TERMS_OF_SERVICE = "TOS$ACCEPT_PRODUCT_TERMS_OF_SERVICE",
TOS$ACCEPT_PRODUCT_TERMS_DESCRIPTION = "TOS$ACCEPT_PRODUCT_TERMS_DESCRIPTION",
TOS$CONTINUE = "TOS$CONTINUE",
TOS$ERROR_ACCEPTING = "TOS$ERROR_ACCEPTING",
TIPS$CUSTOMIZE_MICROAGENT = "TIPS$CUSTOMIZE_MICROAGENT",
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/i18n/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -16370,6 +16370,40 @@
"tr": "Devam etmeden önce lütfen hizmet şartlarımızı gözden geçirin ve kabul edin",
"ca": "Reviseu i accepteu les condicions del servei abans de continuar"
},
"TOS$ACCEPT_PRODUCT_TERMS_OF_SERVICE": {
"en": "Accept {{product}} Terms of Service",
"ja": "Accept {{product}} Terms of Service",
"zh-CN": "Accept {{product}} Terms of Service",
"zh-TW": "Accept {{product}} Terms of Service",
"ko-KR": "Accept {{product}} Terms of Service",
"fr": "Accept {{product}} Terms of Service",
"es": "Accept {{product}} Terms of Service",
"de": "Accept {{product}} Terms of Service",
"it": "Accept {{product}} Terms of Service",
"pt": "Accept {{product}} Terms of Service",
"uk": "Accept {{product}} Terms of Service",
"no": "Accept {{product}} Terms of Service",
"ar": "Accept {{product}} Terms of Service",
"tr": "Accept {{product}} Terms of Service",
"ca": "Accept {{product}} Terms of Service"
},
"TOS$ACCEPT_PRODUCT_TERMS_DESCRIPTION": {
"en": "Please review and accept the {{product}} terms of service before continuing",
"ja": "Please review and accept the {{product}} terms of service before continuing",
"zh-CN": "Please review and accept the {{product}} terms of service before continuing",
"zh-TW": "Please review and accept the {{product}} terms of service before continuing",
"ko-KR": "Please review and accept the {{product}} terms of service before continuing",
"fr": "Please review and accept the {{product}} terms of service before continuing",
"es": "Please review and accept the {{product}} terms of service before continuing",
"de": "Please review and accept the {{product}} terms of service before continuing",
"it": "Please review and accept the {{product}} terms of service before continuing",
"pt": "Please review and accept the {{product}} terms of service before continuing",
"uk": "Please review and accept the {{product}} terms of service before continuing",
"no": "Please review and accept the {{product}} terms of service before continuing",
"ar": "Please review and accept the {{product}} terms of service before continuing",
"tr": "Please review and accept the {{product}} terms of service before continuing",
"ca": "Please review and accept the {{product}} terms of service before continuing"
},
"TOS$CONTINUE": {
"en": "Continue",
"ja": "続行",
Expand Down
35 changes: 32 additions & 3 deletions frontend/src/routes/accept-tos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,41 @@ import OpenHandsLogoWhite from "#/assets/branding/openhands-logo-white.svg?react
import { TOSCheckbox } from "#/components/features/waitlist/tos-checkbox";
import { BrandButton } from "#/components/features/settings/brand-button";
import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";
import {
ENTERPRISE_TERMS_OF_SERVICE_URL,
TERMS_OF_SERVICE_URL,
} from "#/constants/legal-links";
import { useAcceptTos } from "#/hooks/mutation/use-accept-tos";
import { useAppMode } from "#/hooks/use-app-mode";

const CLOUD_PRODUCT_NAME = "OpenHands Cloud";
const ENTERPRISE_PRODUCT_NAME = "OpenHands Enterprise";

export default function AcceptTOS() {
const { t } = useTranslation();
const [searchParams] = useSearchParams();
const [isTosAccepted, setIsTosAccepted] = React.useState(false);
const { isEnterpriseCloud, isEnterpriseSelfHosted } = useAppMode();

// Get the redirect URL from the query parameters
const redirectUrl = searchParams.get("redirect_url") || "/";

// Use mutation for accepting TOS
const { mutate: acceptTOS, isPending: isSubmitting } = useAcceptTos();

// Name the product the terms cover. Until the web-client config is in the
// cache (or on a backend that reports no deployment_mode) keep the generic
// wording rather than guess a product.
let product: string | null = null;
if (isEnterpriseSelfHosted) {
product = ENTERPRISE_PRODUCT_NAME;
} else if (isEnterpriseCloud) {
product = CLOUD_PRODUCT_NAME;
}
const termsUrl = isEnterpriseSelfHosted
? ENTERPRISE_TERMS_OF_SERVICE_URL
: TERMS_OF_SERVICE_URL;

const handleAcceptTOS = () => {
if (isTosAccepted && !isSubmitting) {
acceptTOS({ redirectUrl });
Expand All @@ -32,14 +54,21 @@ export default function AcceptTOS() {

<div className="flex flex-col gap-2 w-full items-center text-center">
<h1 className="text-2xl font-bold">
{t(I18nKey.TOS$ACCEPT_TERMS_OF_SERVICE)}
{product
? t(I18nKey.TOS$ACCEPT_PRODUCT_TERMS_OF_SERVICE, { product })
: t(I18nKey.TOS$ACCEPT_TERMS_OF_SERVICE)}
</h1>
<p className="text-sm text-gray-500">
{t(I18nKey.TOS$ACCEPT_TERMS_DESCRIPTION)}
{product
? t(I18nKey.TOS$ACCEPT_PRODUCT_TERMS_DESCRIPTION, { product })
: t(I18nKey.TOS$ACCEPT_TERMS_DESCRIPTION)}
</p>
</div>

<TOSCheckbox onChange={() => setIsTosAccepted((prev) => !prev)} />
<TOSCheckbox
termsUrl={termsUrl}
onChange={() => setIsTosAccepted((prev) => !prev)}
/>

<BrandButton
isDisabled={!isTosAccepted || isSubmitting}
Expand Down
Loading