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

+4 -4
View File
@@ -44,7 +44,7 @@ export default function LabsPage() {
// Scanning a report is not: it files a document and commits through the OCR
// route, and neither is delegated. So a WRITE delegate keeps the manual add
// and loses the choice menu around it.
const { canAdd, canManage, inSharedRecord } = useRecordCapabilities();
const { canAdd, inSharedRecord } = useRecordCapabilities();
const mounted = useMounted();
const router = useRouter();
const queryClient = useQueryClient();
@@ -69,7 +69,7 @@ export default function LabsPage() {
isLoading,
labsEnabled: enabled,
mounted,
canManage,
ownRecord: !inSharedRecord,
}),
);
@@ -111,7 +111,7 @@ export default function LabsPage() {
point, left of the primary Add and linking to the Labs settings
page (view, sort order, biomarker CRUD + reorder). Mirrors the
medication page header's wrench glyph + slot + 44px tap floor. */}
{canManage && (
{!inSharedRecord && (
<Button
asChild
variant="ghost"
@@ -133,7 +133,7 @@ export default function LabsPage() {
mode (vision, or local OCR opted-in for text-only providers), so
the surface stays simple for everyone else. When scanning is
unavailable, Add opens the manual form directly. */}
{ocrCapability.data?.available && canManage ? (
{ocrCapability.data?.available && !inSharedRecord ? (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button className="min-h-11 sm:min-h-9">
+2 -2
View File
@@ -169,7 +169,7 @@ export default function MedicationsPageClient() {
// to tapping each card in turn — so withholding it made a caregiver with
// five morning tablets tap five times for nothing. The customize page stays
// withheld; sharing does not cover it at all.
const { canAdd, canManage, inSharedRecord } = useRecordCapabilities();
const { canAdd, inSharedRecord } = useRecordCapabilities();
// v1.18.1 (D3) — medications is an opt-out module. When the account has it
// turned off the whole page disappears (the nav entry is hidden by the same
// gate) and the list query never fires (the API would 403 anyway).
@@ -433,7 +433,7 @@ export default function MedicationsPageClient() {
Same glyph, slot (left of the add button) and responsive
44-px mobile tap floor as the dashboard and insights
headers. */}
{canManage && (
{!inSharedRecord && (
<Button
asChild
variant="ghost"
+8 -6
View File
@@ -21,7 +21,9 @@ import { useTranslations } from "@/lib/i18n/context";
export default function MoodPageClient() {
const { user, isAuthenticated, isLoading } = useAuth();
const { canManage, inSharedRecord } = useRecordCapabilities();
const { canManageDomain, inSharedRecord } = useRecordCapabilities();
// A mood entry is created at MANAGE under the mind section.
const canAddMood = canManageDomain("mind");
const mounted = useMounted();
const router = useRouter();
const queryClient = useQueryClient();
@@ -89,7 +91,7 @@ export default function MoodPageClient() {
the "not part of what was shared" panel: `/settings` is not a
shared-record destination and the shell answers before the
page does. */}
{canManage && (
{!inSharedRecord && (
<Button
asChild
variant="ghost"
@@ -105,13 +107,13 @@ export default function MoodPageClient() {
</Link>
</Button>
)}
{/* v1.36.x — a mood entry is not one of the verbs a grant
admits, so it stays with the account whose record it is. A
delegate at any level gets no add path here. */}
{canManage && (
{/* A mood entry is a MANAGE create: a WRITE delegate gets no add
path here, a guardian or a MANAGE delegate does. */}
{canAddMood && (
<Button
onClick={() => setDialogOpen(true)}
className="min-h-11 sm:min-h-9"
data-slot="mood-add-entry"
>
<Plus className="h-4 w-4" />
{t("mood.addEntry")}