Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(calendar): prompt to enable calendar only for your own inboxes (#8639)

gbirman70c8952ee210
diff --git a/apps/web/src/features/auth/CalendarPermissionPrompt.test.tsx b/apps/web/src/features/auth/CalendarPermissionPrompt.test.tsx
new file mode 100644
index 0000000000..c5f7d9ac00
--- /dev/null
+++ b/apps/web/src/features/auth/CalendarPermissionPrompt.test.tsx
@@ -0,0 +1,133 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import { FakeToaster } from '@core/component/Toast/tests/fake-toast';
+import type { Link as EmailLink } from '@service-email/generated/schemas';
+import { cleanup, render, screen } from '@solidjs/testing-library';
+import userEvent from '@testing-library/user-event';
+import { createSignal } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({ startAddInbox: vi.fn() }));
+
+const [userId, setUserId] = createSignal<string | undefined>('macro|self');
+const [links, setLinks] = createSignal<EmailLink[]>([]);
+
+vi.mock(
+ '@core/component/Toast/Toast',
+ () => import('@core/component/Toast/tests/fake-toast')
+);
+
+vi.mock('@core/mobile/isMobile', () => ({ isMobile: () => false }));
+
+vi.mock('@app/features/calendar/hooks/use-calendar-ui-flag', () => ({
+ useCalendarUiFlag: () => () => true,
+ useCalendarPromptAllowed: () => () => true,
+}));
+
+vi.mock('@core/context/user', () => ({ useUserId: () => userId }));
+
+vi.mock('@core/email-link', () => ({
+ useAddInboxFlow: () => mocks.startAddInbox,
+}));
+
+vi.mock('@queries/email/link', () => ({
+ useEmailLinksQuery: () => ({
+ isSuccess: true,
+ get data() {
+ return { links: links() };
+ },
+ }),
+}));
+
+import { CalendarPermissionPrompt } from './CalendarPermissionPrompt';
+
+const PERSIST_KEY = 'macro:calendar-prompt:dismissed';
+
+const link = (id: string, overrides: Partial<EmailLink> = {}): EmailLink =>
+ ({
+ id,
+ provider: 'GMAIL',
+ macro_id: 'macro|self',
+ email_address: `${id}@example.com`,
+ needs_calendar_permission: true,
+ needs_reauth: false,
+ calendar_disabled: false,
+ has_calendar_data: false,
+ is_primary: false,
+ ...overrides,
+ }) as unknown as EmailLink;
+
+function renderPrompt() {
+ render(() => (
+ <>
+ <FakeToaster />
+ <CalendarPermissionPrompt />
+ </>
+ ));
+}
+
+beforeEach(() => {
+ mocks.startAddInbox.mockResolvedValue(undefined);
+ localStorage.clear();
+ setUserId('macro|self');
+ setLinks([]);
+});
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+describe('CalendarPermissionPrompt', () => {
+ it('asks only for the viewer’s own inbox, never for one another user delegated', async () => {
+ const user = userEvent.setup();
+ setLinks([
+ link('own'),
+ link('delegated', { macro_id: 'macro|someone-else' }),
+ ]);
+ renderPrompt();
+
+ expect(screen.getAllByRole('status')).toHaveLength(1);
+ expect(
+ screen.getByText(
+ 'Macro can now sync your calendar. Grant calendar access for [email protected] to turn it on.'
+ )
+ ).toBeTruthy();
+ expect(screen.queryByText(/delegated@example\.com/)).toBeNull();
+
+ await user.click(screen.getByRole('button', { name: 'Grant access' }));
+ expect(mocks.startAddInbox).toHaveBeenCalledWith({
+ scopes: 'calendar',
+ provider: 'GMAIL',
+ reconnectLinkId: 'own',
+ emailAddress: '[email protected]',
+ });
+ expect(screen.queryByRole('status')).toBeNull();
+ });
+
+ it('stays quiet when the only inbox missing calendar is delegated', () => {
+ setLinks([
+ link('own', { needs_calendar_permission: false }),
+ link('delegated', { macro_id: 'macro|someone-else' }),
+ ]);
+ renderPrompt();
+
+ expect(screen.queryByRole('status')).toBeNull();
+ });
+
+ it('keeps a closed prompt closed while the viewer is still loading', () => {
+ localStorage.setItem(PERSIST_KEY, JSON.stringify(['own']));
+ setUserId(undefined);
+ setLinks([link('own')]);
+ renderPrompt();
+
+ setUserId('macro|self');
+
+ expect(screen.queryByRole('status')).toBeNull();
+ expect(JSON.parse(localStorage.getItem(PERSIST_KEY) ?? '[]')).toEqual([
+ 'own',
+ ]);
+ });
+});
diff --git a/apps/web/src/features/auth/CalendarPermissionPrompt.tsx b/apps/web/src/features/auth/CalendarPermissionPrompt.tsx
index 2d5c90e26c..83038de09e 100644
--- a/apps/web/src/features/auth/CalendarPermissionPrompt.tsx
+++ b/apps/web/src/features/auth/CalendarPermissionPrompt.tsx
@@ -3,6 +3,7 @@ import {
useCalendarUiFlag,
} from '@app/features/calendar/hooks/use-calendar-ui-flag';
import { useKeyedPersistentToasts } from '@core/component/Toast/useKeyedPersistentToasts';
+import { useUserId } from '@core/context/user';
import { useAddInboxFlow } from '@core/email-link';
import { fireAndForget } from '@core/util/fireAndForget';
import { useEmailLinksQuery } from '@queries/email/link';
@@ -14,6 +15,10 @@ import { useEmailLinksQuery } from '@queries/email/link';
* re-shows Google consent for the linked account and applies the upgraded
* grant to the existing link, which kicks off the calendar backfill.
*
+ * Only the viewer's own inboxes are prompted. The links list also carries
+ * inboxes another Macro user delegated to the viewer; whether that user's
+ * calendar syncs is theirs to decide, as in the calendar settings.
+ *
* Inboxes that also need a full reconnect are skipped so the two prompts don't
* stack. Reconnecting restores previously enabled calendar access too; an
* inbox that never enabled calendar can still opt in through this prompt.
@@ -29,6 +34,7 @@ export function CalendarPermissionPrompt() {
const calendarUiEnabled = useCalendarUiFlag();
const promptAllowed = useCalendarPromptAllowed();
const linksQuery = useEmailLinksQuery();
+ const userId = useUserId();
const startAddInbox = useAddInboxFlow();
useKeyedPersistentToasts({
@@ -36,6 +42,7 @@ export function CalendarPermissionPrompt() {
calendarUiEnabled() && promptAllowed()
? (linksQuery.isSuccess ? linksQuery.data.links : []).filter(
(link) =>
+ link.macro_id === userId() &&
link.needs_calendar_permission &&
!link.needs_reauth &&
!link.calendar_disabled
@@ -43,10 +50,11 @@ export function CalendarPermissionPrompt() {
: [],
key: (link) => link.id,
persistKey: 'macro:calendar-prompt:dismissed',
- // Until the flag resolves and the links land, the empty list above means
- // "don't know yet", not "no inbox needs this" — stored dismissals must
- // survive that window.
- itemsLoaded: () => calendarUiEnabled() && linksQuery.isSuccess,
+ // Until the flag, the links and the viewer's id resolve, the empty list
+ // above means "don't know yet", not "no inbox needs this" — stored
+ // dismissals must survive that window.
+ itemsLoaded: () =>
+ calendarUiEnabled() && linksQuery.isSuccess && userId() !== undefined,
toast: (link, dismiss) => ({
title: 'Enable calendar',
content(): string {
diff --git a/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx b/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx
index 550619aeed..e955865ba0 100644
--- a/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx
+++ b/apps/web/src/features/channel/Call/tests/full-screen-call-prompt.test.tsx
@@ -2,17 +2,20 @@
* @vitest-environment jsdom
*/
+import { FakeToaster } from '@core/component/Toast/tests/fake-toast';
import { fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { FullScreenCallPrompt } from '../FullScreenCallPrompt';
-import { FakeToaster } from './fake-toast';
const native = vi.hoisted(() => ({
allowed: false as boolean | 'unavailable',
invoke: vi.fn(),
}));
-vi.mock('@core/component/Toast/Toast', () => import('./fake-toast'));
+vi.mock(
+ '@core/component/Toast/Toast',
+ () => import('@core/component/Toast/tests/fake-toast')
+);
vi.mock('@core/util/platform', () => ({
isPlatform: (platform: string) => platform === 'android',
}));
diff --git a/apps/web/src/features/channel/Call/tests/fake-toast.tsx b/apps/web/src/lib/core/component/Toast/tests/fake-toast.tsx
similarity index 95%
rename from apps/web/src/features/channel/Call/tests/fake-toast.tsx
rename to apps/web/src/lib/core/component/Toast/tests/fake-toast.tsx
index 8e290b1787..dd04799505 100644
--- a/apps/web/src/features/channel/Call/tests/fake-toast.tsx
+++ b/apps/web/src/lib/core/component/Toast/tests/fake-toast.tsx
@@ -24,6 +24,7 @@ export function FakeToaster() {
{(toast) => (
<div role="status">
<p>{toast.config.title}</p>
+ <p>{toast.config.content?.()}</p>
<For each={toast.config.actions}>
{(action) => (
<button onClick={action.onClick}>{action.label}</button>
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index ea6f1b2a84..dee2f72f0f 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -227,6 +227,11 @@ Connect calendar for accounts missing calendar permission, and Disconnect with
confirmation. When the only linked account lacks calendar permission, the Google
Calendar row shows just a filled Connect button for it, with no account list or
visibility note. Disconnect removes calendar access/data, not the Gmail connection.
+Settings → Calendar lists only the viewer's own inboxes. The **Enable calendar**
+toast (behind `enable-calendar-prompt-web` and `enable-calendar-prompt-mobile`)
+follows the same rule: it asks once per own inbox missing calendar permission,
+never for an inbox another Macro user delegated to the viewer (a **Shared** row
+in Settings → Email, whose per-inbox Enable calendar button stays available).
Account checkboxes show/hide all child calendars; partial selection is shown as
mixed. Individual calendars can also be shown/hidden. The account color is the
default for its calendars; a child color overrides it. Click a color dot to open