Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: offer copy for unsupported Outlook and Teams drafts (#9944)
[._.]/ Adam Eivyec8bdb873200
diff --git a/client/src/components/messages/DraftsTab.jsx b/client/src/components/messages/DraftsTab.jsxindex a9964f841a..345fe65e83 100644--- a/client/src/components/messages/DraftsTab.jsx+++ b/client/src/components/messages/DraftsTab.jsx@@ -122,6 +122,10 @@ export default function DraftsTab({ accounts }) {return account.name;};+ const isCopyOnly = draft => draft.sendVia === 'review' ||+ accounts.find(account => account.id === draft.accountId)?.canSend === false ||+ draft.sendVia === 'playwright';+const statusColors = {draft: 'bg-gray-700 text-gray-300',pending_review: 'bg-port-warning/20 text-port-warning',@@ -170,7 +174,7 @@ export default function DraftsTab({ accounts }) {)}</div><div className="flex items-center gap-2">- {draft.status === 'draft' && draft.sendVia !== 'review' && (+ {draft.status === 'draft' && !isCopyOnly(draft) && (<buttononClick={() => handleApprove(draft.id)}className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1 text-gray-400 hover:text-port-success transition-colors"@@ -183,7 +187,7 @@ export default function DraftsTab({ accounts }) {which have no programmatic send channel) never offer Send —messageSender can't deliver them, so the button would onlyfail. Send them yourself from the Messages/Signal app. */}- {draft.status === 'approved' && draft.sendVia !== 'review' && (+ {draft.status === 'approved' && !isCopyOnly(draft) && (<buttononClick={() => handleSend(draft.id)}className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1 text-gray-400 hover:text-port-accent transition-colors"@@ -195,10 +199,10 @@ export default function DraftsTab({ accounts }) {{sendingIds.has(draft.id) ? <RefreshCw size={16} className="animate-spin" /> : <Send size={16} />}</button>)}- {draft.sendVia === 'review' && (+ {isCopyOnly(draft) && (<><span className="text-xs text-gray-500" title="No programmatic send — copy and send from your messaging app">- Review only+ {draft.sendVia === 'review' ? 'Review only' : "Sending from this account isn't supported yet — copy the draft"}</span><buttononClick={() => handleCopy(draft)}@@ -213,7 +217,7 @@ export default function DraftsTab({ accounts }) {{/* Review-only drafts never reach a 'sent' state (there's no sendchannel), so keep Delete available at any status — otherwise anapproved iMessage/Signal draft would be stuck with no action. */}- {(['draft', 'pending_review', 'failed'].includes(draft.status) || draft.sendVia === 'review') && (+ {(['draft', 'pending_review', 'failed'].includes(draft.status) || isCopyOnly(draft)) && (<buttononClick={() => requestDelete(draft.id)}className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center p-1 text-gray-400 hover:text-port-error transition-colors"@@ -230,7 +234,7 @@ export default function DraftsTab({ accounts }) {)}{/* Review-only drafts are sent by hand, so show the full body (notclamped) — it's the text the user copies into their messaging app. */}- <div className={`text-sm text-gray-400 whitespace-pre-wrap ${draft.sendVia === 'review' ? '' : 'line-clamp-3'}`}>+ <div className={`text-sm text-gray-400 whitespace-pre-wrap ${isCopyOnly(draft) ? '' : 'line-clamp-3'}`}>{draft.body}</div>{draft.status === 'delivery_unknown' && (diff --git a/client/src/components/messages/DraftsTab.test.jsx b/client/src/components/messages/DraftsTab.test.jsxindex 99c24fd50b..9cb73f06b3 100644--- a/client/src/components/messages/DraftsTab.test.jsx+++ b/client/src/components/messages/DraftsTab.test.jsx@@ -131,3 +131,25 @@ describe('DraftsTab interrupted delivery', () => {expect(api.sendMessageDraft).not.toHaveBeenCalled();});});++describe('DraftsTab send capabilities', () => {+ it('offers copy instead of approval/send for Outlook and Teams while Gmail still sends', async () => {+ api.getMessageDrafts.mockResolvedValue([+ { id: 'outlook-draft', status: 'draft', accountId: 'outlook', sendVia: 'playwright', body: 'Outlook text' },+ { id: 'teams-draft', status: 'approved', accountId: 'teams', sendVia: 'playwright', body: 'Teams text' },+ { id: 'gmail-draft', status: 'approved', accountId: 'gmail', sendVia: 'api', body: 'Gmail text' }+ ]);+ render(<DraftsTab accounts={[+ { id: 'outlook', name: 'Outlook', canSend: false },+ { id: 'teams', name: 'Teams', canSend: false },+ { id: 'gmail', name: 'Gmail', canSend: true }+ ]} />);+ expect(await screen.findAllByText(/Sending from this account isn't supported yet/)).toHaveLength(2);+ expect(screen.getAllByRole('button', { name: 'Copy message' })).toHaveLength(2);+ expect(screen.queryByRole('button', { name: 'Approve' })).not.toBeInTheDocument();+ expect(screen.getAllByRole('button', { name: 'Send' })).toHaveLength(1);+ api.sendMessageDraft.mockResolvedValueOnce({ success: true });+ fireEvent.click(screen.getByRole('button', { name: 'Send' }));+ await waitFor(() => expect(api.sendMessageDraft).toHaveBeenCalledWith('gmail-draft'));+ });+});diff --git a/client/src/components/privacy/PrivacyBrokersTab.jsx b/client/src/components/privacy/PrivacyBrokersTab.jsxindex 84c32d8bc6..0fcf66d5a3 100644--- a/client/src/components/privacy/PrivacyBrokersTab.jsx+++ b/client/src/components/privacy/PrivacyBrokersTab.jsx@@ -144,6 +144,10 @@ export default function PrivacyBrokersTab({ subjectId, consentScopes, onManageCoconst [optOutNow, optOutRunning] = useAsyncAction(async () => {const r = await runPass(runPrivacyOptOut, 'broker_optout');load();+ if (r?.nextActions?.length) {+ toast.error(r.nextActions.join('. '));+ return r;+ }toast.success(r?.reason === 'no_disclosure_identity'? 'Add a scan-eligible name to the vault to run an opt-out pass': `Opt-out pass: ${r?.submitted?.length || 0} actioned, ${r?.skipped || 0} skipped`);diff --git a/client/src/components/privacy/PrivacyBrokersTab.test.jsx b/client/src/components/privacy/PrivacyBrokersTab.test.jsxindex fc9fe7e125..724ee17683 100644--- a/client/src/components/privacy/PrivacyBrokersTab.test.jsx+++ b/client/src/components/privacy/PrivacyBrokersTab.test.jsx@@ -58,6 +58,15 @@ import * as apiMod from '../../services/api';const renderTab = (props = {}) => render(<MemoryRouter initialEntries={['/privacy/brokers']}><PrivacyBrokersTab {...props} /></MemoryRouter>);describe('PrivacyBrokersTab', () => {+ it('shows the missing send account next action after an opt-out pass', async () => {+ const toast = (await import('../ui/Toast')).default;+ apiMod.runPrivacyOptOut.mockResolvedValueOnce({ submitted: [], skipped: 1, nextActions: ['Connect a Gmail account to send opt-out emails'] });+ renderTab();+ await screen.findByText('Spokeo');+ fireEvent.click(screen.getByRole('button', { name: /Run opt-out pass/i }));+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Connect a Gmail account to send opt-out emails'));+ });+beforeEach(() => {vi.clearAllMocks();api.runScanDeferred = null;diff --git a/server/routes/privacy.test.js b/server/routes/privacy.test.jsindex aa1c06709a..77620e912b 100644--- a/server/routes/privacy.test.js+++ b/server/routes/privacy.test.js@@ -17,6 +17,7 @@ vi.mock('../services/privacyVault.js', () => ({updateVaultRecord: vi.fn(async (id, patch) => ({ id, ...patch })),deleteVaultRecord: vi.fn(async () => ({ ok: true })),revealValue: vi.fn(async (id) => ({ id, type: 'email', value: '[email protected]' })),+ listScanEligibleValues: vi.fn(async () => [{ type: 'legal_name', value: 'Example Person' }, { type: 'email', value: '[email protected]' }]),getVaultStatus: vi.fn(async () => ({ keyConfigured: true, recordCounts: { email: 1 } })),}));@@ -55,7 +56,8 @@ vi.mock('../services/settings.js', () => ({updateSettingsWith: vi.fn(async (mutate) => mutate({ privacy: { recheck: {} } })),}));-vi.mock('../services/privacyScan.js', () => ({+vi.mock('../services/privacyScan.js', async (importOriginal) => ({+ buildSearchVectors: (await importOriginal()).buildSearchVectors,runScanPass: vi.fn(async (opts) => ({ scanned: 2, verdicts: { found: 1, not_found: 1 }, skipped: 0, brokers: 20, _opts: opts })),}));@@ -77,6 +79,8 @@ vi.mock('../services/privacyChanges.js', () => ({// Household subjects (#3658) — mocked so the route layer is exercised without a DB.const SELF = '00000000-0000-4000-8000-000000000001';vi.mock('../services/privacySubjects.js', () => ({+ resolveSubjectId: id => id || SELF,+ assertSubjectConsent: vi.fn(async () => ({ id: SELF })),listSubjects: vi.fn(async () => [{ id: SELF, displayName: 'Me', relationship: 'self', isSelf: true, consentCount: 1, recordCount: 2 }]),getSubject: vi.fn(async (id) => (id === SELF ? { id, displayName: 'Me', relationship: 'self', isSelf: true } : null)),createSubject: vi.fn(async (input) => ({ id: 'c0ffee00-0000-4000-8000-0000000000a1', ...input, isSelf: false })),@@ -483,7 +487,31 @@ describe('POST /api/privacy/scan', () => {// ─── Opt-out automation engine (issue #2145) ────────────────────────────────+vi.mock('../services/messageAccounts.js', () => ({ listAccounts: vi.fn() }));+vi.mock('../services/messageDrafts.js', () => ({ createDraft: vi.fn(), approveDraft: vi.fn() }));+describe('POST /api/privacy/optout', () => {+ it('keeps the real opt-out workflow at found with only a Playwright account, even with auto-approve', async () => {+ const accounts = await import('../services/messageAccounts.js');+ const drafts = await import('../services/messageDrafts.js');+ const brokers = await import('../services/privacyBrokers.js');+ const settings = await import('../services/settings.js');+ const actual = await vi.importActual('../services/privacyOptOut.js');+ drafts.createDraft.mockResolvedValueOnce({ id: 'draft-example', status: 'draft' });+ drafts.approveDraft.mockResolvedValueOnce({ id: 'draft-example', status: 'approved' });+ accounts.listAccounts.mockResolvedValueOnce([{ id: 'outlook', type: 'outlook', canSend: false }]);+ brokers.listBrokers.mockResolvedValueOnce([{ id: 'email-broker', name: 'Example broker', optout: { method: 'email', email: '[email protected]' }, disclosureFields: ['full_name', 'email'] }]);+ brokers.listBrokerCases.mockResolvedValueOnce([{ id: 'case-1', brokerId: 'email-broker', state: 'found' }]);+ settings.getSettings.mockResolvedValueOnce({ privacy: { recheck: { autoApproveOptOutEmails: true } } });+ optOutService.runOptOutPass.mockImplementationOnce(actual.runOptOutPass);+ const res = await request(makeApp()).post('/api/privacy/optout').send({ runVerification: false });+ expect(res.status).toBe(200);+ expect(res.body).toMatchObject({ submitted: [], skipped: 1, nextActions: ['Connect a Gmail account to send opt-out emails'] });+ expect(brokers.transitionCase).not.toHaveBeenCalled();+ expect(drafts.createDraft).not.toHaveBeenCalled();+ expect(drafts.approveDraft).not.toHaveBeenCalled();+ });+it('runs an opt-out pass and returns the summary', async () => {const res = await request(makeApp()).post('/api/privacy/optout').send({});expect(res.status).toBe(200);diff --git a/server/services/messageAccounts.js b/server/services/messageAccounts.jsindex ea31a8efeb..0364e03242 100644--- a/server/services/messageAccounts.js+++ b/server/services/messageAccounts.js@@ -24,12 +24,12 @@ async function saveAccounts(accounts) {export async function listAccounts() {const accounts = await loadAccounts();- return Object.values(accounts).sort((a, b) => a.name.localeCompare(b.name));+ return Object.values(accounts).map(account => ({ ...account, canSend: account.type === 'gmail' })).sort((a, b) => a.name.localeCompare(b.name));}export async function getAccount(id) {const accounts = await loadAccounts();- return accounts[id] || null;+ return accounts[id] ? { ...accounts[id], canSend: accounts[id].type === 'gmail' } : null;}export async function createAccount(data) {diff --git a/server/services/messageAccounts.test.js b/server/services/messageAccounts.test.jsindex 2ea35bf17e..554d9dedd0 100644--- a/server/services/messageAccounts.test.js+++ b/server/services/messageAccounts.test.js@@ -39,6 +39,17 @@ function holdNextWrite({ fail = false } = {}) {afterAll(() => rmSync(TEST_DATA_ROOT, { recursive: true, force: true }));describe('messageAccounts', () => {+ it('derives send capabilities on read without trusting persisted capability flags', async () => {+ await messageAccounts.createAccount({ name: 'Gmail', type: 'gmail' });+ uuid.mockReturnValueOnce('outlook-id');+ await messageAccounts.createAccount({ name: 'Outlook', type: 'outlook' });+ uuid.mockReturnValueOnce('teams-id');+ await messageAccounts.createAccount({ name: 'Teams', type: 'teams' });+ expect((await messageAccounts.listAccounts()).map(({ type, canSend }) => ({ type, canSend }))).toEqual([+ { type: 'gmail', canSend: true }, { type: 'outlook', canSend: false }, { type: 'teams', canSend: false }+ ]);+ });+beforeEach(() => {atomicWrite.mockReset().mockImplementation(persist);uuid.mockReset().mockReturnValue('msg-uuid-5678');diff --git a/server/services/messageSender.js b/server/services/messageSender.jsindex 955621a741..ab98c1bb44 100644--- a/server/services/messageSender.js+++ b/server/services/messageSender.js@@ -18,6 +18,10 @@ export async function sendDraft(draftId, io) {const account = await getAccount(draft.accountId);if (!account) return { success: false, status: 404, code: 'ACCOUNT_NOT_FOUND', error: 'Account not found' };+ if (account.canSend === false) {+ return { success: false, status: 501, code: 'SEND_NOT_SUPPORTED', error: "Sending from this account isn't supported yet — copy the draft" };+ }+const expectedSendVia = ACCOUNT_TYPE_TO_SEND_VIA[account.type];if (draft.sendVia !== expectedSendVia) {return { success: false, status: 400, code: 'SEND_VIA_MISMATCH', error: `sendVia "${draft.sendVia}" does not match account type "${account.type}" (expected "${expectedSendVia}")` };diff --git a/server/services/messageSender.test.js b/server/services/messageSender.test.jsindex 27833900f3..4eb8430b9b 100644--- a/server/services/messageSender.test.js+++ b/server/services/messageSender.test.js@@ -43,6 +43,14 @@ beforeEach(() => {});describe('draft send workflow', () => {+ it('refuses unsupported sends without consuming approval or dispatching', async () => {+ seed({ id: 'outlook-draft', sendVia: 'playwright' });+ doubles.getAccount.mockResolvedValueOnce({ id: 'account-1', type: 'outlook', canSend: false });+ expect(await sendDraft('outlook-draft')).toMatchObject({ status: 501, code: 'SEND_NOT_SUPPORTED' });+ expect(await getDraft('outlook-draft')).toMatchObject({ status: 'approved' });+ expect(doubles.sendPlaywright).not.toHaveBeenCalled();+ });+it('claims once after overlapping reads and prevents edits from reopening the send', async () => {seed({ id: 'draft-1' });const bothRead = barrier();diff --git a/server/services/privacyChanges.js b/server/services/privacyChanges.jsindex 0f13e73e87..16a033ec92 100644--- a/server/services/privacyChanges.js+++ b/server/services/privacyChanges.js@@ -342,8 +342,8 @@ export async function draftUpdateEmail(eventId, orgId) {if (!to) throw new ServerError('Organization has no contact email', { status: 400, code: 'ORG_EMAIL_MISSING' });const accounts = await listAccounts();- const account = accounts.find((a) => a.type === 'gmail') ?? accounts[0];- if (!account) throw new ServerError('No message account configured', { status: 400, code: 'NO_MESSAGE_ACCOUNT' });+ const account = accounts.find((a) => a.canSend && a.enabled !== false);+ if (!account) throw new ServerError('Connect a Gmail account to send update emails', { status: 400, code: 'NO_MESSAGE_ACCOUNT' });const oldRecord = await getVaultRecord(event.vaultRecordId);const newReveal = await revealValue(event.replacementRecordId);@@ -362,7 +362,7 @@ export async function draftUpdateEmail(eventId, orgId) {subject,body,generatedBy: 'privacy-change',- sendVia: account.type === 'gmail' ? 'api' : 'playwright',+ sendVia: 'api',});console.log(`📧 Drafted privacy update email for org ${orgId} (change ${eventId}, draft ${draft.id})`);return { draftId: draft.id, status: draft.status };diff --git a/server/services/privacyChanges.test.js b/server/services/privacyChanges.test.jsindex 9a3669a38b..b56e832e8e 100644--- a/server/services/privacyChanges.test.js+++ b/server/services/privacyChanges.test.js@@ -29,7 +29,7 @@ vi.mock('./privacyOrgs.js', () => ({getOrg: vi.fn(async (id) => ({ id, name: 'Acme Bank', contact: { email: '[email protected]' } })),}));vi.mock('./messageAccounts.js', () => ({- listAccounts: vi.fn(async () => [{ id: 'acct-1', type: 'gmail', name: 'Primary' }]),+ listAccounts: vi.fn(async () => [{ id: 'acct-1', type: 'gmail', canSend: true, name: 'Primary' }]),}));vi.mock('./messageDrafts.js', () => ({createDraft: vi.fn(async (data) => ({ id: 'draft-1', status: 'draft', ...data })),@@ -271,6 +271,13 @@ describe('listChangeEvents', () => {});describe('draftUpdateEmail', () => {+ it('refuses an unsupported account before revealing the replacement or creating a draft', async () => {+ queryMock.mockResolvedValue({ rows: [eventRow()] });+ messageAccounts.listAccounts.mockResolvedValueOnce([{ id: 'outlook', type: 'outlook', canSend: false }]);+ await expect(draftUpdateEmail('ev1', 'o1')).rejects.toMatchObject({ code: 'NO_MESSAGE_ACCOUNT' });+ expect(privacyVault.revealValue).not.toHaveBeenCalled();+ });+it('creates an UNAPPROVED draft (status draft) to the org contact email', async () => {queryMock.mockImplementation(async (sql) => {if (/FROM privacy_change_events WHERE id/.test(sql)) return { rows: [eventRow()] };diff --git a/server/services/privacyOptOut.js b/server/services/privacyOptOut.jsindex 0514c3dd6a..f541bc2596 100644--- a/server/services/privacyOptOut.js+++ b/server/services/privacyOptOut.js@@ -332,10 +332,10 @@ export async function emailLane(broker, kase, {return { caseId: kase.id, lane: 'email', outcome: 'human_task_queued' };}const accounts = await accountsProvider();- const account = accounts.find((a) => a.type === 'gmail') ?? accounts[0];+ const account = accounts.find((a) => a.canSend && a.enabled !== false);if (!account) {- await transitionCase(kase.id, 'human_task_queued', { channel: 'email', reason: 'no_message_account', now });- return { caseId: kase.id, lane: 'email', outcome: 'human_task_queued' };+ return { caseId: kase.id, lane: 'email', outcome: 'account_required',+ nextAction: 'Connect a Gmail account to send opt-out emails' };}const { subject, body, templateName } = await renderOptOutEmail({ broker, payload, disclosedFields, listingUrls, now });const draft = await draftCreator({@@ -344,7 +344,7 @@ export async function emailLane(broker, kase, {subject,body,generatedBy: 'privacy-optout',- sendVia: account.type === 'gmail' ? 'api' : 'playwright',+ sendVia: 'api',});await transitionCase(kase.id, 'optout_in_progress', { channel: 'email', disclosedFields, evidence: { lane: 'email', to, template: templateName, draftId: draft.id, disclosed: disclosedFields }, now });@@ -521,6 +521,7 @@ export async function runOptOutPass({const { submit } = planOptOutActions(casesWithBroker);const submitted = [];+ const nextActions = new Set();let skipped = 0;for (const { case: kase, broker } of submit) {// Listing URLs live in the case's sealed identity evidence (#8333).@@ -540,7 +541,12 @@ export async function runOptOutPass({const result = lane === 'email'? await emailLane(broker, kase, { disclosedFields, payload, listingUrls, autoApprove, now, ...(deps.email || {}) }): await webFormLane(broker, kase, { disclosedFields, payload, listingUrls, autoSubmit, now, ...(deps.webForm || {}) });- submitted.push({ brokerId: broker.id, ...result });+ if (result.outcome === 'account_required') {+ skipped += 1;+ nextActions.add(result.nextAction);+ } else {+ submitted.push({ brokerId: broker.id, ...result });+ }}const verification = runVerification@@ -548,7 +554,7 @@ export async function runOptOutPass({: null;console.log(`📋 Opt-out pass: ${submitted.length} actioned, ${skipped} skipped (autoApprove=${autoApprove}, autoSubmit=${autoSubmit})`);- return { submitted, skipped, verification, subjectId: resolvedSubjectId, autonomy: { autoApprove, autoSubmit } };+ return { submitted, skipped, nextActions: [...nextActions], verification, subjectId: resolvedSubjectId, autonomy: { autoApprove, autoSubmit } };}// ─── Human-task digest ──────────────────────────────────────────────────────diff --git a/server/services/privacyOptOut.test.js b/server/services/privacyOptOut.test.jsindex 859a9373f1..92746a455f 100644--- a/server/services/privacyOptOut.test.js+++ b/server/services/privacyOptOut.test.js@@ -38,7 +38,7 @@ vi.mock('./privacyScan.js', async (importOriginal) => {const createDraft = vi.fn(async (d) => ({ id: 'draft-1', status: 'draft', ...d }));const approveDraft = vi.fn(async () => ({ id: 'draft-1', status: 'approved' }));vi.mock('./messageDrafts.js', () => ({ createDraft, approveDraft }));-vi.mock('./messageAccounts.js', () => ({ listAccounts: vi.fn(async () => [{ id: 'acct-1', type: 'gmail' }]) }));+vi.mock('./messageAccounts.js', () => ({ listAccounts: vi.fn(async () => [{ id: 'acct-1', type: 'gmail', canSend: true }]) }));vi.mock('./messageSync.js', () => ({ getMessages: vi.fn(async () => ({ messages: [] })) }));vi.mock('./settings.js', () => ({ getSettings: vi.fn(async () => ({ privacy: { recheck: {} } })) }));