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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/34730-slack-settings-ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

Clause-②: no
Metadata-protocol: none

feat(app-shell): connect your Slack account on the notification settings page, and an admin Slack page in Setup

The console side of Slack direct-message delivery (step 3 of the Slack DM work; the server doors shipped with `@objectstack/service-messaging`'s Slack link routes).

- **Notification Settings: your Slack link.** Where the preference door lists the `slack` channel (only on a deployment that composes connector-slack), the page shows a Slack section. Without an install, or with an install whose token Slack refused, it says so and offers nothing. Otherwise **Connect Slack** asks `POST /api/v1/messaging/me/slack-link/proposal`; the page shows what the door answers: that a Slack user with your verified email was found (never whom), with **Confirm** (`…/confirm`) and **Cancel** (`DELETE /api/v1/messaging/me/slack-link`); or, when nothing was proposed, a sentence naming every reason the door does not tell apart (no verified email, no Slack user with it, or that Slack user linked to someone else). A confirmed link shows the Slack user and **Disconnect**. A refusal is shown in the server's own words (its `userMessage` when it carries one), and the section then reads the door again.
- **Setup's Slack page** (component `messaging:slack`, `/apps/setup/component/messaging/slack`): for an organization administrator holding `setup.write`, the capability the doors ask; anyone else sees what is needed and no door is read. It installs or sets again the organization's bot token (`PUT /api/v1/messaging/slack/account`) through a password input that always starts empty, removes the install after a confirm that says every linked person is told, and lists every link as served (person, Slack user once confirmed, when) with a confirmed **Remove** per link. When the list reaches the 10,000 links the server answers, the page says it may be incomplete.
- Every new sentence is in all eleven built-in locales (`slackLink`, `slackSetup`).
26 changes: 26 additions & 0 deletions content/docs/permissions/administrator-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,32 @@ rules. A flow that should message the whole organization uses the `notify`
step's `org:members` recipient instead
([Flows](/docs/automation/flows)).

## Deliver notifications by Slack direct message

On a deployment that composes the Slack connector (`ConnectorSlackPlugin`),
notifications can also reach people as Slack direct messages, from your
organization's own Slack app. Without the connector none of this appears:
the notification settings page lists no Slack channel.

1. **Install Slack (an administrator).** Open Setup's Slack page,
`/apps/setup/component/messaging/slack`; it needs `setup.write` in your
current organization, as the server does. Paste your Slack app's bot
token (it starts with `xoxb-`) and choose **Install**. Slack checks the
token before anything is saved; it is stored encrypted and never shown
again, so the field is always empty. **Save token** sets it again, for
instance after Slack refused it (the page then says **Token refused**).
2. **Connect (each person).** On **Notification Settings**, the Slack
section's **Connect Slack** asks for a proposal: a Slack user of your
workspace with the person's verified email, not linked to anyone else.
The proposal names no one until the person chooses **Confirm**; **Cancel**
drops it. Nothing reaches them on Slack before they confirm.
**Disconnect** removes the link.
3. **Manage links (an administrator).** The same Slack page lists every
link (the person, the Slack user once confirmed, and when) and removes
one; the person is told by in-app message and email and can connect again.
**Remove Slack** removes the install and every link, and tells each linked
person the same way.

## Quick paths

| I need to… | Do this |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '
import { builtInLocales } from '@object-ui/i18n/locales';
import { NotificationSettingsPage } from './NotificationSettingsPage';
import { MY_PREFERENCES_URL } from './myPreferences';
import { SLACK_LINK_URL } from './slackDoors';
import { getAppComponent } from '../../services/componentRegistry';
// The registry check below loads every built-in page, which reaches the
// metadata admin's dynamic `@objectstack/lint` import: pay that load at
Expand Down Expand Up @@ -66,10 +67,22 @@ function answer(taskEnabled: boolean, taskRow?: string, general: General = BUILT
};
}

function host(apiFetch: ReturnType<typeof vi.fn>, adapter: { create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> }) {
const NO_SLACK_INSTALL = { data: { account: null, link: null } };

/**
* The Slack link door (`/me/slack-link`) answers through `slackFetch`, so
* `apiFetch` counts only the preference reads these tests are about.
*/
function host(
apiFetch: ReturnType<typeof vi.fn>,
adapter: { create: ReturnType<typeof vi.fn>; update: ReturnType<typeof vi.fn> },
slackFetch: (url: string, init?: RequestInit) => Promise<Response> = async () => json(NO_SLACK_INSTALL),
) {
const prefsFetch = apiFetch as unknown as (url: string, init?: RequestInit) => Promise<Response>;
const routed = (url: string, init?: RequestInit) => (url.startsWith(SLACK_LINK_URL) ? slackFetch(url, init) : prefsFetch(url, init));
return ({ children }: { children: ReactNode }) => (
<AdapterCtx.Provider value={adapter as never}>
<SchemaRendererProvider dataSource={adapter as never} apiFetch={apiFetch as never}>
<SchemaRendererProvider dataSource={adapter as never} apiFetch={routed as never}>
{children}
</SchemaRendererProvider>
</AdapterCtx.Provider>
Expand Down Expand Up @@ -366,3 +379,29 @@ describe('the caller\'s grant on sys_notification_preference decides whether the
);
});
});

describe('the Slack section is drawn only where the preference door lists slack', () => {
const withoutSlack = () => {
const body = answer(false);
body.data.channels = body.data.channels.filter((c) => c.channel !== 'slack');
body.data.topics = body.data.topics.map((t) => ({ ...t, channels: t.channels.filter((c) => c.channel !== 'slack') }));
return body;
};

it('with slack listed, the section reads the person’s link', async () => {
const slackFetch = vi.fn(async () => json(NO_SLACK_INSTALL));
render(<NotificationSettingsPage />, { wrapper: host(vi.fn(async () => json(answer(false))), { create: vi.fn(), update: vi.fn() }, slackFetch) });

expect(await screen.findByTestId('slack-link-section')).toBeInTheDocument();
await waitFor(() => expect(slackFetch).toHaveBeenCalledWith(SLACK_LINK_URL, expect.objectContaining({ method: 'GET' })));
});

it('without slack listed, no section and no Slack door is called', async () => {
const slackFetch = vi.fn(async () => json(NO_SLACK_INSTALL));
render(<NotificationSettingsPage />, { wrapper: host(vi.fn(async () => json(withoutSlack())), { create: vi.fn(), update: vi.fn() }, slackFetch) });

await screen.findByTestId('notification-settings-matrix');
expect(screen.queryByTestId('slack-link-section')).toBeNull();
expect(slackFetch).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*
* Channels are columns as the door lists them, so a channel the deployment
* adds later (Slack, …) appears without a change here; a channel the
* deployment cannot send on yet says so in its header.
* deployment cannot send on yet says so in its header. Where the door lists
* `slack` (connector-slack is composed), the page also draws the person's own
* Slack link (`SlackLinkSection`): Slack delivers only to a confirmed link.
*
* A caller who holds neither a create nor an edit grant on
* `sys_notification_preference` (an external member: `external_default`
Expand Down Expand Up @@ -75,6 +77,7 @@ import {
type PreferenceWrite,
type QuietHoursWindow,
} from './myPreferences.js';
import { SlackLinkSection } from './SlackLinkSection.js';

type Load = { readonly state: 'loading' } | { readonly state: 'failed' } | { readonly state: 'read'; readonly prefs: MyPreferences };

Expand All @@ -94,6 +97,9 @@ const SOURCE_KEY: Record<PreferenceSource, string> = {
mandatory: 'notificationSettings.sourceMandatory',
};

/** The channel the Slack section belongs to, as the preference door lists it. */
const SLACK_CHANNEL = 'slack';

function errorText(err: unknown): string {
return err instanceof Error && err.message ? err.message : String(err);
}
Expand Down Expand Up @@ -336,6 +342,8 @@ export function NotificationSettingsPage() {
</div>
</CardContent>
</Card>

{apiFetch && prefs.channels.some((c) => c.channel === SLACK_CHANNEL) && <SlackLinkSection apiFetch={apiFetch} />}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* The person's Slack section (#34730 step 3): connect → proposal → confirm →
* linked, cancel, disconnect, and each answer of the Slack link doors drawn as
* the door gave it. The doors are faked by URL and method with the envelopes
* `slack-link-routes.ts` writes; `t` echoes the KEY.
*/

import '@testing-library/jest-dom/vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';

vi.mock('@object-ui/i18n', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
useObjectTranslation: () => ({ t: (key: string) => `«${key}»`, language: 'en' }),
}));

import { SlackLinkSection } from './SlackLinkSection';
import { SLACK_LINK_URL } from './slackDoors';

const ACME = { id: 'acc1', workspace: 'Acme', workspaceId: 'T1', status: 'active' };
const LINKED = { id: 'l1', userId: 'alice', slackUserId: 'UADA', slackUserName: 'Ada', state: 'confirmed', confirmedAt: '2026-11-20T10:00:00.000Z' };
const ok = (data: unknown) => new Response(JSON.stringify({ success: true, data }), { status: 200 });
const refused = (status: number, code: string, message: string, userMessage?: string) =>
new Response(JSON.stringify({ success: false, error: { code, message, ...(userMessage ? { userMessage } : {}) } }), { status });

type Route = (state: { account: unknown; link: unknown }) => Response;

/** A fake of the four person doors over one stored state; `routes` overrides a door by `METHOD path`. */
function doors(initial: { account: unknown; link: unknown }, routes: Record<string, Route> = {}) {
const state = { ...initial };
const fetch = vi.fn(async (url: string, init?: RequestInit) => {
const key = `${init?.method ?? 'GET'} ${url}`;
if (routes[key]) return routes[key](state);
switch (key) {
case `GET ${SLACK_LINK_URL}`:
return ok(state);
case `POST ${SLACK_LINK_URL}/proposal`:
state.link = { state: 'proposed' };
return ok({ link: state.link });
case `POST ${SLACK_LINK_URL}/confirm`:
state.link = LINKED;
return ok({ link: LINKED });
case `DELETE ${SLACK_LINK_URL}`: {
const removed = state.link !== null;
state.link = null;
return ok({ removed });
}
}
return refused(404, 'NOT_FOUND', key);
});
return { fetch, state };
}

const calls = (f: ReturnType<typeof vi.fn>) => f.mock.calls.map(([url, init]) => `${(init as RequestInit | undefined)?.method ?? 'GET'} ${url}`);

afterEach(() => {
cleanup();
vi.restoreAllMocks();
});

describe('SlackLinkSection', () => {
it('connect → the proposal names no one → confirm → linked', async () => {
const { fetch } = doors({ account: ACME, link: null });
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-connect'));
const proposal = await screen.findByTestId('slack-link-proposal');
expect(proposal).toHaveTextContent('«slackLink.proposed»');
expect(proposal).not.toHaveTextContent('Ada');

fireEvent.click(screen.getByTestId('slack-link-confirm'));
expect(await screen.findByTestId('slack-link-linked')).toHaveTextContent('«slackLink.linked»');
expect(calls(fetch)).toEqual([
`GET ${SLACK_LINK_URL}`,
`POST ${SLACK_LINK_URL}/proposal`,
`GET ${SLACK_LINK_URL}`,
`POST ${SLACK_LINK_URL}/confirm`,
`GET ${SLACK_LINK_URL}`,
]);
});

it('cancel removes the proposal', async () => {
const { fetch, state } = doors({ account: ACME, link: { state: 'proposed' } });
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-cancel'));
expect(await screen.findByTestId('slack-link-connect')).toBeInTheDocument();
expect(state.link).toBeNull();
expect(calls(fetch)).toContain(`DELETE ${SLACK_LINK_URL}`);
});

it('disconnect removes the link', async () => {
const { fetch, state } = doors({ account: ACME, link: LINKED });
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-disconnect'));
expect(await screen.findByTestId('slack-link-connect')).toBeInTheDocument();
expect(state.link).toBeNull();
});

it('no install: says so and offers nothing', async () => {
const { fetch } = doors({ account: null, link: null });
render(<SlackLinkSection apiFetch={fetch} />);

expect(await screen.findByTestId('slack-link-not-installed')).toHaveTextContent('«slackLink.notInstalled»');
expect(screen.queryByTestId('slack-link-connect')).toBeNull();
});

it('a revoked token: says so and offers no connect', async () => {
const { fetch } = doors({ account: { ...ACME, status: 'revoked' }, link: null });
render(<SlackLinkSection apiFetch={fetch} />);

expect(await screen.findByTestId('slack-link-revoked')).toHaveTextContent('«slackLink.revoked»');
expect(screen.queryByTestId('slack-link-connect')).toBeNull();
});

it('a proposal answering link: null (no verified email, or no Slack user for it) names every cause, never one', async () => {
const { fetch } = doors({ account: ACME, link: null }, { [`POST ${SLACK_LINK_URL}/proposal`]: () => ok({ link: null }) });
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-connect'));
expect(await screen.findByTestId('slack-link-no-match')).toHaveTextContent('«slackLink.noMatch»');
expect(screen.getByTestId('slack-link-connect')).toBeInTheDocument();
});

it('a stale proposal: the server’s own sentence (its userMessage), and a new proposal can be asked for', async () => {
const stale = 'Your email is no longer verified, or is not the email this Slack link was proposed for: ask for a new proposal. Nothing was changed.';
const { fetch } = doors({ account: ACME, link: { state: 'proposed' } }, {
[`POST ${SLACK_LINK_URL}/confirm`]: () => refused(409, 'RESOURCE_CONFLICT', 'english', stale),
});
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-confirm'));
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent(stale);
fireEvent.click(await screen.findByTestId('slack-link-propose-again'));
await waitFor(() => expect(calls(fetch)).toContain(`POST ${SLACK_LINK_URL}/proposal`));
});

it('a replaced or removed proposal: the server’s 404 sentence, and the section reads the door again', async () => {
const gone = 'You have no proposed Slack link in this organization to confirm: ask for a proposal first. Nothing was changed.';
const { fetch } = doors({ account: ACME, link: { state: 'proposed' } }, {
[`POST ${SLACK_LINK_URL}/confirm`]: (s) => {
s.link = null;
return refused(404, 'RESOURCE_NOT_FOUND', gone);
},
});
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-confirm'));
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent(gone);
expect(await screen.findByTestId('slack-link-connect')).toBeInTheDocument();
});

it('Slack refusing the token mid-proposal: the server’s 502 sentence, then the revoked install as re-read', async () => {
const { fetch } = doors({ account: ACME, link: null }, {
[`POST ${SLACK_LINK_URL}/proposal`]: (s) => {
s.account = { ...ACME, status: 'revoked' };
return refused(502, 'EXTERNAL_SERVICE_ERROR', 'Slack answered token_revoked. Nothing was changed.');
},
});
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-connect'));
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent('Slack answered token_revoked. Nothing was changed.');
expect(await screen.findByTestId('slack-link-revoked')).toBeInTheDocument();
});

it('no install when the person clicks: the server’s 409 sentence', async () => {
const message = 'Slack is not installed for this organization: an administrator installs it first. Nothing was changed.';
const { fetch } = doors({ account: ACME, link: null }, {
[`POST ${SLACK_LINK_URL}/proposal`]: (s) => {
s.account = null;
return refused(409, 'RESOURCE_CONFLICT', message);
},
});
render(<SlackLinkSection apiFetch={fetch} />);

fireEvent.click(await screen.findByTestId('slack-link-connect'));
expect(await screen.findByTestId('slack-link-refused')).toHaveTextContent(message);
expect(await screen.findByTestId('slack-link-not-installed')).toBeInTheDocument();
});

it('a failed read says so', async () => {
const { fetch } = doors({ account: null, link: null }, { [`GET ${SLACK_LINK_URL}`]: () => refused(503, 'SERVICE_UNAVAILABLE', 'no data engine') });
render(<SlackLinkSection apiFetch={fetch} />);

expect(await screen.findByTestId('slack-link-load-failed')).toHaveTextContent('«slackLink.loadFailed»');
});
});
Loading
Loading