mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 15:02:02 +00:00
⚖️ refactor: Move Policy Links to the Signup Consent (#16138)
This commit is contained in:
parent
86d5ad5c6b
commit
1bfaa5f96f
21 changed files with 937 additions and 121 deletions
|
|
@ -541,7 +541,6 @@ if (cluster.isMaster) {
|
|||
so the answer is the deployment's base configuration, like index.js. */
|
||||
indexHTML = injectConfiguredFooterBootstrap(indexHTML, {
|
||||
customFooter: process.env.CUSTOM_FOOTER,
|
||||
interfaceConfig: baseAppConfig?.interfaceConfig,
|
||||
});
|
||||
|
||||
const cspPolicy = createCspPolicy();
|
||||
|
|
|
|||
|
|
@ -292,7 +292,6 @@ const startServer = async () => {
|
|||
caller's and the client prefers it. */
|
||||
indexHTML = injectConfiguredFooterBootstrap(indexHTML, {
|
||||
customFooter: process.env.CUSTOM_FOOTER,
|
||||
interfaceConfig: appConfig?.interfaceConfig,
|
||||
});
|
||||
|
||||
const cspPolicy = createCspPolicy();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import { ThemeSelector } from '@librechat/client';
|
||||
import { TStartupConfig } from 'librechat-data-provider';
|
||||
import { ErrorMessage } from '~/components/Auth/ErrorMessage';
|
||||
import { hasPublishedPolicies } from '~/utils/policies';
|
||||
import { TranslationKeys, useLocalize } from '~/hooks';
|
||||
import SocialLoginRender from './SocialLoginRender';
|
||||
import { BlinkAnimation } from './BlinkAnimation';
|
||||
import LegalConsent from './LegalConsent';
|
||||
import { Banner } from '../Banners';
|
||||
import Footer from './Footer';
|
||||
|
||||
|
|
@ -27,6 +29,30 @@ function AuthLayout({
|
|||
const localize = useLocalize();
|
||||
|
||||
const hasStartupConfigError = startupConfigError !== null && startupConfigError !== undefined;
|
||||
const isRegister = pathname.includes('register');
|
||||
const isLogin = !pathname.includes('2fa') && pathname.includes('login');
|
||||
const showsSocialLogin = isLogin || isRegister;
|
||||
/** Both ways in state it, rather than the layout guessing which of them can
|
||||
* create an account. That guess is not available here: account creation
|
||||
* also happens on a first provider sign-in, on a first LDAP sign-in through
|
||||
* the ordinary form, and is gated server-side by ALLOW_SOCIAL_REGISTRATION,
|
||||
* which the startup payload does not carry. The sentence is about
|
||||
* continuing, which is what both screens do, and it names the same policies
|
||||
* the footer bar linked, so a screen states them once. */
|
||||
const hasPolicies = hasPublishedPolicies(startupConfig);
|
||||
/** Registration states it under its own submit button, where it is read
|
||||
* before the account is created rather than below however many provider
|
||||
* buttons a deployment configured, and it renders that form only once the
|
||||
* config has loaded without error. The login screen has no submit button of
|
||||
* its own to sit under, so there the layout states it below the providers,
|
||||
* for as long as it knows the policies: a background refetch must not swap
|
||||
* the sentence for the bar and back. */
|
||||
const registrationStatesConsent =
|
||||
isRegister && hasPolicies && !hasStartupConfigError && !isFetching;
|
||||
const statesConsentBelowProviders = isLogin && hasPolicies;
|
||||
/** The bar is dropped exactly when the sentence is on the screen, so a
|
||||
* reader never meets both and never meets neither. */
|
||||
const statesConsent = registrationStatesConsent || statesConsentBelowProviders;
|
||||
const DisplayError = () => {
|
||||
if (hasStartupConfigError) {
|
||||
return (
|
||||
|
|
@ -87,13 +113,11 @@ function AuthLayout({
|
|||
</h1>
|
||||
)}
|
||||
{children}
|
||||
{!pathname.includes('2fa') &&
|
||||
(pathname.includes('login') || pathname.includes('register')) && (
|
||||
<SocialLoginRender startupConfig={startupConfig} />
|
||||
)}
|
||||
{showsSocialLogin && <SocialLoginRender startupConfig={startupConfig} />}
|
||||
{statesConsentBelowProviders && <LegalConsent startupConfig={startupConfig} />}
|
||||
</div>
|
||||
</main>
|
||||
<Footer startupConfig={startupConfig} />
|
||||
{!statesConsent && <Footer startupConfig={startupConfig} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { TStartupConfig } from 'librechat-data-provider';
|
||||
import { policyUrls } from '~/utils/policies';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
function Footer({ startupConfig }: { startupConfig: TStartupConfig | null | undefined }) {
|
||||
|
|
@ -6,13 +7,14 @@ function Footer({ startupConfig }: { startupConfig: TStartupConfig | null | unde
|
|||
if (!startupConfig) {
|
||||
return null;
|
||||
}
|
||||
const privacyPolicy = startupConfig.interface?.privacyPolicy;
|
||||
const termsOfService = startupConfig.interface?.termsOfService;
|
||||
/** Read the way the consent reads them, so a blank url is not a policy on one
|
||||
* screen and a link back to this page on another. */
|
||||
const { privacyPolicyUrl, termsOfServiceUrl } = policyUrls(startupConfig);
|
||||
|
||||
const privacyPolicyRender = privacyPolicy?.externalUrl && (
|
||||
const privacyPolicyRender = privacyPolicyUrl != null && (
|
||||
<a
|
||||
className="text-sm text-accent-primary underline decoration-transparent transition-all duration-200 hover:text-accent-primary-hover hover:decoration-accent-primary-hover focus:text-accent-primary-hover focus:decoration-accent-primary-hover"
|
||||
href={privacyPolicy.externalUrl}
|
||||
href={privacyPolicyUrl}
|
||||
// Removed for WCAG compliance
|
||||
// target={privacyPolicy.openNewTab ? '_blank' : undefined}
|
||||
rel="noreferrer"
|
||||
|
|
@ -21,10 +23,10 @@ function Footer({ startupConfig }: { startupConfig: TStartupConfig | null | unde
|
|||
</a>
|
||||
);
|
||||
|
||||
const termsOfServiceRender = termsOfService?.externalUrl && (
|
||||
const termsOfServiceRender = termsOfServiceUrl != null && (
|
||||
<a
|
||||
className="text-sm text-accent-primary underline decoration-transparent transition-all duration-200 hover:text-accent-primary-hover hover:decoration-accent-primary-hover focus:text-accent-primary-hover focus:decoration-accent-primary-hover"
|
||||
href={termsOfService.externalUrl}
|
||||
href={termsOfServiceUrl}
|
||||
// Removed for WCAG compliance
|
||||
// target={termsOfService.openNewTab ? '_blank' : undefined}
|
||||
rel="noreferrer"
|
||||
|
|
|
|||
63
client/src/components/Auth/LegalConsent.tsx
Normal file
63
client/src/components/Auth/LegalConsent.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { Trans } from 'react-i18next';
|
||||
import type { TStartupConfig } from 'librechat-data-provider';
|
||||
import { hasPublishedPolicies, policyUrls } from '~/utils/policies';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
/** The links sit inside a sentence, so they keep an underline of their own:
|
||||
* colour alone would be the only thing telling them apart from the text
|
||||
* around them. No `target`, like the rest of the auth screens. */
|
||||
const linkClassName =
|
||||
'font-medium text-accent-primary underline underline-offset-2 transition-colors hover:text-accent-primary-hover focus-visible:text-accent-primary-hover';
|
||||
|
||||
/** Worded for whichever policies the deployment published, so one it never
|
||||
* wrote is never claimed to have been agreed to. */
|
||||
const consentKey = (privacyPolicyUrl?: string, termsOfServiceUrl?: string) => {
|
||||
if (termsOfServiceUrl == null) {
|
||||
return 'com_auth_legal_consent_privacy';
|
||||
}
|
||||
if (privacyPolicyUrl == null) {
|
||||
return 'com_auth_legal_consent_terms';
|
||||
}
|
||||
return 'com_auth_legal_consent';
|
||||
};
|
||||
|
||||
/**
|
||||
* The consent an account is created under, stated where it is created rather
|
||||
* than left to a link beneath the composer. It closes the auth card, so it
|
||||
* covers the registration form and the provider buttons alike: a first sign-in
|
||||
* through a provider creates an account too. Absent entirely on a deployment
|
||||
* that published neither policy.
|
||||
*/
|
||||
function LegalConsent({ startupConfig }: { startupConfig: TStartupConfig | null | undefined }) {
|
||||
const localize = useLocalize();
|
||||
const { privacyPolicyUrl, termsOfServiceUrl } = policyUrls(startupConfig);
|
||||
|
||||
/** The same answer the layout uses to drop its footer bar, so the two cannot
|
||||
* both be on the screen: it is false with nothing published, and on a
|
||||
* deployment that collects an explicit acceptance of its own. */
|
||||
if (!hasPublishedPolicies(startupConfig)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<p className="mt-4 text-center text-sm font-light text-text-secondary">
|
||||
<Trans
|
||||
i18nKey={consentKey(privacyPolicyUrl, termsOfServiceUrl)}
|
||||
components={{
|
||||
privacy: (
|
||||
<a className={linkClassName} href={privacyPolicyUrl} rel="noreferrer">
|
||||
{localize('com_ui_privacy_policy')}
|
||||
</a>
|
||||
),
|
||||
terms: (
|
||||
<a className={linkClassName} href={termsOfServiceUrl} rel="noreferrer">
|
||||
{localize('com_ui_terms_of_service')}
|
||||
</a>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
export default LegalConsent;
|
||||
|
|
@ -9,6 +9,7 @@ import type { TRegisterUser, TError } from 'librechat-data-provider';
|
|||
import type { TLoginLayoutContext } from '~/common';
|
||||
import { useLocalize, TranslationKeys } from '~/hooks';
|
||||
import { ErrorMessage } from './ErrorMessage';
|
||||
import LegalConsent from './LegalConsent';
|
||||
|
||||
const Registration: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
|
|
@ -237,6 +238,10 @@ const Registration: React.FC = () => {
|
|||
{isSubmitting ? <Spinner /> : localize('com_auth_continue')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Under the button it is agreed to, and read before the account is
|
||||
created; the auth layout drops its footer bar in exchange. */}
|
||||
<LegalConsent startupConfig={startupConfig} />
|
||||
</form>
|
||||
|
||||
<p className="my-4 text-center text-sm font-light text-text-secondary">
|
||||
|
|
|
|||
190
client/src/components/Auth/__tests__/AuthLayout.spec.tsx
Normal file
190
client/src/components/Auth/__tests__/AuthLayout.spec.tsx
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
import { I18nextProvider } from 'react-i18next';
|
||||
import type { TStartupConfig } from 'librechat-data-provider';
|
||||
import * as endpointQueries from '~/data-provider/Endpoints/queries';
|
||||
import * as miscDataProvider from '~/data-provider/Misc/queries';
|
||||
import { render, screen } from 'test/layout-test-utils';
|
||||
import AuthLayout from '~/components/Auth/AuthLayout';
|
||||
import i18n from '~/locales/i18n';
|
||||
|
||||
/**
|
||||
* The auth layout decides where the consent is stated, and a screen that states
|
||||
* it does not also carry the footer bar linking the same two policies. Both
|
||||
* ways in state it: which of them can create an account is not knowable here
|
||||
* (a provider sign-in and an LDAP sign-in both create one, and
|
||||
* ALLOW_SOCIAL_REGISTRATION is server-side), and the sentence is about
|
||||
* continuing, which both screens do.
|
||||
*
|
||||
* `test/setupTests.js` stubs `initReactI18next`, so nothing binds the app's
|
||||
* i18next instance to react-i18next the way `locales/i18n` does at runtime;
|
||||
* `Trans` reads it from the provider below instead.
|
||||
*/
|
||||
|
||||
const PRIVACY_URL = 'https://example.com/privacy';
|
||||
const TERMS_URL = 'https://example.com/terms';
|
||||
|
||||
const policies = {
|
||||
privacyPolicy: { externalUrl: PRIVACY_URL },
|
||||
termsOfService: { externalUrl: TERMS_URL },
|
||||
};
|
||||
|
||||
type Options = {
|
||||
pathname?: string;
|
||||
isFetching?: boolean;
|
||||
startupConfigError?: unknown;
|
||||
socialLoginEnabled?: boolean;
|
||||
/** What `socialLogins` lists, and whether the listed provider's own flag is
|
||||
* set: a button needs both, not just the global switch. */
|
||||
providers?: string[];
|
||||
googleLoginEnabled?: boolean;
|
||||
/** Partial on purpose: a fixture sets the policies under test, and the field
|
||||
* names are still checked against the real interface config. */
|
||||
interfaceConfig?: Partial<NonNullable<TStartupConfig['interface']>>;
|
||||
};
|
||||
|
||||
function setup({
|
||||
pathname = 'register',
|
||||
isFetching = false,
|
||||
startupConfigError = null,
|
||||
socialLoginEnabled = false,
|
||||
providers,
|
||||
googleLoginEnabled,
|
||||
interfaceConfig,
|
||||
}: Options) {
|
||||
const startupConfig = {
|
||||
appTitle: 'LibreChat',
|
||||
socialLoginEnabled,
|
||||
socialLogins: providers ?? (socialLoginEnabled ? ['google'] : []),
|
||||
googleLoginEnabled: googleLoginEnabled ?? socialLoginEnabled,
|
||||
serverDomain: 'mock-server',
|
||||
interface: interfaceConfig,
|
||||
} as unknown as TStartupConfig;
|
||||
|
||||
jest
|
||||
.spyOn(endpointQueries, 'useGetStartupConfig')
|
||||
//@ts-ignore - the layout reads only the resolved data
|
||||
.mockReturnValue({ data: startupConfig, isFetching: false, isError: false });
|
||||
jest
|
||||
.spyOn(miscDataProvider, 'useGetBannerQuery')
|
||||
//@ts-ignore - the banner is not under test
|
||||
.mockReturnValue({ data: null, isLoading: false, isError: false });
|
||||
|
||||
return render(
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<AuthLayout
|
||||
startupConfig={startupConfig}
|
||||
isFetching={isFetching}
|
||||
error={null}
|
||||
startupConfigError={startupConfigError}
|
||||
header={'Create your account'}
|
||||
pathname={pathname}
|
||||
>
|
||||
<form aria-label="Registration form" />
|
||||
</AuthLayout>
|
||||
</I18nextProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
const consent = () => screen.queryByText(/By continuing/i);
|
||||
const footerBar = () => document.querySelector('[role="contentinfo"]');
|
||||
|
||||
describe('AuthLayout legal placement', () => {
|
||||
/** The registration form states the consent itself, under its own submit
|
||||
* button (Registration.spec covers that); the layout's part is dropping the
|
||||
* footer bar so the same two policies are not linked twice. */
|
||||
test('registration drops the footer bar the consent replaces', () => {
|
||||
setup({ pathname: 'register', interfaceConfig: policies });
|
||||
|
||||
expect(footerBar()).toBeNull();
|
||||
expect(consent()).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('the login screen states it too', () => {
|
||||
setup({ pathname: 'login', socialLoginEnabled: true, interfaceConfig: policies });
|
||||
|
||||
expect(consent()).toBeInTheDocument();
|
||||
expect(document.querySelectorAll(`a[href="${PRIVACY_URL}"]`)).toHaveLength(1);
|
||||
expect(document.querySelectorAll(`a[href="${TERMS_URL}"]`)).toHaveLength(1);
|
||||
expect(footerBar()).toBeNull();
|
||||
});
|
||||
|
||||
/** No provider button is needed for the screen to be a way in: a first LDAP
|
||||
* sign-in creates the account through this very form. */
|
||||
test('a login screen with no provider button states it as well', () => {
|
||||
setup({ pathname: 'login', socialLoginEnabled: false, interfaceConfig: policies });
|
||||
|
||||
expect(consent()).toBeInTheDocument();
|
||||
expect(footerBar()).toBeNull();
|
||||
});
|
||||
|
||||
/** The second factor is not a way in of its own; the screen that sent the
|
||||
* reader here already stated the consent. */
|
||||
test('the second factor states nothing', () => {
|
||||
setup({ pathname: 'login/2fa', socialLoginEnabled: true, interfaceConfig: policies });
|
||||
|
||||
expect(consent()).not.toBeInTheDocument();
|
||||
expect(footerBar()).not.toBeNull();
|
||||
});
|
||||
|
||||
/** The consent and the footer bar read policy urls the same way, so a blank
|
||||
* one is not a policy on one screen and a link to nowhere on the other. */
|
||||
test('a blank policy url leaves neither a consent nor a link in the footer bar', () => {
|
||||
setup({ pathname: 'login', interfaceConfig: { privacyPolicy: { externalUrl: ' ' } } });
|
||||
|
||||
expect(consent()).not.toBeInTheDocument();
|
||||
expect(footerBar()).not.toBeNull();
|
||||
expect(document.querySelector('[role="contentinfo"] a')).toBeNull();
|
||||
});
|
||||
|
||||
/** Registration renders its form, and with it the consent, only once the
|
||||
* config has loaded without error. The footer bar carries the policies
|
||||
* until then, so the screen is never left with neither. */
|
||||
test('registration refetching its config keeps the footer bar', () => {
|
||||
setup({ pathname: 'register', isFetching: true, interfaceConfig: policies });
|
||||
|
||||
expect(consent()).not.toBeInTheDocument();
|
||||
expect(footerBar()).not.toBeNull();
|
||||
});
|
||||
|
||||
test('registration whose config failed keeps the footer bar', () => {
|
||||
setup({
|
||||
pathname: 'register',
|
||||
startupConfigError: new Error('config unavailable'),
|
||||
interfaceConfig: policies,
|
||||
});
|
||||
|
||||
expect(consent()).not.toBeInTheDocument();
|
||||
expect(footerBar()).not.toBeNull();
|
||||
});
|
||||
|
||||
/** The login screen states it itself, so a background refetch of an already
|
||||
* known config must not swap the sentence for the bar and back. */
|
||||
test('the login screen keeps the consent across a background refetch', () => {
|
||||
setup({ pathname: 'login', isFetching: true, interfaceConfig: policies });
|
||||
|
||||
expect(consent()).toBeInTheDocument();
|
||||
expect(footerBar()).toBeNull();
|
||||
});
|
||||
|
||||
/** A deployment that asks for explicit acceptance in a modal after sign-in
|
||||
* must not be told it already agreed by continuing. */
|
||||
test('a modal-acceptance deployment keeps the bare links instead', () => {
|
||||
setup({
|
||||
pathname: 'register',
|
||||
interfaceConfig: {
|
||||
privacyPolicy: { externalUrl: PRIVACY_URL },
|
||||
termsOfService: { externalUrl: TERMS_URL, modalAcceptance: true },
|
||||
},
|
||||
});
|
||||
|
||||
expect(consent()).not.toBeInTheDocument();
|
||||
expect(footerBar()).not.toBeNull();
|
||||
expect(document.querySelectorAll(`a[href="${TERMS_URL}"]`)).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('a deployment with no policies keeps the footer bar it always had', () => {
|
||||
setup({ pathname: 'register', interfaceConfig: undefined });
|
||||
|
||||
expect(consent()).not.toBeInTheDocument();
|
||||
expect(footerBar()).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import * as reactRouter from 'react-router-dom';
|
||||
import { I18nextProvider } from 'react-i18next';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import * as mockDataProvider from 'librechat-data-provider/react-query';
|
||||
import type { TStartupConfig } from 'librechat-data-provider';
|
||||
|
|
@ -9,6 +10,7 @@ import * as authMutations from '~/data-provider/Auth/mutations';
|
|||
import * as authQueries from '~/data-provider/Auth/queries';
|
||||
import Registration from '~/components/Auth/Registration';
|
||||
import AuthLayout from '~/components/Auth/AuthLayout';
|
||||
import i18n from '~/locales/i18n';
|
||||
|
||||
jest.mock('librechat-data-provider/react-query');
|
||||
|
||||
|
|
@ -87,17 +89,23 @@ const setup = ({
|
|||
.spyOn(miscDataProvider, 'useGetBannerQuery')
|
||||
//@ts-ignore - we don't need all parameters of the QueryObserverSuccessResult
|
||||
.mockReturnValue(useGetBannerQueryReturnValue);
|
||||
/* `test/setupTests.js` stubs `initReactI18next`, so nothing binds the app's
|
||||
i18next instance to react-i18next the way `locales/i18n` does at runtime.
|
||||
`Trans` reads it from this provider instead, and renders the sentence it
|
||||
renders in the app. */
|
||||
const renderResult = render(
|
||||
<AuthLayout
|
||||
startupConfig={useGetStartupConfigReturnValue.data as TStartupConfig}
|
||||
isFetching={useGetStartupConfigReturnValue.isFetching}
|
||||
error={null}
|
||||
startupConfigError={null}
|
||||
header={'Create your account'}
|
||||
pathname="register"
|
||||
>
|
||||
<Registration />
|
||||
</AuthLayout>,
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<AuthLayout
|
||||
startupConfig={useGetStartupConfigReturnValue.data as TStartupConfig}
|
||||
isFetching={useGetStartupConfigReturnValue.isFetching}
|
||||
error={null}
|
||||
startupConfigError={null}
|
||||
header={'Create your account'}
|
||||
pathname="register"
|
||||
>
|
||||
<Registration />
|
||||
</AuthLayout>
|
||||
</I18nextProvider>,
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
@ -230,3 +238,97 @@ test('shows error message when registration fails', async () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
const withInterface = (interfaceConfig: Partial<NonNullable<TStartupConfig['interface']>>) => ({
|
||||
...mockStartupConfig,
|
||||
data: { ...mockStartupConfig.data, interface: interfaceConfig },
|
||||
});
|
||||
|
||||
test('states the consent, with a link to each policy the deployment configured', () => {
|
||||
const { getByRole, getByText } = setup({
|
||||
useGetStartupConfigReturnValue: withInterface({
|
||||
privacyPolicy: { externalUrl: 'https://example.com/privacy' },
|
||||
termsOfService: { externalUrl: 'https://example.com/terms' },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(getByText(/By continuing, you agree to the/i)).toBeInTheDocument();
|
||||
|
||||
const terms = getByRole('link', { name: 'Terms of Service' });
|
||||
expect(terms).toHaveAttribute('href', 'https://example.com/terms');
|
||||
expect(terms).not.toHaveAttribute('target');
|
||||
|
||||
const privacy = getByRole('link', { name: 'Privacy Policy' });
|
||||
expect(privacy).toHaveAttribute('href', 'https://example.com/privacy');
|
||||
expect(privacy).not.toHaveAttribute('target');
|
||||
});
|
||||
|
||||
test('claims agreement only to the policy the deployment published', () => {
|
||||
const { getByRole, getByText, queryByRole } = setup({
|
||||
useGetStartupConfigReturnValue: withInterface({
|
||||
privacyPolicy: { externalUrl: 'https://example.com/privacy' },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(getByText(/By continuing, you acknowledge the/i)).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: 'Privacy Policy' })).toBeInTheDocument();
|
||||
expect(queryByRole('link', { name: 'Terms of Service' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('claims agreement to terms a deployment published without a privacy policy', () => {
|
||||
const { getByRole, getByText, queryByRole } = setup({
|
||||
useGetStartupConfigReturnValue: withInterface({
|
||||
termsOfService: { externalUrl: 'https://example.com/terms' },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(getByText(/By continuing, you agree to the/i)).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: 'Terms of Service' })).toBeInTheDocument();
|
||||
expect(queryByRole('link', { name: 'Privacy Policy' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
/** `externalUrl` is an optional string, so an operator can set it to nothing.
|
||||
* A blank one would link back to this page and name a policy that does not
|
||||
* exist, which is worse than saying nothing. */
|
||||
test('treats a blank policy url as a policy the deployment never published', () => {
|
||||
const { getByText, queryByRole } = setup({
|
||||
useGetStartupConfigReturnValue: withInterface({
|
||||
privacyPolicy: { externalUrl: ' ' },
|
||||
termsOfService: { externalUrl: 'https://example.com/terms' },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(getByText(/By continuing, you agree to the/i)).toBeInTheDocument();
|
||||
expect(queryByRole('link', { name: 'Privacy Policy' })).not.toBeInTheDocument();
|
||||
expect(document.querySelector('a[href=""]')).toBeNull();
|
||||
});
|
||||
|
||||
test('says nothing about policies a deployment never configured', () => {
|
||||
const { queryByText } = setup();
|
||||
|
||||
expect(queryByText(/By continuing/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
/** A deployment that collects an explicit acceptance after sign-in is not one
|
||||
* where continuing is the agreement, so the form states nothing. */
|
||||
test('says nothing on a deployment that accepts its terms in a modal', () => {
|
||||
const { queryByText } = setup({
|
||||
useGetStartupConfigReturnValue: withInterface({
|
||||
privacyPolicy: { externalUrl: 'https://example.com/privacy' },
|
||||
termsOfService: { externalUrl: 'https://example.com/terms', modalAcceptance: true },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(queryByText(/By continuing/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('says nothing when every configured policy url is blank', () => {
|
||||
const { queryByText } = setup({
|
||||
useGetStartupConfigReturnValue: withInterface({
|
||||
privacyPolicy: { externalUrl: '' },
|
||||
termsOfService: { externalUrl: '' },
|
||||
}),
|
||||
});
|
||||
|
||||
expect(queryByText(/By continuing/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -216,9 +216,9 @@ function ChatView({ index = 0, project }: { index?: number; project?: TChatProje
|
|||
centerFormOnLanding={centerFormOnLanding}
|
||||
/>
|
||||
)}
|
||||
{/* The generic disclaimer is the welcome screen's; a
|
||||
deployment's own footer, privacy policy and terms
|
||||
stay with the conversation that always showed them. */}
|
||||
{/* The generic disclaimer and the policy links are the
|
||||
welcome screen's; a deployment's own footer stays
|
||||
with the conversation that always showed it. */}
|
||||
{!isLandingPage && configuredFooter && <Footer configuredOnly />}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,17 +4,18 @@ import ReactMarkdown from 'react-markdown';
|
|||
import { Constants, hasConfiguredFooter } from 'librechat-data-provider';
|
||||
import type { TStartupConfig } from 'librechat-data-provider';
|
||||
import { useGetStartupConfig } from '~/data-provider';
|
||||
import { policyUrls } from '~/utils/policies';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
type FooterProps = {
|
||||
className?: string;
|
||||
startupConfig?: FooterStartupConfig | null;
|
||||
/** A started conversation keeps only what the deployment configured. The
|
||||
/** A started conversation keeps only the footer the deployment wrote. The
|
||||
* generic model disclaimer belongs to the welcome screen, where it is first
|
||||
* read, but a custom footer, a privacy policy and terms of service are the
|
||||
* operator's own content: scoping the disclaimer out must not take their
|
||||
* configuration off the screen that used to carry it. With nothing
|
||||
* configured, this renders nothing at all. */
|
||||
* read, and the policy links belong where they are agreed to: registration
|
||||
* states the consent with both links, and the welcome screen the
|
||||
* conversation starts from carries them under the composer. With no custom
|
||||
* footer configured, this renders nothing at all. */
|
||||
configuredOnly?: boolean;
|
||||
};
|
||||
|
||||
|
|
@ -42,10 +43,10 @@ const shellHasConfiguredFooter =
|
|||
* over. Both decisions read this one answer so they cannot disagree.
|
||||
*
|
||||
* Until `/api/config` answers, that answer is the shell's, which is the
|
||||
* deployment's own configuration (`librechat.yaml` plus `CUSTOM_FOOTER`). A DB
|
||||
* config override that adds or removes a policy link for the caller's tenant,
|
||||
* role or user is resolved only by `/api/config`, so on such a deployment the
|
||||
* resolved answer — the one that wins here — can differ from the shell's.
|
||||
* deployment's own `CUSTOM_FOOTER`. A DB config override that sets or clears
|
||||
* the footer for the caller's tenant, role or user is resolved only by
|
||||
* `/api/config`, so on such a deployment the resolved answer (the one that
|
||||
* wins here) can differ from the shell's.
|
||||
*/
|
||||
export function useConfiguredFooter(): boolean {
|
||||
const { data: config, isSuccess } = useGetStartupConfig();
|
||||
|
|
@ -59,23 +60,24 @@ function Footer({ className, startupConfig, configuredOnly = false }: FooterProp
|
|||
const config = shouldFetchConfig ? fetchedConfig : startupConfig;
|
||||
const localize = useLocalize();
|
||||
|
||||
const privacyPolicy = config?.interface?.privacyPolicy;
|
||||
const termsOfService = config?.interface?.termsOfService;
|
||||
/** The same reading the consent and the auth footer use: a blank url is not
|
||||
* a published policy. */
|
||||
const { privacyPolicyUrl, termsOfServiceUrl } = policyUrls(configuredOnly ? undefined : config);
|
||||
|
||||
const privacyPolicyRender = privacyPolicy?.externalUrl != null && (
|
||||
<a className="text-text-muted underline" href={privacyPolicy.externalUrl} rel="noreferrer">
|
||||
const privacyPolicyRender = privacyPolicyUrl != null && (
|
||||
<a className="text-text-muted underline" href={privacyPolicyUrl} rel="noreferrer">
|
||||
{localize('com_ui_privacy_policy')}
|
||||
</a>
|
||||
);
|
||||
|
||||
const termsOfServiceRender = termsOfService?.externalUrl != null && (
|
||||
<a className="text-text-muted underline" href={termsOfService.externalUrl} rel="noreferrer">
|
||||
const termsOfServiceRender = termsOfServiceUrl != null && (
|
||||
<a className="text-text-muted underline" href={termsOfServiceUrl} rel="noreferrer">
|
||||
{localize('com_ui_terms_of_service')}
|
||||
</a>
|
||||
);
|
||||
|
||||
const configuredFooter = typeof config?.customFooter === 'string' ? config.customFooter : null;
|
||||
/** The generic disclaimer is the part a conversation drops; operator content is not. */
|
||||
/** The generic disclaimer is the part a conversation drops; the operator's own footer is not. */
|
||||
const genericFooter = configuredOnly
|
||||
? ''
|
||||
: '[LibreChat ' +
|
||||
|
|
|
|||
|
|
@ -53,4 +53,58 @@ describe('Footer', () => {
|
|||
expect(screen.getByRole('link', { name: 'Privacy policy' })).not.toHaveAttribute('target');
|
||||
expect(screen.getByRole('link', { name: 'Terms of service' })).not.toHaveAttribute('target');
|
||||
});
|
||||
|
||||
test('leaves the policy links behind once a conversation starts', () => {
|
||||
render(
|
||||
<Footer
|
||||
configuredOnly
|
||||
startupConfig={{
|
||||
customFooter: 'Operator policy',
|
||||
interface: {
|
||||
privacyPolicy: { externalUrl: 'https://example.com/privacy' },
|
||||
termsOfService: { externalUrl: 'https://example.com/terms' },
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByText('Operator policy')).toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: 'Privacy policy' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: 'Terms of service' })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
/** `externalUrl` is an optional string, so an operator can set it to nothing;
|
||||
* a link to a blank url points back at the page the reader is on. */
|
||||
test('treats a blank policy url as a policy the deployment never published', () => {
|
||||
const { container } = render(
|
||||
<Footer
|
||||
startupConfig={{
|
||||
interface: {
|
||||
privacyPolicy: { externalUrl: ' ' },
|
||||
termsOfService: { externalUrl: '' },
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.queryByRole('link', { name: 'Privacy policy' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('link', { name: 'Terms of service' })).not.toBeInTheDocument();
|
||||
expect(container.querySelector('a[href=""]')).toBeNull();
|
||||
});
|
||||
|
||||
test('places no bar in a conversation whose deployment configured only policies', () => {
|
||||
const { container } = render(
|
||||
<Footer
|
||||
configuredOnly
|
||||
startupConfig={{
|
||||
interface: {
|
||||
privacyPolicy: { externalUrl: 'https://example.com/privacy' },
|
||||
termsOfService: { externalUrl: 'https://example.com/terms' },
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -253,6 +253,9 @@
|
|||
"com_auth_github_login": "Continue with Github",
|
||||
"com_auth_google_login": "Continue with Google",
|
||||
"com_auth_here": "HERE",
|
||||
"com_auth_legal_consent": "By continuing, you agree to the <terms>Terms of Service</terms> and acknowledge the <privacy>Privacy Policy</privacy>.",
|
||||
"com_auth_legal_consent_privacy": "By continuing, you acknowledge the <privacy>Privacy Policy</privacy>.",
|
||||
"com_auth_legal_consent_terms": "By continuing, you agree to the <terms>Terms of Service</terms>.",
|
||||
"com_auth_login": "Login",
|
||||
"com_auth_login_with_new_password": "You may now login with your new password.",
|
||||
"com_auth_name_max_length": "Name must be less than 80 characters",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { TAskFunction } from '~/common';
|
|||
import logger from './logger';
|
||||
|
||||
export * from './map';
|
||||
export * from './policies';
|
||||
export * from './json';
|
||||
export * from './icons';
|
||||
export * from './svg';
|
||||
|
|
|
|||
40
client/src/utils/policies.ts
Normal file
40
client/src/utils/policies.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import type { TStartupConfig } from 'librechat-data-provider';
|
||||
|
||||
/**
|
||||
* The policy links a deployment published, as the surfaces that render them
|
||||
* agree to read it. `externalUrl` is an optional string, so an operator can
|
||||
* leave it blank; a blank one is not a published policy, because rendered as a
|
||||
* link it points back at the page the reader is on and names a document that
|
||||
* does not exist.
|
||||
*/
|
||||
export function publishedPolicyUrl(externalUrl?: string): string | undefined {
|
||||
const url = externalUrl?.trim();
|
||||
return url != null && url !== '' ? url : undefined;
|
||||
}
|
||||
|
||||
type PolicySource = {
|
||||
interface?: Pick<NonNullable<TStartupConfig['interface']>, 'privacyPolicy' | 'termsOfService'>;
|
||||
};
|
||||
|
||||
export function policyUrls(startupConfig: PolicySource | null | undefined) {
|
||||
return {
|
||||
privacyPolicyUrl: publishedPolicyUrl(startupConfig?.interface?.privacyPolicy?.externalUrl),
|
||||
termsOfServiceUrl: publishedPolicyUrl(startupConfig?.interface?.termsOfService?.externalUrl),
|
||||
};
|
||||
}
|
||||
|
||||
/** Whether the deployment published anything to consent to by continuing. The
|
||||
* auth layout reads this to choose between the consent and its footer bar, so
|
||||
* the two cannot disagree about whether the sentence is on the screen.
|
||||
*
|
||||
* A deployment that asks for the terms to be accepted in a modal has its own
|
||||
* explicit acceptance after sign-in (`routes/Root.tsx`), so a sentence saying
|
||||
* the reader already agreed by continuing would contradict the dialog it is
|
||||
* about to show; those screens keep the bare links they always had. */
|
||||
export function hasPublishedPolicies(startupConfig: PolicySource | null | undefined): boolean {
|
||||
if (startupConfig?.interface?.termsOfService?.modalAcceptance === true) {
|
||||
return false;
|
||||
}
|
||||
const { privacyPolicyUrl, termsOfServiceUrl } = policyUrls(startupConfig);
|
||||
return privacyPolicyUrl != null || termsOfServiceUrl != null;
|
||||
}
|
||||
|
|
@ -10,10 +10,9 @@ import { deleteConversations, deleteMessagesByConversation, seedConversations }
|
|||
* deployment's own configuration, so two cases have to keep working: a document
|
||||
* that carries no answer at all (the Vite dev server serves `client/index.html`
|
||||
* itself, and a proxy could strip the script), and a caller whose resolved
|
||||
* configuration disagrees with it — a per-tenant, role or user config override
|
||||
* of `interface.privacyPolicy` is resolved only by `/api/config`. In both, the
|
||||
* resolved answer is the one that decides, and the bar never covers the
|
||||
* composer once it has.
|
||||
* configuration disagrees with it, since a per-tenant, role or user override of
|
||||
* `customFooter` is resolved only by `/api/config`. In both, the resolved answer
|
||||
* is the one that decides, and the bar never covers the composer once it has.
|
||||
*
|
||||
* The footer is hidden below `sm`, so this runs on the desktop viewport it
|
||||
* describes.
|
||||
|
|
@ -103,21 +102,19 @@ test.describe('footer answer in the shell', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('a policy link this caller alone has still clears the composer @scenario:an-override-policy-link-clears-the-composer', async ({
|
||||
test('a footer this caller alone has still clears the composer @scenario:an-override-custom-footer-clears-the-composer', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const conversationId = randomUUID();
|
||||
await seedConversations(getE2EUser().email, [
|
||||
{ conversationId, title: 'Override policy link', updatedAt: new Date() },
|
||||
{ conversationId, title: 'Override custom footer', updatedAt: new Date() },
|
||||
]);
|
||||
|
||||
try {
|
||||
/** The harness deployment configures no footer, so its document says so:
|
||||
* this caller's resolved configuration is the one that disagrees. */
|
||||
await serveResolvedConfig(page, {
|
||||
interface: { privacyPolicy: { externalUrl: 'https://example.com/privacy' } },
|
||||
});
|
||||
await serveResolvedConfig(page, { customFooter: CUSTOM_FOOTER });
|
||||
|
||||
await page.goto(`/c/${conversationId}`, { timeout: 15000 });
|
||||
await expect(page.locator(COMPOSER)).toBeVisible();
|
||||
|
|
@ -126,10 +123,9 @@ test.describe('footer answer in the shell', () => {
|
|||
'the deployment was expected to report no configured footer',
|
||||
).toBe(false);
|
||||
|
||||
const policyLink = page.getByRole('link', { name: /privacy/i });
|
||||
await expect(policyLink).toBeVisible({ timeout: 15000 });
|
||||
await expect(policyLink).toHaveAttribute('href', 'https://example.com/privacy');
|
||||
await expectFooterBelowComposer(page, policyLink);
|
||||
const footer = page.getByText(CUSTOM_FOOTER);
|
||||
await expect(footer).toBeVisible({ timeout: 15000 });
|
||||
await expectFooterBelowComposer(page, footer);
|
||||
|
||||
/** The bar arrived after the first paint, so the check that matters is the
|
||||
* composer's action row still taking its own clicks. */
|
||||
|
|
|
|||
147
e2e/specs/mock/scenarios/policy-links-placement.spec.ts
Normal file
147
e2e/specs/mock/scenarios/policy-links-placement.spec.ts
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
import { randomUUID } from 'crypto';
|
||||
import { expect, test } from '@playwright/test';
|
||||
import type { Page } from '@playwright/test';
|
||||
import { getE2EUser } from '../../../setup/user';
|
||||
import { deleteConversations, deleteMessagesByConversation, seedConversations } from '../db';
|
||||
|
||||
/**
|
||||
* A policy link is read where it is agreed to. Registration states the consent
|
||||
* with both links, and the welcome screen a conversation starts from carries
|
||||
* them under its composer; the conversation itself does not, on every turn of
|
||||
* every thread. What a conversation keeps is the operator's own custom footer.
|
||||
*
|
||||
* The second scenario is the layout half of the same change: the footer bar is
|
||||
* absolutely positioned in a zero-height wrapper, so the composer reserves its
|
||||
* band. A deployment that configures policy links and nothing else now paints
|
||||
* no bar in a conversation, so it must not reserve one either.
|
||||
*
|
||||
* The footer is hidden below `sm`, so this runs on the desktop viewport it
|
||||
* describes.
|
||||
*/
|
||||
|
||||
const COMPOSER = '[data-testid="composer-surface"]';
|
||||
const PRIVACY_URL = 'https://example.com/privacy';
|
||||
const TERMS_URL = 'https://example.com/terms';
|
||||
|
||||
test.use({ viewport: { width: 1280, height: 800 } });
|
||||
|
||||
/** The harness deployment configures no policies, so a spec that needs them
|
||||
* answers the startup config for itself rather than changing the config every
|
||||
* other spec reads. The rest of `interface` is preserved: replacing it would
|
||||
* take permissions and capabilities off the page with it. */
|
||||
async function withPolicies(page: Page, policies: Record<string, unknown>) {
|
||||
await page.route('**/api/config', async (route) => {
|
||||
const response = await route.fetch();
|
||||
const config = await response.json();
|
||||
await route.fulfill({
|
||||
response,
|
||||
json: { ...config, interface: { ...config.interface, ...policies } },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function composerBottom(page: Page) {
|
||||
const box = await page.locator(COMPOSER).boundingBox();
|
||||
expect(box).not.toBeNull();
|
||||
return Math.round((box?.y ?? 0) + (box?.height ?? 0));
|
||||
}
|
||||
|
||||
test.describe('policy link placement', () => {
|
||||
test('the policy links leave a started conversation @scenario:policy-links-leave-a-started-conversation', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const conversationId = randomUUID();
|
||||
await seedConversations(getE2EUser().email, [
|
||||
{ conversationId, title: 'Policy link placement', updatedAt: new Date() },
|
||||
]);
|
||||
|
||||
try {
|
||||
await withPolicies(page, {
|
||||
privacyPolicy: { externalUrl: PRIVACY_URL },
|
||||
termsOfService: { externalUrl: TERMS_URL },
|
||||
});
|
||||
|
||||
await page.goto('/c/new', { timeout: 15000 });
|
||||
await expect(page.locator(`a[href="${PRIVACY_URL}"]`)).toBeVisible({ timeout: 15000 });
|
||||
await expect(page.locator(`a[href="${TERMS_URL}"]`)).toBeVisible();
|
||||
|
||||
await page.goto(`/c/${conversationId}`, { timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible();
|
||||
/** The config has answered by now: the welcome screen above read it from
|
||||
* the same cache, so an empty count here is the placement and not a
|
||||
* request still in flight. */
|
||||
await expect(page.locator(`a[href="${PRIVACY_URL}"]`)).toHaveCount(0);
|
||||
await expect(page.locator(`a[href="${TERMS_URL}"]`)).toHaveCount(0);
|
||||
} finally {
|
||||
await deleteMessagesByConversation([conversationId]);
|
||||
await deleteConversations([conversationId]);
|
||||
}
|
||||
});
|
||||
|
||||
test('an empty custom footer reserves no band either @scenario:an-empty-custom-footer-leaves-no-band-in-a-conversation', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const conversationId = randomUUID();
|
||||
await seedConversations(getE2EUser().email, [
|
||||
{ conversationId, title: 'Empty custom footer', updatedAt: new Date() },
|
||||
]);
|
||||
|
||||
try {
|
||||
await page.goto(`/c/${conversationId}`, { timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible();
|
||||
const withoutFooter = await composerBottom(page);
|
||||
|
||||
/** An operator who sets the footer to nothing is suppressing the welcome
|
||||
* screen's disclaimer; a conversation renders no bar for it. */
|
||||
await page.route('**/api/config', async (route) => {
|
||||
const response = await route.fetch();
|
||||
const config = await response.json();
|
||||
await route.fulfill({ response, json: { ...config, customFooter: '' } });
|
||||
});
|
||||
await page.reload({ timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible();
|
||||
|
||||
expect(
|
||||
await composerBottom(page),
|
||||
'the conversation reserved a band for an empty footer',
|
||||
).toBe(withoutFooter);
|
||||
} finally {
|
||||
await deleteMessagesByConversation([conversationId]);
|
||||
await deleteConversations([conversationId]);
|
||||
}
|
||||
});
|
||||
|
||||
test('a deployment with policies alone reserves no band in a conversation @scenario:a-policy-only-deployment-leaves-no-band-in-a-conversation', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const conversationId = randomUUID();
|
||||
await seedConversations(getE2EUser().email, [
|
||||
{ conversationId, title: 'Policy only clearance', updatedAt: new Date() },
|
||||
]);
|
||||
|
||||
try {
|
||||
await page.goto(`/c/${conversationId}`, { timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible();
|
||||
const withoutPolicies = await composerBottom(page);
|
||||
|
||||
await withPolicies(page, {
|
||||
privacyPolicy: { externalUrl: PRIVACY_URL },
|
||||
termsOfService: { externalUrl: TERMS_URL },
|
||||
});
|
||||
await page.reload({ timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible();
|
||||
await expect(page.locator(`a[href="${PRIVACY_URL}"]`)).toHaveCount(0);
|
||||
|
||||
expect(
|
||||
await composerBottom(page),
|
||||
'the conversation reserved a band for a bar it does not paint',
|
||||
).toBe(withoutPolicies);
|
||||
} finally {
|
||||
await deleteMessagesByConversation([conversationId]);
|
||||
await deleteConversations([conversationId]);
|
||||
}
|
||||
});
|
||||
});
|
||||
218
e2e/specs/mock/scenarios/registration-consent.spec.ts
Normal file
218
e2e/specs/mock/scenarios/registration-consent.spec.ts
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { TStartupConfig } from 'librechat-data-provider';
|
||||
import type { Browser, Page } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* A deployment's policies are agreed to on the way in, so both ways in state
|
||||
* the consent, with a direct link to each policy it published: the registration
|
||||
* form under its own submit button, the login screen below the provider
|
||||
* buttons. Which of them creates the account is not knowable in the client, and
|
||||
* the sentence is about continuing, which both screens do. It is worded for
|
||||
* what is configured: a deployment that published only one policy must not
|
||||
* claim the reader agreed to the other, and one that published neither says
|
||||
* nothing at all.
|
||||
*
|
||||
* These run unauthenticated, because an authenticated session redirects away
|
||||
* from the auth screens before anything renders.
|
||||
*/
|
||||
|
||||
const PRIVACY_URL = 'https://example.com/privacy';
|
||||
const TERMS_URL = 'https://example.com/terms';
|
||||
|
||||
type ConfigOverrides = Partial<TStartupConfig>;
|
||||
|
||||
/** The harness deployment configures no policies, so a spec that needs them
|
||||
* answers the startup config for itself. `interface` is merged rather than
|
||||
* replaced: overwriting it would take the page's own capabilities with it. */
|
||||
async function withConfig(page: Page, overrides: ConfigOverrides) {
|
||||
await page.route('**/api/config', async (route) => {
|
||||
const response = await route.fetch();
|
||||
const config = (await response.json()) as TStartupConfig;
|
||||
await route.fulfill({
|
||||
response,
|
||||
json: {
|
||||
...config,
|
||||
...overrides,
|
||||
interface: { ...config.interface, ...overrides.interface },
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** A signed-out visitor, which is the only one who ever reaches these screens. */
|
||||
async function openAuthScreen(
|
||||
browser: Browser,
|
||||
baseURL: string | undefined,
|
||||
path: string,
|
||||
overrides: ConfigOverrides,
|
||||
) {
|
||||
const context = await browser.newContext({ storageState: undefined, baseURL });
|
||||
const page = await context.newPage();
|
||||
await withConfig(page, overrides);
|
||||
await page.goto(path, { timeout: 15000 });
|
||||
await expect(page.getByRole('textbox', { name: 'Email' })).toBeVisible({ timeout: 15000 });
|
||||
return { context, page };
|
||||
}
|
||||
|
||||
const bothPolicies: ConfigOverrides = {
|
||||
interface: {
|
||||
privacyPolicy: { externalUrl: PRIVACY_URL },
|
||||
termsOfService: { externalUrl: TERMS_URL },
|
||||
},
|
||||
};
|
||||
|
||||
test.describe('registration consent', () => {
|
||||
test('registration states the consent with a link to each policy @scenario:registration-states-the-policy-consent', async ({
|
||||
browser,
|
||||
baseURL,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const { context, page } = await openAuthScreen(browser, baseURL, '/register', bothPolicies);
|
||||
|
||||
try {
|
||||
await expect(page.getByText(/By continuing, you agree to the/i)).toBeVisible();
|
||||
|
||||
/** One link each: the screen states the consent instead of also carrying
|
||||
* the footer bar that used to repeat both links beneath it. */
|
||||
const privacy = page.locator(`a[href="${PRIVACY_URL}"]`);
|
||||
const terms = page.locator(`a[href="${TERMS_URL}"]`);
|
||||
await expect(privacy).toHaveCount(1);
|
||||
await expect(terms).toHaveCount(1);
|
||||
await expect(privacy).toBeVisible();
|
||||
await expect(terms).toBeVisible();
|
||||
|
||||
/** The links are read by name, so they carry their own text rather than
|
||||
* leaving a screen reader with the sentence around them. */
|
||||
await expect(privacy).toHaveText('Privacy Policy');
|
||||
await expect(terms).toHaveText('Terms of Service');
|
||||
|
||||
/** Reachable by keyboard, not only by pointer. */
|
||||
await terms.focus();
|
||||
await expect(terms).toBeFocused();
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('the consent names only the policy the deployment published @scenario:registration-consent-names-only-the-published-policy', async ({
|
||||
browser,
|
||||
baseURL,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const { context, page } = await openAuthScreen(browser, baseURL, '/register', {
|
||||
interface: { privacyPolicy: { externalUrl: PRIVACY_URL } },
|
||||
});
|
||||
|
||||
try {
|
||||
await expect(page.getByText(/By continuing, you acknowledge the/i)).toBeVisible();
|
||||
await expect(page.locator(`a[href="${PRIVACY_URL}"]`)).toHaveCount(1);
|
||||
await expect(page.getByText(/agree to the Terms of Service/i)).toHaveCount(0);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('a deployment with no policies states no consent @scenario:registration-without-policies-states-no-consent', async ({
|
||||
browser,
|
||||
baseURL,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
const { context, page } = await openAuthScreen(browser, baseURL, '/register', {});
|
||||
|
||||
try {
|
||||
await expect(page.getByRole('button', { name: 'Submit registration' })).toBeVisible();
|
||||
await expect(page.getByText(/By continuing/i)).toHaveCount(0);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('a blank policy url is not a published policy @scenario:a-blank-policy-url-is-not-a-published-policy', async ({
|
||||
browser,
|
||||
baseURL,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
/** `externalUrl` is an optional string, so this is a configuration an
|
||||
* operator can write; a link to nothing would name a document that does
|
||||
* not exist and navigate back to this page. */
|
||||
const { context, page } = await openAuthScreen(browser, baseURL, '/register', {
|
||||
interface: { privacyPolicy: { externalUrl: '' }, termsOfService: { externalUrl: '' } },
|
||||
});
|
||||
|
||||
try {
|
||||
await expect(page.getByRole('button', { name: 'Submit registration' })).toBeVisible();
|
||||
await expect(page.getByText(/By continuing/i)).toHaveCount(0);
|
||||
await expect(page.locator('a[href=""]')).toHaveCount(0);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('the login screen states the consent without any provider button @scenario:the-login-screen-states-the-consent', async ({
|
||||
browser,
|
||||
baseURL,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
/** No provider button is needed for this screen to be a way in: a first
|
||||
* LDAP sign-in creates the account through this very form
|
||||
* (api/strategies/ldapStrategy.js). */
|
||||
const { context, page } = await openAuthScreen(browser, baseURL, '/login', bothPolicies);
|
||||
|
||||
try {
|
||||
await expect(page.getByRole('link', { name: /Continue with/i })).toHaveCount(0);
|
||||
await expect(page.getByText(/By continuing, you agree to the/i)).toBeVisible();
|
||||
await expect(page.locator(`a[href="${PRIVACY_URL}"]`)).toHaveCount(1);
|
||||
await expect(page.locator(`a[href="${TERMS_URL}"]`)).toHaveCount(1);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('a modal-acceptance deployment keeps the bare links @scenario:a-modal-acceptance-deployment-states-no-passive-consent', async ({
|
||||
browser,
|
||||
baseURL,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
/** That deployment asks for the terms to be accepted in a dialog after
|
||||
* sign-in, so a sentence saying the reader already agreed by continuing
|
||||
* would contradict the dialog it is about to show. */
|
||||
const { context, page } = await openAuthScreen(browser, baseURL, '/register', {
|
||||
interface: {
|
||||
privacyPolicy: { externalUrl: PRIVACY_URL },
|
||||
termsOfService: { externalUrl: TERMS_URL, modalAcceptance: true },
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await expect(page.getByText(/By continuing/i)).toHaveCount(0);
|
||||
await expect(page.locator(`a[href="${PRIVACY_URL}"]`)).toHaveCount(1);
|
||||
await expect(page.locator(`a[href="${TERMS_URL}"]`)).toHaveCount(1);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('a login screen that can create an account states the consent @scenario:a-social-login-screen-states-the-consent', async ({
|
||||
browser,
|
||||
baseURL,
|
||||
}) => {
|
||||
test.setTimeout(60000);
|
||||
/** A provider button on the login screen creates the account on a first
|
||||
* sign-in, so that screen is a place an account is created. */
|
||||
const { context, page } = await openAuthScreen(browser, baseURL, '/login', {
|
||||
...bothPolicies,
|
||||
socialLoginEnabled: true,
|
||||
googleLoginEnabled: true,
|
||||
socialLogins: ['google'],
|
||||
});
|
||||
|
||||
try {
|
||||
await expect(page.getByRole('link', { name: /Continue with Google/i })).toBeVisible();
|
||||
await expect(page.getByText(/By continuing, you agree to the/i)).toBeVisible();
|
||||
await expect(page.locator(`a[href="${PRIVACY_URL}"]`)).toHaveCount(1);
|
||||
await expect(page.locator(`a[href="${TERMS_URL}"]`)).toHaveCount(1);
|
||||
} finally {
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -11,35 +11,20 @@ const flagOf = (html: string): boolean | undefined => {
|
|||
};
|
||||
|
||||
describe('injectConfiguredFooterBootstrap', () => {
|
||||
it('answers yes for each kind of configured footer content', () => {
|
||||
it('answers yes for the footer the deployment configured', () => {
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL, { customFooter: 'Operator' }))).toBe(true);
|
||||
expect(
|
||||
flagOf(
|
||||
injectConfiguredFooterBootstrap(SHELL, {
|
||||
interfaceConfig: { privacyPolicy: { externalUrl: 'https://example.com/privacy' } },
|
||||
}),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
flagOf(
|
||||
injectConfiguredFooterBootstrap(SHELL, {
|
||||
interfaceConfig: { termsOfService: { externalUrl: 'https://example.com/terms' } },
|
||||
}),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL, { customFooter: 'A | B' }))).toBe(true);
|
||||
});
|
||||
|
||||
it('answers no for a deployment that configured nothing', () => {
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL, {}))).toBe(false);
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL))).toBe(false);
|
||||
expect(
|
||||
flagOf(
|
||||
injectConfiguredFooterBootstrap(SHELL, {
|
||||
customFooter: undefined,
|
||||
interfaceConfig: { privacyPolicy: {}, termsOfService: {} },
|
||||
}),
|
||||
),
|
||||
).toBe(false);
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL, { customFooter: undefined }))).toBe(false);
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL, { customFooter: null }))).toBe(false);
|
||||
/** Set to nothing: the welcome screen's disclaimer is suppressed, and a
|
||||
* conversation renders no bar to reserve a band for. */
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL, { customFooter: '' }))).toBe(false);
|
||||
expect(flagOf(injectConfiguredFooterBootstrap(SHELL, { customFooter: ' ' }))).toBe(false);
|
||||
});
|
||||
|
||||
it('places the answer ahead of the app that reads it', () => {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
import { hasConfiguredFooter } from 'librechat-data-provider';
|
||||
import type { TInterfaceConfig } from 'librechat-data-provider';
|
||||
import { injectBootstrapConfig } from './bootstrap';
|
||||
|
||||
const CONFIGURED_FOOTER_SENTINEL = 'data-librechat-configured-footer="true"';
|
||||
|
||||
/** What the deployment configured, as the server holds it: the footer env var
|
||||
* and the interface config the app loaded. */
|
||||
/** What the deployment configured, as the server holds it: the footer env var. */
|
||||
export interface ConfiguredFooterSource {
|
||||
customFooter?: string | null;
|
||||
interfaceConfig?: Pick<TInterfaceConfig, 'privacyPolicy' | 'termsOfService'> | null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -19,13 +16,9 @@ export interface ConfiguredFooterSource {
|
|||
* server already knows when it serves the document, so it says so and no client
|
||||
* has to guess: a first-ever visit to a configured deployment paints the
|
||||
* composer in its final position instead of correcting by the bar's height.
|
||||
* The answer is the deployment's own configuration — `librechat.yaml` plus
|
||||
* `CUSTOM_FOOTER` — because the document is served before there is a caller to
|
||||
* resolve: a per-tenant, role or user config override of `privacyPolicy` or
|
||||
* `termsOfService` is resolved by `/api/config`, and the client prefers that
|
||||
* resolved answer over this one. Reading the effective config here would cost
|
||||
* an override query on the document that carries the conversation's LCP, and
|
||||
* still could not resolve role or user overrides pre-authentication.
|
||||
* The answer is the deployment's own `CUSTOM_FOOTER`, because the document is
|
||||
* served before there is a caller whose config overrides could be resolved; the
|
||||
* client prefers `/api/config`'s resolved answer once it has it.
|
||||
*
|
||||
* Always injected, including the negative answer, so an absent flag means "no
|
||||
* server said" (the Vite dev server) rather than "no footer".
|
||||
|
|
@ -39,7 +32,6 @@ export const injectConfiguredFooterBootstrap = (
|
|||
values: {
|
||||
hasConfiguredFooter: hasConfiguredFooter({
|
||||
customFooter: source?.customFooter ?? undefined,
|
||||
interface: source?.interfaceConfig ?? null,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,26 +1,20 @@
|
|||
import { hasConfiguredFooter } from './footer';
|
||||
|
||||
describe('hasConfiguredFooter', () => {
|
||||
it('is true for any content the deployment configured itself', () => {
|
||||
it('is true for a footer the deployment configured itself', () => {
|
||||
expect(hasConfiguredFooter({ customFooter: 'Operator policy' })).toBe(true);
|
||||
/** An operator who set the footer to nothing still set it. */
|
||||
expect(hasConfiguredFooter({ customFooter: '' })).toBe(true);
|
||||
expect(
|
||||
hasConfiguredFooter({ interface: { privacyPolicy: { externalUrl: 'https://x/privacy' } } }),
|
||||
).toBe(true);
|
||||
expect(
|
||||
hasConfiguredFooter({ interface: { termsOfService: { externalUrl: 'https://x/terms' } } }),
|
||||
).toBe(true);
|
||||
expect(hasConfiguredFooter({ customFooter: '[Docs](https://example.com)' })).toBe(true);
|
||||
});
|
||||
|
||||
it('is false for a deployment that configured none of it', () => {
|
||||
expect(hasConfiguredFooter()).toBe(false);
|
||||
expect(hasConfiguredFooter(null)).toBe(false);
|
||||
expect(hasConfiguredFooter({})).toBe(false);
|
||||
/** The links carry the policy sections, so a section without one is not a
|
||||
* footer: this is what the bar renders from. */
|
||||
expect(hasConfiguredFooter({ interface: { privacyPolicy: {}, termsOfService: {} } })).toBe(
|
||||
false,
|
||||
);
|
||||
/** An operator who set the footer to nothing suppressed the welcome
|
||||
* screen's disclaimer; a conversation renders nothing for it, so it must
|
||||
* not reserve the band a bar would need. */
|
||||
expect(hasConfiguredFooter({ customFooter: '' })).toBe(false);
|
||||
/** The bar trims each part, so whitespace is the same nothing. */
|
||||
expect(hasConfiguredFooter({ customFooter: ' ' })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,31 +1,31 @@
|
|||
import type { TStartupConfig } from './config';
|
||||
|
||||
/**
|
||||
* The startup-config fields that put a footer bar beneath a conversation's
|
||||
* The startup-config field that puts a footer bar beneath a conversation's
|
||||
* composer. Narrow on purpose: the server answers the same question while it
|
||||
* serves the HTML shell, reading these fields off its own configuration instead
|
||||
* serves the HTML shell, reading this field off its own configuration instead
|
||||
* of assembling a startup payload it has no request for.
|
||||
*/
|
||||
export type TConfiguredFooterSource = Pick<Partial<TStartupConfig>, 'customFooter'> & {
|
||||
interface?: Pick<
|
||||
NonNullable<TStartupConfig['interface']>,
|
||||
'privacyPolicy' | 'termsOfService'
|
||||
> | null;
|
||||
};
|
||||
export type TConfiguredFooterSource = Pick<Partial<TStartupConfig>, 'customFooter'>;
|
||||
|
||||
/**
|
||||
* Whether a deployment configured footer content of its own — a custom footer,
|
||||
* a privacy policy or terms of service.
|
||||
* Whether a deployment configured footer content of its own.
|
||||
*
|
||||
* Only a custom footer with content counts. A privacy policy and terms of
|
||||
* service are read where they are agreed to, on the auth screens, and on the
|
||||
* welcome screen the conversation starts from; a started conversation carries
|
||||
* neither, so neither one puts a bar beneath its composer. A footer of
|
||||
* nothing, or of whitespace the bar trims away, is an operator suppressing the
|
||||
* default disclaimer on the welcome screen; it renders nothing in a
|
||||
* conversation, so it is no bar either.
|
||||
*
|
||||
* The footer bar is absolutely positioned in a zero-height wrapper, so the
|
||||
* composer above it is what reserves its band: this answer decides both the
|
||||
* bar and the clearance. The client and the server share it because the two
|
||||
* answering differently is exactly the layout correction it exists to remove.
|
||||
* bar and the clearance, and it has to match what the bar renders or the
|
||||
* composer reserves a band for nothing. The client and the server share it
|
||||
* because the two answering differently is exactly the layout correction it
|
||||
* exists to remove.
|
||||
*/
|
||||
export function hasConfiguredFooter(source?: TConfiguredFooterSource | null): boolean {
|
||||
return (
|
||||
typeof source?.customFooter === 'string' ||
|
||||
source?.interface?.privacyPolicy?.externalUrl != null ||
|
||||
source?.interface?.termsOfService?.externalUrl != null
|
||||
);
|
||||
return typeof source?.customFooter === 'string' && source.customFooter.trim() !== '';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue