mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
chore(release): v1.4.25
Largest feature delta in the v1.4.x line. Insights expands into seven dedicated metric sub-pages; GLP-1 medication tracking lands end-to-end (drug-level chart with Research Mode acknowledgment, EMA titration ladder, cadence + compliance, side-effect taxonomy, pen/vial inventory); cross-source priority becomes a two-axis resolver; per-user timezone threads through ten analytics surfaces; Withings activity + sleep v2 sync; onboarding rebuilt as a nested-route wizard; Personal Records ship end-to-end; Health Score provenance accordion; Coach runs native first-party prompts across six locales with a 1800-assertion refusal-probe matrix; OpenAPI drift gate hard-fails; multi-arch GHCR image. Migrations 0043 through 0060 are additive and forward-only. PROMPT_VERSION 4.24.0 → 4.25.0 with GROUND RULE 9 (refuses dose recommendations) and GROUND RULE 15 (refuses drug-level estimates with MDR + MDCG 2021-24 cites). See CHANGELOG.md for the full per-section delta.
This commit is contained in:
1 parent
de0689e419
commit
17b8d8d2c2
528 files changed
+104033
-6524
No files matched your search
@@ -3,6 +3,7 @@
|
||||
import { useMemo } from "react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { toast } from "sonner";
|
||||
import { Cpu, Fingerprint, Globe, KeyRound } from "lucide-react";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { PasswordInput as SettingsPasswordInput } from "@/components/settings/password-input";
|
||||
@@ -81,6 +82,9 @@ export interface AdminSettings {
|
||||
bugReportEnabled: boolean;
|
||||
reminderLateMinutes: number;
|
||||
reminderMissedMinutes: number;
|
||||
// v1.4.25 W7 — null means "fall back to Europe/Berlin in the resolver".
|
||||
defaultUserTimezone: string | null;
|
||||
moodLogGlobal?: boolean;
|
||||
}
|
||||
|
||||
export interface AdminAuditEntry {
|
||||
@@ -286,6 +290,189 @@ export function useAuthActionLabels(): Record<string, string> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* v1.4.25 W8b — Provider column for the Login-Übersicht.
|
||||
*
|
||||
* The audit log doesn't have a dedicated `provider` field; the action
|
||||
* name itself encodes how the login happened (`auth.login.passkey`,
|
||||
* `auth.bearer.success`, …). We derive a coarse provider tag from
|
||||
* the action so admins can see at a glance whether each row is a
|
||||
* password, passkey, API token, or OAuth (Withings) event.
|
||||
*
|
||||
* Keep the mapping exhaustive — every `auth.*` action that lands in
|
||||
* the audit table must resolve to one of `password | passkey |
|
||||
* api_token | withings | unknown`. New actions are wired here once,
|
||||
* mirroring the convention established by `useAuthActionLabels`.
|
||||
*/
|
||||
export type AuthProvider =
|
||||
| "password"
|
||||
| "passkey"
|
||||
| "api_token"
|
||||
| "withings"
|
||||
| "unknown";
|
||||
|
||||
export function providerForAction(action: string): AuthProvider {
|
||||
if (
|
||||
action === "auth.login.passkey" ||
|
||||
action === "auth.passkey.register" ||
|
||||
action === "auth.passkey.delete"
|
||||
) {
|
||||
return "passkey";
|
||||
}
|
||||
if (
|
||||
action === "auth.login.password" ||
|
||||
action === "auth.password.change" ||
|
||||
// Failed sign-ins go through the password endpoint — the passkey
|
||||
// flow has its own `auth.login.failed` row but `details.reason`
|
||||
// disambiguates further; for the column tag, "password" is the
|
||||
// truthful summary of how the credential was offered.
|
||||
action === "auth.login.failed"
|
||||
) {
|
||||
return "password";
|
||||
}
|
||||
if (
|
||||
action === "auth.bearer.success" ||
|
||||
action === "auth.bearer.failure" ||
|
||||
action === "auth.token.autoissue.native" ||
|
||||
action === "auth.token.refresh" ||
|
||||
action === "auth.token.refresh.failed" ||
|
||||
action === "auth.token.refresh.revoke" ||
|
||||
action === "auth.token.revoke"
|
||||
) {
|
||||
return "api_token";
|
||||
}
|
||||
if (action.startsWith("auth.withings")) {
|
||||
return "withings";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
const AUTH_PROVIDER_ICONS = {
|
||||
password: KeyRound,
|
||||
passkey: Fingerprint,
|
||||
api_token: Cpu,
|
||||
withings: Globe,
|
||||
unknown: Globe,
|
||||
} as const;
|
||||
|
||||
export function iconForAuthProvider(
|
||||
provider: AuthProvider,
|
||||
): React.ComponentType<{ className?: string }> {
|
||||
return AUTH_PROVIDER_ICONS[provider];
|
||||
}
|
||||
|
||||
/**
|
||||
* i18n label map for the Provider column. Keys match `AuthProvider`
|
||||
* so callers can index directly: `labels[providerForAction(action)]`.
|
||||
*/
|
||||
export function useAuthProviderLabels(): Record<AuthProvider, string> {
|
||||
const { t, locale } = useTranslations();
|
||||
return useMemo(
|
||||
() => ({
|
||||
password: t("admin.providerPassword"),
|
||||
passkey: t("admin.providerPasskey"),
|
||||
api_token: t("admin.providerApiToken"),
|
||||
withings: t("admin.providerWithings"),
|
||||
unknown: t("admin.providerUnknown"),
|
||||
}),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[locale],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* v1.4.25 W8b — Build the CSV record set for the audit-log export.
|
||||
*
|
||||
* Pulled out of the section component so the column order, header
|
||||
* mapping, and provider/outcome derivation are reachable from a
|
||||
* pure unit test without rendering the React tree. Marc's spec pins
|
||||
* the column order at `timestamp → user → IP → location → provider
|
||||
* → outcome` (email is absent from the audit-log API and would
|
||||
* require schema/API changes that are out of scope). `action` and
|
||||
* `details` follow so the export keeps the full triage payload.
|
||||
*
|
||||
* `formatTimestamp` is injected (not imported) so the production
|
||||
* callsite passes the user-tz formatter (`formatInUserTz`) while the
|
||||
* unit test passes a deterministic stub.
|
||||
*/
|
||||
export interface AuditCsvEntry {
|
||||
createdAt: string;
|
||||
action: string;
|
||||
ipAddress: string | null;
|
||||
location: string | null;
|
||||
details: string | null;
|
||||
user: { id: string; username: string } | null;
|
||||
}
|
||||
|
||||
export interface AuditCsvLabels {
|
||||
timestamp: string;
|
||||
user: string;
|
||||
ip: string;
|
||||
location: string;
|
||||
provider: string;
|
||||
outcome: string;
|
||||
action: string;
|
||||
details: string;
|
||||
outcomeFailed: string;
|
||||
outcomeSuccess: string;
|
||||
unknownUser: string;
|
||||
providerLabels: Record<AuthProvider, string>;
|
||||
}
|
||||
|
||||
export interface AuditCsvRecord {
|
||||
timestamp: string;
|
||||
user: string;
|
||||
ip: string;
|
||||
location: string;
|
||||
provider: string;
|
||||
outcome: string;
|
||||
action: string;
|
||||
details: string;
|
||||
// Index signature so the record satisfies the structural
|
||||
// `ExportableRecord` contract used by `toCSV`. Fixed columns above
|
||||
// still drive the order of the emitted CSV.
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export function buildAuditLogCsvRecords(
|
||||
entries: AuditCsvEntry[],
|
||||
labels: AuditCsvLabels,
|
||||
formatTimestamp: (iso: string) => string,
|
||||
): AuditCsvRecord[] {
|
||||
return entries.map((entry) => {
|
||||
const provider = providerForAction(entry.action);
|
||||
const isFailed =
|
||||
entry.action === "auth.login.failed" ||
|
||||
entry.action === "auth.bearer.failure" ||
|
||||
entry.action === "auth.token.refresh.failed";
|
||||
return {
|
||||
timestamp: formatTimestamp(entry.createdAt),
|
||||
user: entry.user?.username ?? labels.unknownUser,
|
||||
ip: entry.ipAddress ?? "",
|
||||
location: entry.location ?? "",
|
||||
provider: labels.providerLabels[provider],
|
||||
outcome: isFailed ? labels.outcomeFailed : labels.outcomeSuccess,
|
||||
action: entry.action,
|
||||
details: entry.details ?? "",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function auditLogCsvHeaderLabels(
|
||||
labels: AuditCsvLabels,
|
||||
): Record<keyof AuditCsvRecord, string> {
|
||||
return {
|
||||
timestamp: labels.timestamp,
|
||||
user: labels.user,
|
||||
ip: labels.ip,
|
||||
location: labels.location,
|
||||
provider: labels.provider,
|
||||
outcome: labels.outcome,
|
||||
action: labels.action,
|
||||
details: labels.details,
|
||||
};
|
||||
}
|
||||
|
||||
export function useSystemStatus() {
|
||||
return useQuery({
|
||||
queryKey: ["admin", "status"],
|
||||
|
||||
Reference in new issue
Block a user