mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
Let a delegate read the dashboard they land on
Ten routes on `/` refused with `undeclared_mode`, which made the first page of account sharing the only page in it that does not work. Each one now declares a mode, per route rather than as a class. Eight are record reads: the dashboard snapshot, the Today digest, the badge grid, the Coach nudge signal and reminder ledger, the medication low-stock thresholds, and the two presentation blobs. The old objection to admitting an aggregate — a summary can carry a finding from a module the grant does not cover — does not hold while a grant is whole-record and all-or-nothing. Every admission site names that, so the day per-module scope lands the aggregates are findable. The layout routes split their verbs. Reading the owner's arrangement is right and, for the dashboard, forced: the snapshot already carries the layout and the client seeds the same cache cell from it, so an actor answer would put two people's layouts in one key. Writing it is not a caregiver's job, so the PUT and DELETE stay bare and refuse. Same on the medication list, where the stored order names the owner's medication ids and means nothing anywhere else. Two are actor surfaces: the UI language belongs to the person reading the screen and must not be transplanted onto the record, and the feature-flag matrix reads the settings singleton and no user row at all. Also fixes a second instance of the delegate-data-under-owner-banner defect, on the same page: the dashboard's client-side band fallback derived blood- pressure targets and the weight range from `/api/auth/me`, which answers about the caller, and painted them over the record's charts. Under a switch it now derives nothing and waits for the snapshot's own bands. The integration suite drives every admitted route with both accounts seeded, proves the two answers differ, and then demands the owner's back.
This commit is contained in:
1 parent
a0fc404fb8
commit
508cc8a60a
17 files changed
+1025
-49
No files matched your search
@@ -11,7 +11,7 @@
|
||||
* lives on its own `User` column (`medication_list_layout_json`) per
|
||||
* the per-surface-column convention.
|
||||
*/
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { apiHandler, requireAuth, requireRecordAuth } from "@/lib/api-handler";
|
||||
import {
|
||||
apiSuccess,
|
||||
buildPayloadDiagnostic,
|
||||
@@ -75,11 +75,21 @@ async function buildMedicationListLayout(
|
||||
}
|
||||
|
||||
export const GET = apiHandler(async () => {
|
||||
const { user } = await requireAuth();
|
||||
// Read: the RECORD's presentation. Write: refused — see the PUT and DELETE.
|
||||
//
|
||||
// Same split as `/api/dashboard/widgets`, and here the read half decides
|
||||
// itself: `order` is a list of MEDICATION IDS, and unknown ids are dropped
|
||||
// at apply time. The caller's own order names the caller's own medications,
|
||||
// so serving it against the owner's cabinet would resolve to nothing and the
|
||||
// owner's list would fall back to default order — a preference that cannot
|
||||
// apply is not a preference, it is noise. `/medications` is a shared
|
||||
// destination, so this is a list a delegate really does see.
|
||||
const { user } = await requireRecordAuth("read");
|
||||
|
||||
// 5-minute TTL matches the dashboard-widgets / insights-layout
|
||||
// caches; the blob changes only on a view toggle or an order save,
|
||||
// which invalidates via `invalidateUserMedicationListLayout()`.
|
||||
// 5-minute TTL matches the dashboard-widgets / insights-layout caches; the
|
||||
// blob changes only on a view toggle or an order save, which invalidates via
|
||||
// `invalidateUserMedicationListLayout()`. Keyed on the resolved id, so a
|
||||
// delegated read fills the owner's cell and never their own.
|
||||
const layout = await cached(
|
||||
caches.medicationListLayout as ServerCache<MedicationListLayoutWithToken>,
|
||||
user.id,
|
||||
@@ -90,6 +100,13 @@ export const GET = apiHandler(async () => {
|
||||
});
|
||||
|
||||
export const PUT = apiHandler(async (request: NextRequest) => {
|
||||
// Bare on purpose, so it refuses under a switch while the GET does not. The
|
||||
// reorder handle sits on `/medications`, which IS a shared destination, so
|
||||
// this is the one refusal on the front-door set a delegate can actually walk
|
||||
// into — and it is the correct one: the stored order is what the OWNER sees
|
||||
// on their own next visit, and a helper tidying somebody else's cabinet into
|
||||
// their preferred sequence is a change the owner never asked for and would
|
||||
// have to undo by hand.
|
||||
const { user } = await requireAuth();
|
||||
|
||||
const { data: rawBody, error: jsonError } = await safeJson(request, {
|
||||
@@ -194,6 +211,8 @@ export const PUT = apiHandler(async (request: NextRequest) => {
|
||||
});
|
||||
|
||||
export const DELETE = apiHandler(async () => {
|
||||
// Bare, for the reason on the PUT: wiping somebody else's stored order is
|
||||
// the same edit with a bigger blast radius.
|
||||
const { user } = await requireAuth();
|
||||
|
||||
await prisma.user.update({
|
||||
|
||||
Reference in new issue
Block a user