fix(sharing): show a guardian the controls the routes accept (#939)

useRecordCapabilities answers per section now. canWriteDomain and
canManageDomain read the two lists the account payload publishes; in
one's own record they are always true, and under a refused, pending or
unproven context always false. canManage becomes the coarse switch,
true when any section is manageable, and is what the banner and the
navigation read.

Every add, edit and delete control names its own section: labs, mind,
profile, illness, cycle, medications, measurements, documents. Creates
that a WRITE route answers (visits, practitioners) ask canWriteDomain.
The generic delete button, the selection bar, the capture picker, the
dashboard quick entry and the bottom nav take the section from their
callers. Controls whose routes resolve the caller rather than the
record (settings shortcuts, chart overlay preferences, custom metrics,
the Today rail, OCR, efficacy targets, credential tabs) ask for the
caller's own record instead, and the customise-shortcut guard now
requires that shape.

The vault has no delegated write route, so its controls stay withheld
under every grant, and the documents page says so in one sentence
where the upload control would be, in all seven locales.
This commit is contained in:
Marc-André Bombeck committed 2026-09-09 19:42:27 +02:00
1 parent b5c392636f
commit e95612e3d3
64 files changed
+690 -289

No files matched your search

@@ -21,7 +21,11 @@ vi.mock("@/hooks/use-practitioners", () => ({
}));
vi.mock("@/hooks/use-record-capabilities", () => ({
useRecordCapabilities: () => ({ canManage: true }),
useRecordCapabilities: () => ({
canManage: true,
canWriteDomain: () => true,
canManageDomain: () => true,
}),
}));
vi.mock("@/hooks/use-debounced-value", () => ({
@@ -44,7 +44,10 @@ import { PractitionerSheet } from "./practitioner-sheet";
export function PractitionerList({ enabled = true }: { enabled?: boolean }) {
const { t } = useTranslations();
const { canManage } = useRecordCapabilities();
const { canWriteDomain, canManageDomain } = useRecordCapabilities();
// `POST /api/practitioners` answers at WRITE; editing and deleting at MANAGE.
const canAddPractitioner = canWriteDomain("profile");
const canManageProfile = canManageDomain("profile");
const [term, setTerm] = useState("");
const debounced = useDebouncedValue(term, 250);
const list = usePractitioners(debounced, enabled);
@@ -87,7 +90,7 @@ export function PractitionerList({ enabled = true }: { enabled?: boolean }) {
}, [rows]);
const showGroupHeadings = groups.some(([specialty]) => specialty !== null);
const addButton = canManage ? (
const addButton = canAddPractitioner ? (
<Button
type="button"
className="min-h-11"
@@ -186,7 +189,7 @@ export function PractitionerList({ enabled = true }: { enabled?: boolean }) {
</p>
) : null}
</div>
{canManage ? (
{canManageProfile ? (
<div className="flex shrink-0 items-center gap-1">
<Button
type="button"