diff --git a/ui/src/features/connections/GoogleWorkspaceServices.test.tsx b/ui/src/features/connections/GoogleWorkspaceServices.test.tsx index 79023e59337..3ff82f854ae 100644 --- a/ui/src/features/connections/GoogleWorkspaceServices.test.tsx +++ b/ui/src/features/connections/GoogleWorkspaceServices.test.tsx @@ -5,6 +5,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { googleWorkspaceSelectedScopes, type ToolConnection } from "@paperclipai/shared"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { GoogleWorkspaceServicesDialog } from "./GoogleWorkspaceServices"; +import { GOOGLE_WORKSPACE_PRIVACY_POLICY_URL, googleWorkspaceDataUseDisclosure } from "./googleWorkspaceDisclosure"; const listGrants = vi.hoisted(() => vi.fn()); vi.mock("@/api/tools", () => ({ toolsApi: { listConnectionGrants: listGrants } })); @@ -151,3 +152,94 @@ describe("Workspace service consent", () => { }); }); + +const GMAIL_SEND_NOTE = "Google's permission screen also mentions sending email; Paperclip does not send email."; + +describe("Google Workspace data-use disclosure", () => { + const use = [ + "Agents read this content only to do the tasks you give them.", + "To do that, the content is sent to the AI model provider configured for your workspace.", + "It is not used to train general AI models.", + "Results are saved in the task and its run history. They stay there until you delete them, even after you disconnect.", + ]; + + it.each([ + [{ gmail: "read" }, ["Gmail: agents can read and search your email."]], + [{ gmail: "write" }, ["Gmail: agents can read and search your email, and create drafts. Google's permission screen also mentions sending email; Paperclip does not send email."]], + [{ drive: "read" }, ["Drive: agents can read and search your files, Docs, Sheets and Slides."]], + [{ drive: "write" }, ["Drive: agents can read and search your files, Docs, Sheets and Slides. They can also create files and edit Docs, Sheets and Slides."]], + [{ calendar: "read" }, ["Calendar: agents can see your calendars, events and free/busy times."]], + [{ calendar: "write" }, ["Calendar: agents can see your calendars, events and free/busy times. They can also create, change and delete events, and respond to invitations."]], + ] as const)("describes only the selected service (%o)", (selection, access) => { + expect(googleWorkspaceDataUseDisclosure(selection)).toEqual({ access, use }); + }); + + it("lists every selected service in picker order and always explains sharing", () => { + const disclosure = googleWorkspaceDataUseDisclosure({ calendar: "read", gmail: "write", drive: "read" }); + expect(disclosure.access.map(line => line.split(":")[0])).toEqual(["Gmail", "Drive", "Calendar"]); + expect(disclosure.use).toContain("To do that, the content is sent to the AI model provider configured for your workspace."); + }); + + it("never claims Gmail can send: read only never mentions sending, read & write only says Paperclip does not send", () => { + const text = (gmail: "read" | "write") => { + const { access, use } = googleWorkspaceDataUseDisclosure({ gmail }); + return [...access, ...use].join(" "); + }; + expect(text("read")).not.toMatch(/send/i); + expect(text("write")).toContain("Paperclip does not send email."); + expect(text("write").replace(GMAIL_SEND_NOTE, "")).not.toMatch(/send/i); + }); + + it("says nothing with no services selected", () => { + expect(googleWorkspaceDataUseDisclosure({})).toEqual({ access: [], use: [] }); + }); +}); + +describe("Workspace picker disclosure", () => { + let root: Root; + let container: HTMLDivElement; + const flush = async () => { await act(async () => { await new Promise(resolve => setTimeout(resolve, 0)); }); }; + beforeEach(() => { + container = document.createElement("div"); + document.body.append(container); + root = createRoot(container); + }); + afterEach(async () => { + await act(async () => { root.unmount(); }); + container.remove(); + }); + async function render(initial?: Record) { + await act(async () => { root.render( + + ); }); + await flush(); + } + const disclosure = () => document.querySelector('[aria-label="How Paperclip uses your Google data"]'); + + it("shows the selected services, sharing and privacy policy before Continue", async () => { + await render({ gmail: "write", calendar: "read" }); + const block = disclosure()!; + expect(block.textContent).toContain("Gmail: agents can read and search your email, and create drafts. Google's permission screen also mentions sending email; Paperclip does not send email."); + expect(block.textContent).toContain("Calendar: agents can see your calendars, events and free/busy times."); + expect(block.textContent).not.toContain("Drive"); + expect(block.textContent!.replace(GMAIL_SEND_NOTE, "")).not.toMatch(/\bsend/i); + expect(block.textContent).toContain("the content is sent to the AI model provider configured for your workspace"); + const link = block.querySelector("a")!; + expect(link.getAttribute("href")).toBe(GOOGLE_WORKSPACE_PRIVACY_POLICY_URL); + expect(GOOGLE_WORKSPACE_PRIVACY_POLICY_URL).toBe("https://paperclip.ing/privacy"); + expect(link.getAttribute("target")).toBe("_blank"); + expect(link.getAttribute("rel")).toContain("noopener"); + expect(link.textContent).toContain("Limited Use"); + const footer = document.querySelector("footer")!; + expect(block.compareDocumentPosition(footer) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); + }); + + it("follows the selection as services are turned off", async () => { + await render({ drive: "read" }); + expect(disclosure()!.textContent).toContain("Drive: agents can read and search your files"); + const toggle = document.querySelector("#workspace-service-drive")!; + await act(async () => { toggle.click(); }); + expect(disclosure()).toBeNull(); + expect(document.body.textContent).toContain("Select at least one service to continue."); + }); +}); diff --git a/ui/src/features/connections/GoogleWorkspaceServices.tsx b/ui/src/features/connections/GoogleWorkspaceServices.tsx index df249597eee..ef17b7a1533 100644 --- a/ui/src/features/connections/GoogleWorkspaceServices.tsx +++ b/ui/src/features/connections/GoogleWorkspaceServices.tsx @@ -1,5 +1,5 @@ import { useQueryView } from "@/components/QueryView"; -import { useState } from "react"; +import { useState, type ReactNode } from "react"; import { useQuery } from "@tanstack/react-query"; import { GOOGLE_WORKSPACE_DEFAULT_SELECTION, GOOGLE_WORKSPACE_SERVICE_GROUPS, googleWorkspaceDraftRequestedScopes, googleWorkspaceSelectionForScopes, type GoogleWorkspaceServiceSelection, type ToolConnection } from "@paperclipai/shared"; import { toolsApi } from "@/api/tools"; @@ -8,6 +8,7 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } f import { NativeSelect } from "@/components/ui/select"; import { ToggleSwitch } from "@/components/ui/toggle-switch"; import { AppLogo } from "@/pages/apps/AppLogo"; +import { GOOGLE_WORKSPACE_PRIVACY_POLICY_URL, googleWorkspaceDataUseDisclosure } from "./googleWorkspaceDisclosure"; export function GoogleWorkspaceServiceFields({ value, onChange }: { value: GoogleWorkspaceServiceSelection; @@ -36,6 +37,26 @@ export function GoogleWorkspaceServiceFields({ value, onChange }: { ; } +export function isGoogleWorkspaceConnection(connection: Pick): boolean { + return connection.config?.sourceTemplateKey === "google-workspace"; +} + +export function useGoogleWorkspaceServiceGate(): { + dialog: ReactNode; + run: (connection: ToolConnection, start: (selection?: GoogleWorkspaceServiceSelection) => void) => void; +} { + const [pending, setPending] = useState<{ connection: ToolConnection; start: (selection: GoogleWorkspaceServiceSelection) => void } | null>(null); + return { + dialog: pending ? setPending(null)} + onContinue={selection => { setPending(null); pending.start(selection); }} /> : null, + run: (connection, start) => { + if (isGoogleWorkspaceConnection(connection)) setPending({ connection, start }); + else start(); + }, + }; +} + type DialogProps = { onContinue: (value: GoogleWorkspaceServiceSelection) => void; onCancel: (selection?: GoogleWorkspaceServiceSelection) => void; @@ -77,17 +98,38 @@ export function GoogleWorkspaceServicesDialog(props: DialogProps) { return ; } +function DataUseDisclosure({ selection }: { selection: GoogleWorkspaceServiceSelection }) { + const { access, use } = googleWorkspaceDataUseDisclosure(selection); + return
+
+

What agents can do

+
    {access.map(line =>
  • {line}
  • )}
+
+
+

How your data is used

+
    {use.map(line =>
  • {line}
  • )}
+
+

+ + Read our privacy policy, including how we meet Google's Limited Use requirements (opens in a new tab) + +

+
; +} + function ServicePicker({ onContinue, onCancel, initial = GOOGLE_WORKSPACE_DEFAULT_SELECTION }: DialogProps) { const [selection, setSelection] = useState(initial); const empty = Object.keys(selection).length === 0; return { if (!open) onCancel(selection); }}> - +
Connect Google Workspace
Choose the Google services to connect.
- {empty &&

Select at least one service to continue.

} + {empty + ?

Select at least one service to continue.

+ : }