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

@@ -9,7 +9,7 @@ describe("shouldProbeOcrCapability", () => {
isLoading: false,
labsEnabled: true,
mounted: true,
canManage: true,
ownRecord: true,
};
expect(shouldProbeOcrCapability(ownerControl)).toBe(true);
@@ -17,7 +17,7 @@ describe("shouldProbeOcrCapability", () => {
shouldProbeOcrCapability({ ...ownerControl, isAuthenticated: false }),
).toBe(false);
expect(
shouldProbeOcrCapability({ ...ownerControl, canManage: false }),
shouldProbeOcrCapability({ ...ownerControl, ownRecord: false }),
).toBe(false);
expect(
shouldProbeOcrCapability({ ...ownerControl, labsEnabled: false }),
@@ -151,6 +151,7 @@ export function BiomarkerManager() {
<Pencil className="h-4 w-4" />
</Button>
<DeleteButton
domain="labs"
onConfirm={() => deleteMutation.mutate(marker.id)}
title={t("labs.biomarker.deleteConfirmTitle")}
description={t("labs.biomarker.deleteConfirmDescription")}
+4 -2
View File
@@ -95,7 +95,8 @@ const READINGS_PAGE_SIZE = 200;
*/
export function LabBiomarkerDetail({ biomarkerId }: { biomarkerId: string }) {
const { user } = useAuth();
const { canAdd, canManage } = useRecordCapabilities();
const { canAdd, canManageDomain } = useRecordCapabilities();
const canManageLabs = canManageDomain("labs");
const { t, locale } = useTranslations();
const router = useRouter();
const queryClient = useQueryClient();
@@ -332,6 +333,7 @@ export function LabBiomarkerDetail({ biomarkerId }: { biomarkerId: string }) {
full marker editor behind the pencil, so the separate range
control was dropped). */}
<DeleteButton
domain="labs"
onConfirm={() => deleteMarker.mutate()}
title={t("labs.biomarker.deleteConfirmTitle")}
description={t("labs.biomarker.deleteConfirmDescription")}
@@ -340,7 +342,7 @@ export function LabBiomarkerDetail({ biomarkerId }: { biomarkerId: string }) {
className="min-h-11 min-w-11 sm:min-h-9 sm:min-w-9"
iconClassName="h-4 w-4"
/>
{canManage && (
{canManageLabs && (
<Button
variant="ghost"
size="icon"
+4 -2
View File
@@ -77,7 +77,8 @@ function parseDecimal(raw: string): number | null {
*/
export function LabHistoryList({ readings }: { readings: LabResultDto[] }) {
const { t } = useTranslations();
const { canManage } = useRecordCapabilities();
const { canManageDomain } = useRecordCapabilities();
const canManageLabs = canManageDomain("labs");
const queryClient = useQueryClient();
// Client-side column sort over the in-memory reading feed.
@@ -379,7 +380,7 @@ export function LabHistoryList({ readings }: { readings: LabResultDto[] }) {
</TableCell>
<TableCell className="pr-4 text-right">
<div className="flex items-center justify-end gap-1">
{canManage && (
{canManageLabs && (
<Button
size="icon"
variant="ghost"
@@ -393,6 +394,7 @@ export function LabHistoryList({ readings }: { readings: LabResultDto[] }) {
</Button>
)}
<DeleteButton
domain="labs"
onConfirm={() => deleteMutation.mutate(r.id)}
title={t("labs.deleteConfirmTitle")}
description={t("labs.deleteConfirmDescription")}
+4 -3
View File
@@ -47,15 +47,16 @@ export function shouldProbeOcrCapability({
isLoading,
labsEnabled,
mounted,
canManage,
ownRecord,
}: {
isAuthenticated: boolean;
isLoading: boolean;
labsEnabled: boolean;
mounted: boolean;
canManage: boolean;
/** In the caller's own record; the probe and the commit resolve the caller, never a grant. */
ownRecord: boolean;
}): boolean {
return isAuthenticated && !isLoading && labsEnabled && mounted && canManage;
return isAuthenticated && !isLoading && labsEnabled && mounted && ownRecord;
}
/** Capability probe — refetched when the scan dialog opens. */