mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
feat: gate a switched browser on the record's modules, not the actor's
Turning a module off for a profile you look after wrote a column nothing on screen was reading. GET /api/auth/me published the ACTOR's module map while switched, and the navigation, the dashboard tiles and the insights sections all gate on it — so a guardian who turned Cycle off for the child kept seeing a Cycle destination inside the child's record, and a guardian who tracks it saw one there whether or not the child did (#939). The map and the resolved cycle flag now answer for the record the session is inside. They are not display preferences: every surface they gate shows the record's data, so the record is what decides. Locale, theme and layout stay the actor's. The record is taken from the grant-validated active entry rather than the session's own selector, so a revoked switch cannot publish somebody's configuration, and with no switch the payload is what it was. Cycle also gets a row on the guardian's Modules surface, which it never had. It is a delegated module, so its state is the record's own cycle profile and modulePreferences.cycle is refused — which left a guardian no way to turn it off for a record whose sex says it should be on. The family names the real column instead of a blob entry the gate ignores. Refs #939
This commit is contained in:
1 parent
f521b03c35
commit
fb1cb4e3ed
9 files changed
+556
-46
No files matched your search
@@ -84,7 +84,7 @@ const moduleMapResolved = z
|
||||
.meta({
|
||||
id: "ModuleMap",
|
||||
description:
|
||||
"Fully-resolved per-user module enable/disable map. Every toggleable module key is present. `false` means the surface should disappear end-to-end (nav, dashboard, insights, …). `cycle` mirrors `cycleTrackingEnabled`; `coach` mirrors the resolved per-user opt-out + operator master flag.",
|
||||
"Fully-resolved module enable/disable map. Every toggleable module key is present. `false` means the surface should disappear end-to-end (nav, dashboard, insights, …). `cycle` mirrors `cycleTrackingEnabled`; `coach` mirrors the resolved per-user opt-out + operator master flag. On `GET /api/auth/me` it answers for the RECORD the session is inside rather than for the caller, because every surface it gates shows the record's data; with no switch — which is every native request, since the Bearer transport carries none — the two are the same account and the payload is unchanged.",
|
||||
});
|
||||
|
||||
const moduleMapEnvelopeInner = z
|
||||
|
||||
@@ -276,7 +276,7 @@ const recordSettingsPatchRequest = z
|
||||
MANAGED_RECORD_SETTINGS_PATCH_SCHEMAS.modules.meta({
|
||||
id: "RecordModuleSettingsPatch",
|
||||
description:
|
||||
"Partial module toggle. Merged onto the record's current preferences; omitted keys keep their value.",
|
||||
"Partial module toggle. `modulePreferences` is merged onto the record's current preferences; omitted keys keep their value. `cycleTrackingEnabled` is separate because `cycle` is a DELEGATED module: its state lives in the record's own cycle profile and `modulePreferences.cycle` is refused, so this is the field that turns cycle tracking on or off for the record — an explicit boolean overrides the default the record's sex would derive. Both fields are optional and at least one is required; an empty body is a 422 rather than a save that changed nothing.",
|
||||
}),
|
||||
MANAGED_RECORD_SETTINGS_PATCH_SCHEMAS.notifications.meta({
|
||||
id: "RecordNotificationSettingsPatch",
|
||||
|
||||
@@ -30,7 +30,7 @@ export const MANAGED_RECORD_SETTINGS_FIELD_ALLOWLIST = {
|
||||
"timeFormat",
|
||||
"dateFormat",
|
||||
],
|
||||
modules: ["modulePreferences"],
|
||||
modules: ["modulePreferences", "cycleTrackingEnabled"],
|
||||
notifications: ["moodReminderEnabled", "notificationPreferences"],
|
||||
thresholds: ["overrides"],
|
||||
coach: ["disableCoach", "preferences"],
|
||||
@@ -140,7 +140,31 @@ const managedCoachPreferencesSchema = coachPrefsSchema
|
||||
*/
|
||||
export const MANAGED_RECORD_SETTINGS_PATCH_SCHEMAS = {
|
||||
profile: profilePatchSchema,
|
||||
modules: z.object({ modulePreferences: modulePrefsPatchSchema }).strict(),
|
||||
/**
|
||||
* Two fields because the module foundation has two kinds of key, and only
|
||||
* one of them lives in `modulePreferencesJson`.
|
||||
*
|
||||
* `cycle` is a DELEGATED module: its user-layer state is owned by
|
||||
* `CycleProfile.cycleTrackingEnabled` (NULL derives from `User.gender`), and
|
||||
* `modulePreferencesJson.cycle` is ignored on purpose — which is why
|
||||
* `modulePrefsPatchSchema` refuses the key. A guardian therefore had no way
|
||||
* to turn Cycle off for a record whose sex says it should be on, and no row
|
||||
* for it in the list either: it is simply not a writable key (#939). Naming
|
||||
* the real column here writes the real source of truth rather than minting a
|
||||
* second one that the gate would ignore.
|
||||
*
|
||||
* Both optional so a client may send either alone; at least one required, so
|
||||
* an empty body is a refusal rather than a save that changed nothing.
|
||||
*/
|
||||
modules: z
|
||||
.object({
|
||||
modulePreferences: modulePrefsPatchSchema.optional(),
|
||||
cycleTrackingEnabled: z.boolean().optional(),
|
||||
})
|
||||
.strict()
|
||||
.refine((patch) => Object.values(patch).some((v) => v !== undefined), {
|
||||
message: "Name at least one field to change",
|
||||
}),
|
||||
notifications: z
|
||||
.object({
|
||||
moodReminderEnabled: z.boolean().optional(),
|
||||
|
||||
Reference in new issue
Block a user