mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
Let an invitation name its sections and offer management
An owner can now narrow a grant to the parts of their record they mean to share, and can offer the third level. Both decisions are made once, on the invitation, and neither widens afterwards. The invite schema takes `scope`: absent or null is the entire record, which is what every stored grant means and what an owner who does not narrow still gets. An empty array, a key outside the vocabulary and the whole-record sentinel are each refused with a 422 naming the field; `inviteGrant` refuses the same three underneath, and its `invalid_scope` now has an HTTP mapping instead of falling into the generic refusal. Offering MANAGE asks for a fresh second factor when the account has one. That gate resolves through the session cookie and has no Bearer fall-through, so a token caller is refused first with `sharing.invite.manage_browser_only` rather than being told it is not authenticated by a route that had just authenticated it. The consequence is deliberate: management of a health record is offered from a browser. The account payload gains `sections` and `level` beside `access` and `canWrite`, resolved server-side and ordered as the consent screen reads. `access` was `grant.access === "WRITE" ? "write" : "read"`, which would have published a grant that can delete entries as read-only; it is a total map now, so the next level cannot ship silent. The capabilities hook carries both facts and turns neither into an affordance yet — the edit and delete controls come back in the release where the routes behind them answer. The consent surface asks two questions in order rather than laying out a nineteen-cell grid. The level is three radios, narrowest preselected. What they can open is two radios, the entire record preselected, and only the narrow branch expands the eight sections with a sentence each. Both honest limits are stated above the checkboxes, where the decision is being made: a section shares everything written in it, and the cross-record surfaces do not appear for a narrowed grant. Documents carries its own warning, cycle appears only for an owner who tracks it, and Manage collapses the question to the one line that answers it. The Manage sentence says the other person can add, change and remove entries, including ones the owner entered themselves, and says in the same breath what it does not reach. The acceptance side gets its own responsibility line rather than the write one wearing a stronger adjective. Six locales.
This commit is contained in:
1 parent
feb9d25e87
commit
ab14fdb6f3
33 files changed
+2273
-155
No files matched your search
@@ -37,6 +37,8 @@ const OWNER = {
|
||||
username: "owner",
|
||||
displayName: "Margarethe",
|
||||
access: "read" as const,
|
||||
level: "read" as const,
|
||||
sections: null,
|
||||
canWrite: false,
|
||||
};
|
||||
|
||||
@@ -52,7 +54,7 @@ const READ_ONLY: AccountAccess = {
|
||||
};
|
||||
const WRITABLE: AccountAccess = {
|
||||
accounts: [OWNER],
|
||||
active: { ...OWNER, access: "write", canWrite: true },
|
||||
active: { ...OWNER, access: "write", level: "write", canWrite: true },
|
||||
canSwitch: true,
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ const OWNER = {
|
||||
username: "owner",
|
||||
displayName: "Margarethe",
|
||||
access: "write" as const,
|
||||
level: "write" as const,
|
||||
sections: null,
|
||||
canWrite: true,
|
||||
};
|
||||
|
||||
@@ -95,7 +97,12 @@ describe("<ChartOverlayControls>", () => {
|
||||
for (const access of ["read", "write"] as const) {
|
||||
mockAccessRef.value = {
|
||||
accounts: [OWNER],
|
||||
active: { ...OWNER, access, canWrite: access === "write" },
|
||||
active: {
|
||||
...OWNER,
|
||||
access,
|
||||
level: access,
|
||||
canWrite: access === "write",
|
||||
},
|
||||
canSwitch: true,
|
||||
};
|
||||
const html = renderToStaticMarkup(
|
||||
|
||||
@@ -25,6 +25,8 @@ const GRANDMOTHER = {
|
||||
username: "gran",
|
||||
displayName: "Margarethe",
|
||||
access: "read" as const,
|
||||
level: "read" as const,
|
||||
sections: null,
|
||||
canWrite: false,
|
||||
};
|
||||
const FATHER = {
|
||||
@@ -32,6 +34,8 @@ const FATHER = {
|
||||
username: "dad",
|
||||
displayName: null,
|
||||
access: "write" as const,
|
||||
level: "write" as const,
|
||||
sections: null,
|
||||
canWrite: true,
|
||||
};
|
||||
|
||||
@@ -114,7 +118,9 @@ describe("<LookingAfterCard>", () => {
|
||||
// about it this second. A grant that lapsed, or a level this build does
|
||||
// not honour, must not promise an add the next request would refuse.
|
||||
const html = render({
|
||||
accounts: [{ ...FATHER, access: "write", canWrite: false }],
|
||||
accounts: [
|
||||
{ ...FATHER, access: "write", level: "write", canWrite: false },
|
||||
],
|
||||
active: null,
|
||||
canSwitch: true,
|
||||
});
|
||||
|
||||
@@ -115,11 +115,14 @@ const OWNER_READ: AccountAccessEntry = {
|
||||
username: "grandma",
|
||||
displayName: "Margarethe",
|
||||
access: "read" as const,
|
||||
level: "read" as const,
|
||||
sections: null,
|
||||
canWrite: false,
|
||||
};
|
||||
const OWNER_WRITE: AccountAccessEntry = {
|
||||
...OWNER_READ,
|
||||
access: "write",
|
||||
level: "write",
|
||||
canWrite: true,
|
||||
};
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ const OWNER = {
|
||||
username: "grandma",
|
||||
displayName: "Margarethe",
|
||||
access: "read" as const,
|
||||
level: "read" as const,
|
||||
sections: null,
|
||||
canWrite: false,
|
||||
};
|
||||
|
||||
@@ -117,7 +119,12 @@ describe("<SharedRecordBanner>", () => {
|
||||
it("drops the read-only line when the server says the grant can write", () => {
|
||||
// Resolved server-side. The banner never decides what a grant permits; the
|
||||
// day a WRITE grant exists this line stops claiming otherwise on its own.
|
||||
const writable = { ...OWNER, access: "write" as const, canWrite: true };
|
||||
const writable = {
|
||||
...OWNER,
|
||||
access: "write" as const,
|
||||
level: "write" as const,
|
||||
canWrite: true,
|
||||
};
|
||||
const html = render(
|
||||
{ accounts: [writable], active: writable, canSwitch: true },
|
||||
<SharedRecordBanner />,
|
||||
|
||||
@@ -63,6 +63,7 @@ const BASE: GrantRow = {
|
||||
id: "g1",
|
||||
account: { id: "acct-1", username: "housemate", displayName: "Jo" },
|
||||
access: "READ",
|
||||
scope: null,
|
||||
state: "ACTIVE",
|
||||
invitedAt: "2026-01-02T10:00:00.000Z",
|
||||
acceptedAt: "2026-01-02T11:00:00.000Z",
|
||||
|
||||
@@ -65,6 +65,7 @@ const BASE: GrantRow = {
|
||||
id: "g1",
|
||||
account: { id: "acct-1", username: "housemate", displayName: "Jo" },
|
||||
access: "READ",
|
||||
scope: null,
|
||||
state: "PENDING",
|
||||
invitedAt: "2026-01-02T10:00:00.000Z",
|
||||
acceptedAt: null,
|
||||
@@ -75,33 +76,57 @@ const BASE: GrantRow = {
|
||||
};
|
||||
|
||||
describe("offering a level", () => {
|
||||
it("offers both levels and preselects the narrower one", () => {
|
||||
it("offers all three levels and preselects the narrowest", () => {
|
||||
const html = render(<GrantInviteCard />);
|
||||
expect(html).toContain('data-slot="grant-invite-access"');
|
||||
expect(html).toContain('data-access="READ"');
|
||||
expect(html).toContain('data-access="WRITE"');
|
||||
expect(html).toContain('data-access="MANAGE"');
|
||||
// The narrow level is the one somebody chooses their way out of.
|
||||
expect(html).toContain('data-access="READ" data-selected="true"');
|
||||
expect(html).toContain('data-access="WRITE" data-selected="false"');
|
||||
expect(html).toContain('data-access="MANAGE" data-selected="false"');
|
||||
});
|
||||
|
||||
it("shows keyboard focus on the option the radio is hidden inside", () => {
|
||||
it("shows keyboard focus on every option the radio is hidden inside", () => {
|
||||
// The radio is `sr-only`, so the browser's own ring lands on a zero-size
|
||||
// box and tabbing through this fieldset moved an invisible selection —
|
||||
// WCAG 2.4.7, on the screen where somebody grants write access to their
|
||||
// health record. The label wears the ring instead, and `has-[:focus-visible]`
|
||||
// is what carries it from the input to the label.
|
||||
//
|
||||
// Both fieldsets are checked, not only the level one: v1.37.0 added a
|
||||
// second group of radios in the same idiom, and a group that lost the ring
|
||||
// would be the same defect shipped again one section further down.
|
||||
const html = render(<GrantInviteCard />);
|
||||
const options = html.match(
|
||||
const levels = html.match(
|
||||
/<label[^>]*data-slot="grant-invite-access-option"[^>]*>/g,
|
||||
);
|
||||
expect(options).toHaveLength(2);
|
||||
for (const option of options ?? []) {
|
||||
const scopes = html.match(
|
||||
/<label[^>]*data-slot="grant-invite-scope-option"[^>]*>/g,
|
||||
);
|
||||
expect(levels).toHaveLength(3);
|
||||
expect(scopes).toHaveLength(2);
|
||||
for (const option of [...(levels ?? []), ...(scopes ?? [])]) {
|
||||
expect(option, option).toContain("has-[:focus-visible]:ring-2");
|
||||
expect(option, option).toContain("has-[:focus-visible]:ring-ring/50");
|
||||
}
|
||||
});
|
||||
|
||||
it("says plainly that manage can change and delete what the owner wrote", () => {
|
||||
const html = render(<GrantInviteCard />);
|
||||
// The clause that separates this level from the one below it. A rewrite
|
||||
// that keeps "manage" and drops this is a rewrite that stops describing
|
||||
// a delete button.
|
||||
expect(html).toContain("add, change and remove entries in your record");
|
||||
expect(html).toContain("including ones you entered yourself");
|
||||
// And the fence, in the same breath. Consent to management is only
|
||||
// meaningful beside what management does not reach.
|
||||
expect(html).toContain("They cannot change your login");
|
||||
expect(html).toContain("who else has access");
|
||||
expect(html).toContain("You can end this at any time.");
|
||||
});
|
||||
|
||||
it("says what the wider level actually does, and what it does not", () => {
|
||||
const html = render(<GrantInviteCard />);
|
||||
// The thing a person reading "write access" gets wrong.
|
||||
@@ -144,6 +169,24 @@ describe("accepting a level", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("asks a manage invitation for its own, heavier consent", () => {
|
||||
grantsRef.value = { given: [], received: [{ ...BASE, access: "MANAGE" }] };
|
||||
const html = render(<GrantsReceivedCard />);
|
||||
|
||||
expect(html).toContain('data-grant-access="MANAGE"');
|
||||
// The row states the level in its own words, not the write level's.
|
||||
expect(html).toContain("change or remove what is in it");
|
||||
expect(html).toContain('data-slot="grant-manage-consent"');
|
||||
// Not the write sentence wearing a stronger adjective: a different
|
||||
// responsibility gets a different sentence.
|
||||
expect(html).not.toContain('data-slot="grant-write-consent"');
|
||||
expect(html).toContain("change or remove what is already in it");
|
||||
expect(html).toContain("recorded under your name");
|
||||
expect(html.indexOf('data-slot="grant-manage-consent"')).toBeLessThan(
|
||||
html.indexOf('data-slot="grant-accept"'),
|
||||
);
|
||||
});
|
||||
|
||||
it("does not ask a read invitation for a write consent", () => {
|
||||
grantsRef.value = { given: [], received: [{ ...BASE, access: "READ" }] };
|
||||
const html = render(<GrantsReceivedCard />);
|
||||
@@ -196,6 +239,21 @@ describe("ending an access, and what it says about what was entered", () => {
|
||||
expect(body).toContain('revokeAttribution({"days":90})');
|
||||
});
|
||||
|
||||
it("tells a manage owner the same, because the question is sharper there", () => {
|
||||
// The condition is "not READ" rather than "is WRITE". A manager put things
|
||||
// in the record AND changed things in it, so "what happens to what they
|
||||
// did" is the sentence this owner most needs, and a level check that
|
||||
// listed WRITE by name would have dropped it exactly where it matters.
|
||||
const body = revokeBody({
|
||||
t,
|
||||
access: "MANAGE",
|
||||
name: "Jo",
|
||||
retentionDays: 90,
|
||||
});
|
||||
expect(body).toContain("recordSharing.given.revokeEntriesStay");
|
||||
expect(body).toContain('revokeAttribution({"days":90})');
|
||||
});
|
||||
|
||||
it("omits the window rather than inventing one", () => {
|
||||
// The number is the operator's setting. A compiled-in 365 here would be
|
||||
// exactly the invented value the sentence exists to avoid.
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* The consent surface for a narrowed grant.
|
||||
*
|
||||
* What an SSR render can prove and what it cannot, stated up front because it
|
||||
* shapes every assertion below. It can prove that a control exists, that a
|
||||
* sentence sits beside it, that a default is the default, and that a level
|
||||
* that must not offer scope does not render one. It CANNOT prove that the
|
||||
* sections somebody ticks reach the server: there is no click here, so the
|
||||
* submit path never runs. That half is `e2e/account-sharing.spec.ts` (which
|
||||
* reads the posted body) and `src/app/api/account/grants/__tests__/` (which
|
||||
* reads the written row).
|
||||
*
|
||||
* The interactive states are reached by rendering the card with the state
|
||||
* already in it — React's `useState` initialiser is not reachable from a
|
||||
* static render, so the expanded state is asserted through the one branch a
|
||||
* static render CAN see: Manage, whose collapse is unconditional. Everything
|
||||
* the expanded panel says is pinned in the bundle test at the bottom, which is
|
||||
* where a dropped honesty sentence would actually be dropped.
|
||||
*
|
||||
* Mutation checks, run and recorded in the stream's report:
|
||||
* - render the eight checkboxes unconditionally (drop the `narrowed` gate) →
|
||||
* "the entire record is the default and the sections stay closed" goes red;
|
||||
* - render the scope fieldset for MANAGE too → "manage collapses the whole
|
||||
* question" goes red.
|
||||
*/
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
|
||||
vi.mock("@/lib/queries/use-account-grants", async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import("@/lib/queries/use-account-grants")>();
|
||||
return {
|
||||
...actual,
|
||||
useInviteGrant: () => ({ mutate: vi.fn(), isPending: false }),
|
||||
};
|
||||
});
|
||||
|
||||
import { GrantInviteCard, resolveInviteScope } from "../grant-invite-card";
|
||||
|
||||
function render(node: React.ReactNode): string {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">{node}</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("choosing what a grant opens", () => {
|
||||
it("asks the scope question for the two levels it applies to", () => {
|
||||
const html = render(<GrantInviteCard />);
|
||||
expect(html).toContain('data-slot="grant-invite-scope"');
|
||||
expect(html).toContain('data-scope="all"');
|
||||
expect(html).toContain('data-scope="some"');
|
||||
});
|
||||
|
||||
it("makes the entire record the default and leaves the sections closed", () => {
|
||||
// The shape of the whole design: narrowing is an act somebody chooses, so
|
||||
// the default costs nothing and the eight checkboxes are not on screen
|
||||
// until they are wanted. A form that showed them all at once would make
|
||||
// the common case look like unfinished work.
|
||||
const html = render(<GrantInviteCard />);
|
||||
expect(html).toContain('data-scope="all" data-selected="true"');
|
||||
expect(html).toContain('data-scope="some" data-selected="false"');
|
||||
expect(html).not.toContain('data-slot="grant-invite-sections"');
|
||||
expect(html).not.toContain('data-slot="grant-invite-section"');
|
||||
});
|
||||
|
||||
it("says nothing about sections before the level is decided", () => {
|
||||
// The honesty sentences belong to the decision, not to the page. Rendered
|
||||
// unconditionally they would be a disclaimer somebody scrolls past; they
|
||||
// appear where the sections do.
|
||||
const html = render(<GrantInviteCard />);
|
||||
expect(html).not.toContain('data-slot="grant-invite-scope-leak"');
|
||||
expect(html).not.toContain('data-slot="grant-invite-scope-aggregates"');
|
||||
});
|
||||
});
|
||||
|
||||
describe("the bundle behind the expanded state", () => {
|
||||
// What the panel says is copy, and copy is where this silently rots. The
|
||||
// strings are asserted against the shipped English bundle rather than
|
||||
// against a render, so a key that stops being written is caught here and a
|
||||
// key that stops being READ is caught by the i18n reverse-coverage guard.
|
||||
const en = JSON.parse(
|
||||
readFileSync(join(process.cwd(), "messages/en.json"), "utf8"),
|
||||
) as { recordSharing: Record<string, Record<string, unknown>> };
|
||||
const invite = en.recordSharing.invite as Record<string, string>;
|
||||
const sections = en.recordSharing.section as Record<
|
||||
string,
|
||||
{ label: string; detail: string }
|
||||
>;
|
||||
|
||||
it("names all eight sections with a sentence each", () => {
|
||||
// Eight, not seven and not nine: the vocabulary is closed, and a section
|
||||
// in the enum without copy would render a blank line on a consent screen.
|
||||
expect(Object.keys(sections).sort()).toEqual(
|
||||
[
|
||||
"cycle",
|
||||
"documents",
|
||||
"illness",
|
||||
"labs",
|
||||
"measurements",
|
||||
"medications",
|
||||
"mind",
|
||||
"profile",
|
||||
].sort(),
|
||||
);
|
||||
for (const [key, entry] of Object.entries(sections)) {
|
||||
expect(entry.label.length, key).toBeGreaterThan(2);
|
||||
// A sentence, not a repeat of the label: the names are the product's
|
||||
// own boundaries and mean nothing to somebody who did not draw them.
|
||||
expect(entry.detail.length, key).toBeGreaterThan(entry.label.length);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps both honest limits, in the words that make them honest", () => {
|
||||
// Leakage: a section shares everything written inside it, notes included.
|
||||
expect(invite.scopeLeakNote).toContain(
|
||||
"Sharing a section shares everything written in it",
|
||||
);
|
||||
// And the aggregates a narrowed grant simply does not get. Saying this
|
||||
// after the fact is a support ticket; saying it here is consent.
|
||||
expect(invite.scopeAggregateNote).toContain(
|
||||
"only appear when the entire record is shared",
|
||||
);
|
||||
});
|
||||
|
||||
it("warns about the one section whose name does not bound its contents", () => {
|
||||
expect(invite.scopeDocumentsNote).toContain("can contain anything");
|
||||
});
|
||||
|
||||
it("states the manage fence in the invitation copy itself", () => {
|
||||
// Not in a tooltip and not in the docs: on the label, where somebody is
|
||||
// deciding.
|
||||
expect(invite.accessManageCapability).toContain(
|
||||
"add, change and remove entries",
|
||||
);
|
||||
expect(invite.accessManageCapability).toContain(
|
||||
"including ones you entered yourself",
|
||||
);
|
||||
expect(invite.accessManageCapability).toContain("They cannot change your");
|
||||
});
|
||||
});
|
||||
|
||||
describe("what the form would send", () => {
|
||||
// The interactive states a static render cannot reach, exercised through
|
||||
// the pure function the form itself calls. This is the half that matters:
|
||||
// the copy above says what a person is agreeing to, this says what leaves
|
||||
// the browser.
|
||||
|
||||
it("sends nothing scoped for the whole record", () => {
|
||||
expect(
|
||||
resolveInviteScope({ access: "READ", narrowed: false, sections: [] }),
|
||||
).toEqual({ mode: "all", scope: null, blocked: false });
|
||||
});
|
||||
|
||||
it("sends the picked sections in reading order, not clicking order", () => {
|
||||
// The state is a click log. Two owners who picked the same three sections
|
||||
// in a different sequence must write rows that look the same, or a diff of
|
||||
// two grants means nothing.
|
||||
const choice = resolveInviteScope({
|
||||
access: "WRITE",
|
||||
narrowed: true,
|
||||
sections: ["documents", "labs", "measurements"],
|
||||
});
|
||||
expect(choice.mode).toBe("pick");
|
||||
expect(choice.scope).toEqual(["measurements", "labs", "documents"]);
|
||||
expect(choice.blocked).toBe(false);
|
||||
});
|
||||
|
||||
it("refuses to send a narrowed invitation with nothing picked", () => {
|
||||
// A grant that opens nothing is not a narrow grant, it is a mistake
|
||||
// wearing one. The server refuses it; the form does not ask.
|
||||
const choice = resolveInviteScope({
|
||||
access: "READ",
|
||||
narrowed: true,
|
||||
sections: [],
|
||||
});
|
||||
expect(choice.blocked).toBe(true);
|
||||
expect(choice.scope).toEqual([]);
|
||||
});
|
||||
|
||||
it("never sends a scope with manage, whatever is still ticked", () => {
|
||||
// The property that needs a test rather than a comment. The checkbox state
|
||||
// survives a trip through the Manage option on purpose — somebody who
|
||||
// narrows, reads the Manage sentence and goes back should find their
|
||||
// sections intact — so "not on screen" is NOT "not in state". The level is
|
||||
// what decides, and it decides here.
|
||||
const choice = resolveInviteScope({
|
||||
access: "MANAGE",
|
||||
narrowed: true,
|
||||
sections: ["medications", "labs"],
|
||||
});
|
||||
expect(choice.mode).toBe("manage");
|
||||
expect(choice.scope).toBeNull();
|
||||
expect(choice.blocked).toBe(false);
|
||||
});
|
||||
|
||||
it("carries the sentence that says why manage has no sections", () => {
|
||||
const en = JSON.parse(
|
||||
readFileSync(join(process.cwd(), "messages/en.json"), "utf8"),
|
||||
) as { recordSharing: { invite: Record<string, string> } };
|
||||
expect(en.recordSharing.invite.scopeManageNote).toBe(
|
||||
"Manage access always covers the entire record.",
|
||||
);
|
||||
// And the consequence of gating it on a second factor, said where
|
||||
// somebody meets it rather than in an error message afterwards.
|
||||
expect(en.recordSharing.invite.manageStepUpNote).toContain("browser");
|
||||
});
|
||||
});
|
||||
@@ -6,33 +6,63 @@ import { UserPlus } from "lucide-react";
|
||||
import { SettingsCard } from "@/components/settings/settings-card";
|
||||
import { SettingsCardHeader } from "@/components/settings/_card-header";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useModuleEnabled } from "@/hooks/use-module-enabled";
|
||||
import { ApiError } from "@/lib/api/api-fetch";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { useInviteGrant } from "@/lib/queries/use-account-grants";
|
||||
import { SHARE_DOMAINS, type ShareDomain } from "@/lib/sharing/scope";
|
||||
|
||||
/**
|
||||
* v1.36.0 — offering somebody access to this record.
|
||||
* v1.37.0 — offering somebody access to this record.
|
||||
*
|
||||
* Two decisions: who, and what they may do. The level is a choice at the
|
||||
* invitation and only there — a grant is READ or WRITE from the moment it is
|
||||
* offered, nothing widens it later, and the way to a wider one is a fresh
|
||||
* invitation the other person accepts again. So this form is the one screen
|
||||
* where the owner's half of that consent is given, and the option labels have
|
||||
* to be worth reading.
|
||||
* Three decisions now: who, what they may do, and how much of the record they
|
||||
* may open. All three are made once, here — a grant is fixed at the level and
|
||||
* over the sections it was offered with, nothing widens it later, and the way
|
||||
* to a wider one is a fresh invitation the other person accepts again. So this
|
||||
* form is the one screen where the owner's half of that consent is given, and
|
||||
* every label on it has to be worth reading.
|
||||
*
|
||||
* The capability sentences say what actually ships rather than the word
|
||||
* "write", which people read as larger than it is. A delegate can ADD:
|
||||
* readings, results, observations, a medication, a dose marked as taken. They
|
||||
* cannot edit or delete anything, including what they added ten seconds ago.
|
||||
* A person who learns that from a support reply rather than from this card was
|
||||
* not told.
|
||||
* ## Why this shape and not the obvious one
|
||||
*
|
||||
* The invitation confers nothing until the other person accepts it. The card
|
||||
* says so above the field rather than after the submit, because that is the
|
||||
* part somebody needs to know BEFORE they type a name: nothing has been shared
|
||||
* yet, and nothing will be until the other side agrees.
|
||||
* The obvious shape is three levels times eight sections laid out at once:
|
||||
* nineteen controls, all visible, all equal. It reads as a permissions matrix
|
||||
* and it makes the common case — "my partner can see everything" — look like
|
||||
* work somebody has to finish. So the form is two questions asked in order,
|
||||
* and the second one is a door rather than a grid:
|
||||
*
|
||||
* * **What they may do** stays what it was, one radio per level, narrowest
|
||||
* preselected, each with the sentence that says what it actually does
|
||||
* rather than the word for it.
|
||||
* * **What they may open** is two radios, whole record preselected. Narrowing
|
||||
* is the branch somebody chooses, and only then do the eight sections
|
||||
* appear. A person who wants the default reads two lines and presses send;
|
||||
* a person who wants to narrow sees at most eight named subjects with a
|
||||
* sentence each, which is a thing a person can hold in their head. Nobody
|
||||
* ever sees nineteen checkboxes.
|
||||
*
|
||||
* The two honest limits are stated inside the expanded state, where the
|
||||
* decision is actually being made, rather than in help text somebody would
|
||||
* have to go looking for: a section leaks through its own notes and names, and
|
||||
* the cross-record surfaces (dashboard, score, digest) do not appear at all for
|
||||
* a narrowed grant. Both are said before the checkboxes, not after them.
|
||||
*
|
||||
* Manage collapses the whole second question to one line, because management
|
||||
* is whole-record by construction. That is a design decision made elsewhere
|
||||
* (a manager who could edit part of a record could still write anything into
|
||||
* that part, so a boundary drawn there would be a promise the product cannot
|
||||
* keep) and this card states its consequence rather than re-deciding it.
|
||||
*
|
||||
* ## The Manage sentence
|
||||
*
|
||||
* It says the other person can add, change and remove entries, including ones
|
||||
* the owner entered themselves. That clause is the whole of what separates
|
||||
* this level from the one below it, and softening it — "manage the record",
|
||||
* "help keep it up to date" — would be describing a delete button as
|
||||
* housekeeping. What Manage does NOT reach is said in the same breath, because
|
||||
* a fence nobody is told about is not reassurance, it is a surprise waiting.
|
||||
*
|
||||
* Errors are named, not generic. "No account with that name" and "that person
|
||||
* already has access" are different situations with different next steps, and
|
||||
@@ -47,22 +77,57 @@ export function GrantInviteCard() {
|
||||
// READ preselected. The narrower level is the one somebody should have to
|
||||
// choose their way out of, not into.
|
||||
const [access, setAccess] = useState<GrantAccessLevel>("READ");
|
||||
// The entire record preselected, for the same reason and with the opposite
|
||||
// sign: narrowing is the deliberate act, so it is the one that costs a click.
|
||||
const [narrowed, setNarrowed] = useState(false);
|
||||
const [sections, setSections] = useState<ShareDomain[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [invited, setInvited] = useState<string | null>(null);
|
||||
|
||||
// Cycle tracking is offered as a section only to somebody who tracks it.
|
||||
// Listing it otherwise would put a subject on the consent screen that has no
|
||||
// data behind it and, for many accounts, no relevance either.
|
||||
const tracksCycle = useModuleEnabled("cycle");
|
||||
const offered = SHARE_DOMAINS.filter(
|
||||
(domain) => domain !== "cycle" || tracksCycle,
|
||||
);
|
||||
|
||||
const choice = resolveInviteScope({ access, narrowed, sections });
|
||||
|
||||
const chooseAccess = (level: GrantAccessLevel) => {
|
||||
setAccess(level);
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const toggleSection = (domain: ShareDomain) => {
|
||||
setSections((current) =>
|
||||
current.includes(domain)
|
||||
? current.filter((d) => d !== domain)
|
||||
: [...current, domain],
|
||||
);
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const submit = (event: React.FormEvent) => {
|
||||
event.preventDefault();
|
||||
const value = identifier.trim();
|
||||
if (value.length === 0) return;
|
||||
if (value.length === 0 || choice.blocked) return;
|
||||
setError(null);
|
||||
setInvited(null);
|
||||
invite.mutate(
|
||||
{ identifier: value, access, expiresAt: endOfDayIso(expiresOn) },
|
||||
{
|
||||
identifier: value,
|
||||
access,
|
||||
scope: choice.scope,
|
||||
expiresAt: endOfDayIso(expiresOn),
|
||||
},
|
||||
{
|
||||
onSuccess: (grant) => {
|
||||
setIdentifier("");
|
||||
setExpiresOn("");
|
||||
setAccess("READ");
|
||||
setNarrowed(false);
|
||||
setSections([]);
|
||||
setInvited(grant.account.username);
|
||||
},
|
||||
onError: (err) => setError(t(inviteErrorKey(err))),
|
||||
@@ -106,19 +171,120 @@ export function GrantInviteCard() {
|
||||
<AccessOption
|
||||
level="READ"
|
||||
selected={access === "READ"}
|
||||
onSelect={() => setAccess("READ")}
|
||||
onSelect={() => chooseAccess("READ")}
|
||||
label={t("recordSharing.invite.accessReadLabel")}
|
||||
capability={t("recordSharing.invite.accessReadCapability")}
|
||||
/>
|
||||
<AccessOption
|
||||
level="WRITE"
|
||||
selected={access === "WRITE"}
|
||||
onSelect={() => setAccess("WRITE")}
|
||||
onSelect={() => chooseAccess("WRITE")}
|
||||
label={t("recordSharing.invite.accessWriteLabel")}
|
||||
capability={t("recordSharing.invite.accessWriteCapability")}
|
||||
/>
|
||||
<AccessOption
|
||||
level="MANAGE"
|
||||
selected={access === "MANAGE"}
|
||||
onSelect={() => chooseAccess("MANAGE")}
|
||||
label={t("recordSharing.invite.accessManageLabel")}
|
||||
capability={t("recordSharing.invite.accessManageCapability")}
|
||||
/>
|
||||
</div>
|
||||
{choice.mode === "manage" && (
|
||||
<p
|
||||
data-slot="grant-invite-manage-stepup"
|
||||
className="text-muted-foreground pl-1 text-xs"
|
||||
>
|
||||
{t("recordSharing.invite.manageStepUpNote")}
|
||||
</p>
|
||||
)}
|
||||
</fieldset>
|
||||
|
||||
{choice.mode === "manage" ? (
|
||||
// Not a hidden section and not a disabled one: the question does not
|
||||
// apply at this level, so what is rendered is the answer to it.
|
||||
<p
|
||||
data-slot="grant-invite-scope-manage"
|
||||
className="text-muted-foreground pl-1 text-xs"
|
||||
>
|
||||
{t("recordSharing.invite.scopeManageNote")}
|
||||
</p>
|
||||
) : (
|
||||
<fieldset className="space-y-1.5" data-slot="grant-invite-scope">
|
||||
<legend className="pl-1 text-sm leading-none font-medium after:content-[':']">
|
||||
{t("recordSharing.invite.scopeLegend")}
|
||||
</legend>
|
||||
<div className="space-y-2">
|
||||
<ScopeOption
|
||||
mode="all"
|
||||
selected={!narrowed}
|
||||
onSelect={() => {
|
||||
setNarrowed(false);
|
||||
setError(null);
|
||||
}}
|
||||
label={t("recordSharing.invite.scopeAllLabel")}
|
||||
capability={t("recordSharing.invite.scopeAllCapability")}
|
||||
/>
|
||||
<ScopeOption
|
||||
mode="some"
|
||||
selected={narrowed}
|
||||
onSelect={() => {
|
||||
setNarrowed(true);
|
||||
setError(null);
|
||||
}}
|
||||
label={t("recordSharing.invite.scopeSomeLabel")}
|
||||
capability={t("recordSharing.invite.scopeSomeCapability")}
|
||||
/>
|
||||
</div>
|
||||
{choice.mode === "pick" && (
|
||||
<div
|
||||
data-slot="grant-invite-sections"
|
||||
className="border-border space-y-3 rounded-md border p-3"
|
||||
>
|
||||
{/* Both limits are stated ABOVE the checkboxes. A caveat under
|
||||
a control somebody has already ticked is a disclaimer; the
|
||||
same sentence above it is part of the decision. */}
|
||||
<div className="text-muted-foreground space-y-1 text-xs">
|
||||
<p data-slot="grant-invite-scope-leak">
|
||||
{t("recordSharing.invite.scopeLeakNote")}
|
||||
</p>
|
||||
<p data-slot="grant-invite-scope-aggregates">
|
||||
{t("recordSharing.invite.scopeAggregateNote")}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
{offered.map((domain) => (
|
||||
<SectionOption
|
||||
key={domain}
|
||||
domain={domain}
|
||||
checked={sections.includes(domain)}
|
||||
onToggle={() => toggleSection(domain)}
|
||||
label={t(`recordSharing.section.${domain}.label`)}
|
||||
detail={t(`recordSharing.section.${domain}.detail`)}
|
||||
// A document can hold a letter, a scan, a whole file
|
||||
// somebody else wrote. It is the one section whose name
|
||||
// does not bound what is inside it, so it says so.
|
||||
warning={
|
||||
domain === "documents"
|
||||
? t("recordSharing.invite.scopeDocumentsNote")
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{choice.blocked && (
|
||||
<p
|
||||
data-slot="grant-invite-scope-empty"
|
||||
className="text-muted-foreground text-xs"
|
||||
>
|
||||
{t("recordSharing.invite.scopeEmptyHint")}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</fieldset>
|
||||
)}
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="grant-invite-expires">
|
||||
{t("recordSharing.invite.expiresLabel")}
|
||||
@@ -138,7 +304,13 @@ export function GrantInviteCard() {
|
||||
<Button
|
||||
type="submit"
|
||||
data-slot="grant-invite-submit"
|
||||
disabled={invite.isPending || identifier.trim().length === 0}
|
||||
// A narrowed invitation with nothing ticked would be a grant that
|
||||
// opens nothing, which the server refuses. The button is inert and
|
||||
// the sentence above says why, rather than sending a request whose
|
||||
// only purpose is to come back as an error.
|
||||
disabled={
|
||||
invite.isPending || identifier.trim().length === 0 || choice.blocked
|
||||
}
|
||||
>
|
||||
{invite.isPending
|
||||
? t("recordSharing.invite.submitting")
|
||||
@@ -159,8 +331,63 @@ export function GrantInviteCard() {
|
||||
);
|
||||
}
|
||||
|
||||
/** The two levels an invitation can carry, as the client names them. */
|
||||
export type GrantAccessLevel = "READ" | "WRITE";
|
||||
/** The three levels an invitation can carry, as the client names them. */
|
||||
export type GrantAccessLevel = "READ" | "WRITE" | "MANAGE";
|
||||
|
||||
/** What the form is asking, and what it would send if asked to send now. */
|
||||
export interface InviteScopeChoice {
|
||||
/**
|
||||
* Which of the three shapes the second question takes: the collapsed line
|
||||
* that answers it for Manage, the whole record, or the section list.
|
||||
*/
|
||||
mode: "manage" | "all" | "pick";
|
||||
/** Exactly what goes on the wire as `scope`. */
|
||||
scope: ShareDomain[] | null;
|
||||
/** Is the form in a state that must not be sent. */
|
||||
blocked: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* The whole of what the form decides, as one pure function.
|
||||
*
|
||||
* Exported and pure for the same reason `endOfDayIso` and `revokeBody` are:
|
||||
* the component's interactive states are not reachable from a static render,
|
||||
* so a click-free suite can prove the copy exists and nothing about what the
|
||||
* copy leads to. This is the part worth proving.
|
||||
*
|
||||
* Two properties it holds, and both are safety rather than tidiness:
|
||||
*
|
||||
* * **A Manage invitation never carries a scope, whatever is ticked.** The
|
||||
* checkbox state deliberately survives a trip through the Manage option —
|
||||
* somebody who picked three sections, read the Manage sentence and went
|
||||
* back should find their three sections still ticked — so "the sections
|
||||
* are not on screen" is not the same as "the sections are not in state".
|
||||
* The level is what decides, and it decides here rather than at the call
|
||||
* site. The server refuses the pair too; this is what stops the form ever
|
||||
* asking.
|
||||
* * **The sections travel in reading order.** The state is a click log, and
|
||||
* two owners who ticked the same three sections in a different sequence
|
||||
* would otherwise write rows that look different and mean the same.
|
||||
*/
|
||||
export function resolveInviteScope({
|
||||
access,
|
||||
narrowed,
|
||||
sections,
|
||||
}: {
|
||||
access: GrantAccessLevel;
|
||||
narrowed: boolean;
|
||||
sections: ShareDomain[];
|
||||
}): InviteScopeChoice {
|
||||
if (access === "MANAGE") {
|
||||
return { mode: "manage", scope: null, blocked: false };
|
||||
}
|
||||
if (!narrowed) return { mode: "all", scope: null, blocked: false };
|
||||
const picked = SHARE_DOMAINS.filter((domain) => sections.includes(domain));
|
||||
// A narrowed invitation with nothing ticked is not a narrow grant, it is a
|
||||
// grant that opens nothing. The server refuses it; the form does not offer
|
||||
// to send it, and says why instead.
|
||||
return { mode: "pick", scope: picked, blocked: picked.length === 0 };
|
||||
}
|
||||
|
||||
/**
|
||||
* One level, with the sentence that says what it actually does.
|
||||
@@ -189,19 +416,7 @@ function AccessOption({
|
||||
data-slot="grant-invite-access-option"
|
||||
data-access={level}
|
||||
data-selected={selected ? "true" : "false"}
|
||||
className={[
|
||||
"flex min-h-11 cursor-pointer items-start gap-3 rounded-md border p-3 transition-colors",
|
||||
// The radio itself is `sr-only`, so the browser's own focus ring lands
|
||||
// on a zero-size box: keyboard focus moved through this fieldset with
|
||||
// nothing visible moving with it. WCAG 2.4.7, on the screen where
|
||||
// somebody decides who may write into their health record. The label
|
||||
// wears the ring instead, on the same `ring-ring/50 ring-2` token the
|
||||
// capture picker's options use.
|
||||
"has-[:focus-visible]:ring-ring/50 has-[:focus-visible]:ring-2",
|
||||
selected
|
||||
? "border-primary bg-primary/5"
|
||||
: "border-border hover:bg-muted/40",
|
||||
].join(" ")}
|
||||
className={optionClass(selected)}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
@@ -223,6 +438,133 @@ function AccessOption({
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whole record, or the sections you pick.
|
||||
*
|
||||
* Deliberately the same control as the level above it: the two questions are
|
||||
* asked in the same voice, so nothing about the second one reads as advanced
|
||||
* or as an exception. The radio is what makes narrowing a branch rather than a
|
||||
* checkbox somebody might leave half-answered.
|
||||
*/
|
||||
function ScopeOption({
|
||||
mode,
|
||||
selected,
|
||||
onSelect,
|
||||
label,
|
||||
capability,
|
||||
}: {
|
||||
mode: "all" | "some";
|
||||
selected: boolean;
|
||||
onSelect: () => void;
|
||||
label: string;
|
||||
capability: string;
|
||||
}) {
|
||||
return (
|
||||
<label
|
||||
data-slot="grant-invite-scope-option"
|
||||
data-scope={mode}
|
||||
data-selected={selected ? "true" : "false"}
|
||||
className={optionClass(selected)}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name="grant-invite-scope"
|
||||
value={mode}
|
||||
checked={selected}
|
||||
onChange={onSelect}
|
||||
className="sr-only"
|
||||
/>
|
||||
<span className="space-y-1">
|
||||
<span className="text-foreground block text-sm font-medium">
|
||||
{label}
|
||||
</span>
|
||||
<span className="text-muted-foreground block text-xs">
|
||||
{capability}
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* One section of the record, with the sentence that says what is in it.
|
||||
*
|
||||
* A real checkbox rather than a chip or a toggle: eight independent yes/no
|
||||
* answers are what a checkbox list is for, and the eight sentences are what
|
||||
* make the names mean something to somebody who did not draw the boundaries.
|
||||
*/
|
||||
function SectionOption({
|
||||
domain,
|
||||
checked,
|
||||
onToggle,
|
||||
label,
|
||||
detail,
|
||||
warning,
|
||||
}: {
|
||||
domain: ShareDomain;
|
||||
checked: boolean;
|
||||
onToggle: () => void;
|
||||
label: string;
|
||||
detail: string;
|
||||
warning?: string;
|
||||
}) {
|
||||
// Explicit association rather than a wrapping `<label>`: the primitive is a
|
||||
// Radix checkbox, which renders a `<button>`. A button is labelable, so an
|
||||
// implicit label would forward its own click to it and a tap on the box
|
||||
// itself could toggle twice. `htmlFor` gives the sentence a hit target
|
||||
// without that.
|
||||
const id = `grant-invite-section-${domain}`;
|
||||
return (
|
||||
<div
|
||||
data-slot="grant-invite-section"
|
||||
data-section={domain}
|
||||
data-checked={checked ? "true" : "false"}
|
||||
className="hover:bg-muted/40 has-[:focus-visible]:ring-ring/50 flex min-h-11 items-start gap-3 rounded-md p-1.5 transition-colors has-[:focus-visible]:ring-2"
|
||||
>
|
||||
<Checkbox
|
||||
id={id}
|
||||
checked={checked}
|
||||
onCheckedChange={onToggle}
|
||||
className="mt-0.5"
|
||||
/>
|
||||
<label htmlFor={id} className="cursor-pointer space-y-0.5">
|
||||
<span className="text-foreground block text-sm font-medium">
|
||||
{label}
|
||||
</span>
|
||||
<span className="text-muted-foreground block text-xs">{detail}</span>
|
||||
{warning && (
|
||||
<span
|
||||
data-slot="grant-invite-section-warning"
|
||||
className="text-muted-foreground block text-xs"
|
||||
>
|
||||
{warning}
|
||||
</span>
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The shared look of a choosable option row.
|
||||
*
|
||||
* The radio itself is `sr-only`, so the browser's own focus ring lands on a
|
||||
* zero-size box: keyboard focus moved through the fieldset with nothing
|
||||
* visible moving with it. WCAG 2.4.7, on the screen where somebody decides who
|
||||
* may write into their health record. The label wears the ring instead, on the
|
||||
* same `ring-ring/50 ring-2` token the capture picker's options use — and both
|
||||
* fieldsets share this function so the second one cannot lose it.
|
||||
*/
|
||||
function optionClass(selected: boolean): string {
|
||||
return [
|
||||
"flex min-h-11 cursor-pointer items-start gap-3 rounded-md border p-3 transition-colors",
|
||||
"has-[:focus-visible]:ring-ring/50 has-[:focus-visible]:ring-2",
|
||||
selected
|
||||
? "border-primary bg-primary/5"
|
||||
: "border-border hover:bg-muted/40",
|
||||
].join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* The chosen day, as the instant access stops.
|
||||
*
|
||||
@@ -254,7 +596,7 @@ function tomorrowIso(): string {
|
||||
* themselves, and telling those two apart is the difference between "fix the
|
||||
* field" and "you already have your own record".
|
||||
*/
|
||||
function inviteErrorKey(err: unknown): string {
|
||||
export function inviteErrorKey(err: unknown): string {
|
||||
const code =
|
||||
err instanceof ApiError && typeof err.meta?.errorCode === "string"
|
||||
? err.meta.errorCode
|
||||
@@ -266,6 +608,15 @@ function inviteErrorKey(err: unknown): string {
|
||||
return "recordSharing.invite.errorDuplicate";
|
||||
case "sharing.invite.invalid":
|
||||
return "recordSharing.invite.errorInvalid";
|
||||
case "sharing.invite.invalid_scope":
|
||||
return "recordSharing.invite.errorScope";
|
||||
// The decided consequence of gating Manage on a fresh second factor: the
|
||||
// step-up is cookie-only, so this reaches a native caller and nobody else.
|
||||
// Named rather than folded into the generic failure, because "use a
|
||||
// browser for this one" is a next step and "the invitation could not be
|
||||
// sent" is not.
|
||||
case "sharing.invite.manage_browser_only":
|
||||
return "recordSharing.invite.errorManageBrowserOnly";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -275,5 +626,12 @@ function inviteErrorKey(err: unknown): string {
|
||||
if (err instanceof ApiError && err.status === 429) {
|
||||
return "recordSharing.invite.errorRateLimited";
|
||||
}
|
||||
// A 401 on a request that was authenticated enough to reach validation is
|
||||
// the step-up gate, not a lapsed session: the owner has a second factor and
|
||||
// has not proved it recently enough to hand somebody management of their
|
||||
// record. Said as the thing to do next.
|
||||
if (err instanceof ApiError && err.status === 401) {
|
||||
return "recordSharing.invite.errorStepUp";
|
||||
}
|
||||
return "recordSharing.invite.errorFailed";
|
||||
}
|
||||
@@ -74,6 +74,11 @@ export function GrantRowItem({
|
||||
// invitation form is the level the server stored, and asserting on
|
||||
// viewport text would pin the copy instead of the value.
|
||||
data-grant-access={grant.access}
|
||||
// Whole record or a named set, as an attribute for the same reason: the
|
||||
// journey has to be able to prove the sections somebody ticked are the
|
||||
// sections the row carries, and asserting on a comma-joined sentence
|
||||
// would pin the copy instead of the value.
|
||||
data-grant-scope={grant.scope === null ? "record" : grant.scope.join(",")}
|
||||
className="flex flex-wrap items-start justify-between gap-3 py-3"
|
||||
>
|
||||
<div className="min-w-0 flex-1 space-y-1">
|
||||
@@ -86,9 +91,17 @@ export function GrantRowItem({
|
||||
</Badge>
|
||||
</div>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{grant.access === "WRITE"
|
||||
? t("recordSharing.row.canWrite")
|
||||
: t("recordSharing.row.readOnly")}
|
||||
{t(LEVEL_KEY[grant.access])}
|
||||
</p>
|
||||
{/* What the level reaches, said beside what the level is. A row that
|
||||
named only the level would answer half of "what can this person
|
||||
see" for every narrowed grant, and the half it left out is the one
|
||||
the owner narrowed on purpose. */}
|
||||
<p
|
||||
data-slot="grant-row-scope"
|
||||
className="text-muted-foreground text-xs"
|
||||
>
|
||||
{scopeLine(grant.scope, t)}
|
||||
</p>
|
||||
<dl className="text-muted-foreground space-y-0.5 text-xs">
|
||||
<div className="flex flex-wrap gap-x-1">
|
||||
@@ -137,6 +150,43 @@ function stateKey(state: GrantState): string {
|
||||
return state.toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* What the level lets somebody do, in the row's own voice.
|
||||
*
|
||||
* A total map rather than a ternary, and the reason is the bug the ternary
|
||||
* had: `access === "WRITE" ? canWrite : readOnly` called anything it did not
|
||||
* recognise read-only, so the release that added a third level would have
|
||||
* described a grant that can delete entries as one that can only look at them.
|
||||
* An unlisted level does not typecheck here.
|
||||
*/
|
||||
const LEVEL_KEY: Record<GrantRow["access"], string> = {
|
||||
READ: "recordSharing.row.readOnly",
|
||||
WRITE: "recordSharing.row.canWrite",
|
||||
MANAGE: "recordSharing.row.canManage",
|
||||
};
|
||||
|
||||
/**
|
||||
* What the grant reaches: the whole record, a named set, or nothing.
|
||||
*
|
||||
* The third case is real and is not a display bug. A stored scope this build
|
||||
* cannot read resolves fail-closed to the empty set, and the server will
|
||||
* refuse every section for that grant on the next request — so the row says
|
||||
* so, rather than rendering an empty list that looks like a rendering fault
|
||||
* and reads like "everything".
|
||||
*/
|
||||
function scopeLine(
|
||||
scope: GrantRow["scope"],
|
||||
t: (key: string, params?: Record<string, string | number>) => string,
|
||||
): string {
|
||||
if (scope === null) return t("recordSharing.row.entireRecord");
|
||||
if (scope.length === 0) return t("recordSharing.row.noSections");
|
||||
return t("recordSharing.row.sections", {
|
||||
sections: scope
|
||||
.map((domain) => t(`recordSharing.section.${domain}.label`))
|
||||
.join(", "),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* "You withdrew it" versus "she handed it back" — the same column, read from
|
||||
* two sides. `revokedBy` is what makes the distinction possible; conflating
|
||||
|
||||
@@ -128,10 +128,13 @@ export function GrantsGivenCard() {
|
||||
* exported from the invite card. The composition is the thing worth pinning:
|
||||
* which sentences appear, and which one is omitted when its number is unknown.
|
||||
*
|
||||
* Two extra sentences for a grant that could add entries, and only for one: a
|
||||
* read grant never put anything in the record, so telling its owner that
|
||||
* "anything they entered stays" would describe something that cannot have
|
||||
* happened. The last sentence is the honest bound on attribution — the activity
|
||||
* Two extra sentences for a grant that could put something in the record, and
|
||||
* only for one: a read grant never did, so telling its owner that "anything
|
||||
* they entered stays" would describe something that cannot have happened. The
|
||||
* condition is "not READ" rather than "is WRITE", so the level that can also
|
||||
* change and remove entries carries both sentences too — for a manage grant
|
||||
* the question "what happens to what they did" is the sharper one, not the
|
||||
* softer. The last sentence is the honest bound on attribution — the activity
|
||||
* view answers "who entered what" for as long as the audit window reaches, and
|
||||
* that window is the operator's setting. It is said with the number the server
|
||||
* resolved, or not said at all.
|
||||
@@ -149,7 +152,7 @@ export function revokeBody({
|
||||
retentionDays?: number;
|
||||
}): string {
|
||||
const lines = [t("recordSharing.given.revokeBody", { name })];
|
||||
if (access === "WRITE") {
|
||||
if (access !== "READ") {
|
||||
lines.push(t("recordSharing.given.revokeEntriesStay"));
|
||||
if (retentionDays !== undefined) {
|
||||
lines.push(
|
||||
|
||||
@@ -93,13 +93,28 @@ export function GrantsReceivedCard() {
|
||||
*
|
||||
* A write invitation asks for something a read invitation does not: that the
|
||||
* person put entries into somebody else's health record under their own
|
||||
* name, permanently, with no way to take one back. That is worth one
|
||||
* sentence before the button rather than a sentence after the first entry.
|
||||
* name, permanently, with no way to take one back. A manage invitation asks
|
||||
* for more again — that they change and remove what the owner wrote — and it
|
||||
* gets its own sentence rather than a stronger adjective on the write one,
|
||||
* because the two are different responsibilities and the difference is the
|
||||
* whole reason the third level exists. Both are worth one sentence before
|
||||
* the button rather than a sentence after the first entry.
|
||||
*
|
||||
* Shown only while the invitation is unanswered — once accepted, the level
|
||||
* is the row's own line and this would be nagging.
|
||||
* and the sections are the row's own lines and this would be nagging.
|
||||
*/
|
||||
function renderConsent(grant: GrantRow) {
|
||||
if (grant.state !== "PENDING" || grant.access !== "WRITE") return null;
|
||||
if (grant.state !== "PENDING") return null;
|
||||
if (grant.access === "MANAGE") {
|
||||
return (
|
||||
<p data-slot="grant-manage-consent" className="text-foreground text-sm">
|
||||
{t("recordSharing.received.manageConsent", {
|
||||
name: accountLabel(grant.account),
|
||||
})}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
if (grant.access !== "WRITE") return null;
|
||||
return (
|
||||
<p data-slot="grant-write-consent" className="text-foreground text-sm">
|
||||
{t("recordSharing.received.writeConsent", {
|
||||
|
||||
Reference in new issue
Block a user