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

@@ -36,7 +36,9 @@ export function EpisodeVisitsCard({ episodeId }: { episodeId: string }) {
const { t } = useTranslations();
const format = useFormatters();
const { user } = useAuth();
const { canManage } = useRecordCapabilities();
const { canWriteDomain } = useRecordCapabilities();
// The pre-linked visit is a `POST /api/encounters`, which answers at WRITE.
const canAddVisit = canWriteDomain("profile");
const [sheetOpen, setSheetOpen] = useState(false);
const [session, setSession] = useState(0);
@@ -114,7 +116,7 @@ export function EpisodeVisitsCard({ episodeId }: { episodeId: string }) {
</ul>
)}
{canManage ? (
{canAddVisit ? (
<div className="flex flex-wrap items-center gap-1.5">
<Button
type="button"
@@ -135,7 +137,7 @@ export function EpisodeVisitsCard({ episodeId }: { episodeId: string }) {
</CardContent>
</Card>
{canManage ? (
{canAddVisit ? (
<EncounterSheet
key={session}
open={sheetOpen}
@@ -94,7 +94,8 @@ export function IllnessDayTimeline({
}) {
const { t } = useTranslations();
// v1.36.x — logging a day is not a delegated verb.
const { canManage } = useRecordCapabilities();
const { canManageDomain } = useRecordCapabilities();
const canManageIllness = canManageDomain("illness");
const { data, isLoading, isError } = useIllnessDayLogList(episodeId, "desc");
const dayLogs = data?.dayLogs ?? [];
@@ -119,7 +120,7 @@ export function IllnessDayTimeline({
<p className="text-muted-foreground text-sm">
{t("illness.timeline.empty")}
</p>
{canManage && (
{canManageIllness && (
<Button
variant="outline"
className="min-h-11 sm:min-h-9"
@@ -41,7 +41,8 @@ export function IllnessEpisodeDetail({ episodeId }: { episodeId: string }) {
const { t } = useTranslations();
// v1.36.x — logging a day, editing and resolving an episode are the
// owner's; a delegate reads the episode.
const { canManage } = useRecordCapabilities();
const { canManageDomain } = useRecordCapabilities();
const canManageIllness = canManageDomain("illness");
const fmt = useFormatters();
const {
data: episode,
@@ -98,7 +99,7 @@ export function IllnessEpisodeDetail({ episodeId }: { episodeId: string }) {
) : undefined
}
actions={
canManage ? (
canManageIllness ? (
<>
<Button
onClick={() => setLogOpen(true)}
+9 -7
View File
@@ -74,7 +74,8 @@ function EpisodeCard({
view,
}: EpisodeCardProps) {
const { t } = useTranslations();
const { canManage } = useRecordCapabilities();
const { canManageDomain } = useRecordCapabilities();
const canManageIllness = canManageDomain("illness");
const fmt = useFormatters();
const active = episode.resolvedAt === null;
const isChronic = episode.lifecycle === "CHRONIC_ONGOING";
@@ -109,7 +110,7 @@ function EpisodeCard({
</span>
</div>
</div>
{canManage && (
{canManageIllness && (
<div className="flex shrink-0 items-center gap-1">
<Button
variant="outline"
@@ -145,7 +146,7 @@ function EpisodeCard({
<span className="block truncate">{episode.label}</span>
</Link>
</CardTitle>
{canManage && (
{canManageIllness && (
<CardAction>
<EpisodeMenu
episode={episode}
@@ -211,7 +212,7 @@ function EpisodeCard({
flow, promoted from a busy inline cluster. The card navigates to
the detail surface on its title link; this is the one explicit
button. */}
{canManage && (
{canManageIllness && (
<div className="mt-auto pt-0">
<Button
className="min-h-11 w-full sm:min-h-9"
@@ -319,7 +320,7 @@ export function IllnessView() {
// v1.36.x — opening an illness entry is an admitted delegated write. Logging
// a day against one, editing it, resolving it and deleting it are not, so a
// delegate can start the record of an illness and nothing more.
const { canAdd, canManage } = useRecordCapabilities();
const { canAdd, inSharedRecord } = useRecordCapabilities();
const {
data: episodes,
isLoading,
@@ -391,8 +392,9 @@ export function IllnessView() {
actions={
<>
{/* v1.18.6 (MOD-01) — wrench left of the primary Add, linking to the
Illness settings page (view + reorder). */}
{canManage && (
Illness settings page (view + reorder). `/settings` is the
caller's, not the record's, so no grant reaches it. */}
{!inSharedRecord && (
<Button
asChild
variant="ghost"