feat: Settings → Diagnostics, a consented log level and the tab's own log

A user can raise their diagnostics level to Részletes (DEBUG) or Teljes (TRACE) for 24 hours from a
new Settings tab, after a consent box that says what is recorded, that the server keeps it and for
how long (the instance's own retention), and that it lapses. Alap is the base and needs no consent.

- users.diagnostics_level/_until (migration 0087), written only by PUT /api/me/diagnostics, which
  computes the expiry itself; the demo account cannot raise it. /api/me reports the level in force.
- The server logs an elevated user's requests at that level and stores every line of them
  (logs.LevelGate on the stdout handler and the sink; the root is lowered only while an elevation
  is active). Teljes adds the redacted query string to the request line.
- POST /api/diagnostics/events stores the browser's log as source=web rows: account from the
  session, body capped while streaming, events/attrs capped, re-redacted, events under the
  consented level dropped, timestamps clamped, 30 batches a minute, 409 once the level lapsed.
- lib/diagnostics.ts applies the level to the tab and streams only what happens after consent, in
  batches, never its own request lines, with a keepalive flush on pagehide; stops on lapse (its
  own timer), on withdrawal and on 409.
- Detail hooks at DEBUG: which control was clicked (test id, icon, app copy in English — never user
  text, input values or a link's query), visibility/bfcache/resize, filter changes
  (lib/filterLog.ts; typed search only at TRACE), player events (lib/mediaLog.ts; media errors are
  warnings at every level). Offline/online at the base level.
- "Saját napló" viewer: live, newest first, level groups with counts, search, row details, copy
  the filtered events as JSON lines, clear.
- Privacy policy and Terms exist in Hungarian and English (a contract test holds both languages to
  the same sections); the policy now describes the server logs and diagnostic logging, self-service
  deletion and password sign-in.

Fixed on the way:
- A sync auth dependency ran logs.set_user on a copied context, so the account never reached a
  handler's own log lines (measured); a per-request mutable scope carries it now.
- The Settings tab rail left a phone no room (clipped labels, buttons over text): below `sm` it is
  a scrolling row above the content.
- PUT /api/me/preferences took a bare dict body; it is a Pydantic model now.
This commit is contained in:
2026-09-17 02:42:12 +02:00
parent a210992bfc
commit 5883ea509d
49 changed files with 2790 additions and 122 deletions
+56 -21
View File
@@ -2,10 +2,19 @@
// reachable unauthenticated — Google's OAuth consent screen links to them and reviewers
// fetch them directly — so they render outside the authenticated App tree (see main.tsx),
// with no react-query provider: the operator contact is fetched with a bare `send` below.
import { useEffect, useState } from "react";
//
// Both pages exist in Hungarian and English, like the rest of the UI. The prose is a document, not
// a set of UI strings, so each language's body is its own component (see PrivacyPolicy/Terms) and
// `legalBodies.contract.dom.test.tsx` holds the two to the same sections; the chrome around them is i18n.
import { useEffect, useState, type ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { LANGUAGES, setLanguage } from "../../i18n";
import { formatDate } from "../../lib/format";
import { send } from "../../lib/http";
const LAST_UPDATED = "June 14, 2026";
// The day the text last changed materially — bump it with every edit of either body.
const LAST_UPDATED = "2026-09-17";
// Contact shown on the legal pages: the instance operator's configured admin email, from the
// public /auth/config. One shared fetch across the page; null when the operator set none.
@@ -34,8 +43,9 @@ function useOperatorContact(): string | null {
// The operator's contact rendered as a mailto link, or a neutral fallback phrase when unset.
export function ContactEmail() {
const { t } = useTranslation();
const email = useOperatorContact();
if (!email) return <>your instance&apos;s administrator</>;
if (!email) return <>{t("legal.operatorFallback")}</>;
return (
<a href={`mailto:${email}`} className="text-accent hover:underline">
{email}
@@ -43,7 +53,7 @@ export function ContactEmail() {
);
}
export function LegalLink({ href, children }: { href: string; children: React.ReactNode }) {
export function LegalLink({ href, children }: { href: string; children: ReactNode }) {
return (
<a href={href} target="_blank" rel="noreferrer" className="text-accent hover:underline">
{children}
@@ -51,38 +61,57 @@ export function LegalLink({ href, children }: { href: string; children: React.Re
);
}
export default function LegalLayout({
title,
children,
}: {
title: string;
children: React.ReactNode;
}) {
export default function LegalLayout({ title, children }: { title: string; children: ReactNode }) {
const { t, i18n } = useTranslation();
const contact = useOperatorContact();
// A link to a section (`/privacy#diagnostics`): the browser tries to scroll to the fragment before
// this lazily loaded page has rendered it, so jump there once the section exists.
useEffect(() => {
const id = decodeURIComponent(window.location.hash.slice(1));
if (id) document.getElementById(id)?.scrollIntoView();
}, []);
return (
<div className="min-h-screen bg-bg text-fg">
<div className="mx-auto w-[min(92vw,720px)] py-12">
<a href="/" className="inline-block text-2xl font-bold tracking-tight mb-8">
Sift<span className="text-accent">lode</span>
</a>
<div className="mb-8 flex items-center justify-between gap-4">
<a href="/" className="inline-block text-2xl font-bold tracking-tight">
Sift<span className="text-accent">lode</span>
</a>
<div role="group" aria-label={t("legal.languageLabel")} className="flex gap-1 text-xs">
{LANGUAGES.map((lang) => (
<button
key={lang.code}
type="button"
lang={lang.code}
aria-pressed={i18n.language?.startsWith(lang.code) ?? false}
onClick={() => setLanguage(lang.code)}
className="rounded-md px-2 py-1 text-muted hover:text-fg aria-pressed:bg-card aria-pressed:text-fg"
>
{lang.label}
</button>
))}
</div>
</div>
<div className="glass rounded-2xl p-8">
<h1 className="text-2xl font-semibold">{title}</h1>
<p className="text-xs text-muted mt-1 mb-6">Last updated: {LAST_UPDATED}</p>
<p className="text-xs text-muted mt-1 mb-6">
{t("legal.lastUpdated", { date: formatDate(LAST_UPDATED, i18n.language) })}
</p>
<div className="space-y-5 text-sm leading-relaxed text-fg/90">{children}</div>
</div>
<footer className="mt-6 flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted">
<a href="/" className="hover:text-fg transition">
Home
{t("legal.home")}
</a>
<a href="/privacy" className="hover:text-fg transition">
Privacy Policy
{t("common.privacyPolicy")}
</a>
<a href="/terms" className="hover:text-fg transition">
Terms of Service
{t("common.termsOfService")}
</a>
{contact && (
<a href={`mailto:${contact}`} className="hover:text-fg transition">
Contact
{t("legal.contact")}
</a>
)}
</footer>
@@ -91,6 +120,12 @@ export default function LegalLayout({
);
}
export function H2({ children }: { children: React.ReactNode }) {
return <h2 className="text-base font-semibold text-fg pt-2">{children}</h2>;
/** A section heading. `id` is required: it is the anchor a link can point at (Settings →
* Diagnosztika links `/privacy#diagnostics`), and what holds the two languages to the same sections. */
export function H2({ id, children }: { id: string; children: ReactNode }) {
return (
<h2 id={id} className="text-base font-semibold text-fg pt-2 scroll-mt-6">
{children}
</h2>
);
}