Third audit: security fixes and server-side scalability
Security: - docx unzip reads each part once (a repeated entry was a zip bomb) - request files must be named for their type (no PDF named .html) - team roster hidden when its organization is unpublished - /people?ids= hides draft organizations, takes 200 ids - v_events takes the first published host and reads event_hosts directly (migration 059, plus an index on person_awards.event_id) - group accounts refused while access groups are off; group sync can't undo a superadmin's disable - 64 KB body limit on login, feedback and csp-report - Drive pick-up races no longer 500; random upload boundary Scalability: - /events filters by scope, host, status and type on the server; Home no longer prefetches every event - /organizations leaves out bodies and leadership; the map's group panel fetches its own - admin lists page with Show more and a real count - content request record search and the newsletter's post list ask the server Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0bb4b8685f
commit
f99010252f
18 changed files with 229 additions and 96 deletions
|
|
@ -1,10 +1,9 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
EVENT DATA
|
||||
|
||||
One request, filtered per band. The Retreats page has three
|
||||
bands of events, and all three call this hook, the cache in
|
||||
api.ts keys on the path, so they share a single fetch and each
|
||||
narrows the result to what it shows.
|
||||
Events, narrowed by the server. Each filter is part of the path,
|
||||
so the cache in api.ts gives each its own entry and callers
|
||||
asking the same thing share one fetch.
|
||||
|
||||
useEvents({ scope: "national" }) one band
|
||||
useEvents({ host: "northwest" }) one host's events
|
||||
|
|
@ -24,47 +23,33 @@
|
|||
No fallback. An empty list on a failed request would read as
|
||||
"nothing scheduled" when the truth is "the server is down", so
|
||||
the error comes back and each caller says so.
|
||||
|
||||
Filtering here rather than in the query keeps the endpoint to
|
||||
one cached response. At a few dozen events that's the right
|
||||
trade; if the list ever runs to hundreds, move the filters into
|
||||
the URL and let each become its own cache entry.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { useResource } from "./useResource.ts";
|
||||
|
||||
/* One shared empty list, so a memo keyed on `scopes` doesn't
|
||||
/* Shared empty lists, so a memo keyed on them doesn't
|
||||
restart on every render before the data arrives. */
|
||||
const NO_SCOPES: any[] = [];
|
||||
const NO_EVENTS: any[] = [];
|
||||
|
||||
export function useEvents({ scope, host, status, type }: any = {}) {
|
||||
const { data, error, loading } = useResource("/events");
|
||||
/* The path for a filter, as the server reads it (routes/content.js). */
|
||||
export function eventsPath({ scope, host, status, type }: any = {}) {
|
||||
const query = new URLSearchParams();
|
||||
if (scope) query.set("scope", scope);
|
||||
// An organization or a person slug: co-hosting puts one event on
|
||||
// both hosts' lists, which is the point.
|
||||
if (host) query.set("host", host);
|
||||
if (status) query.set("status", status);
|
||||
const types = Array.isArray(type) ? type.join(",") : type;
|
||||
if (types) query.set("type", types);
|
||||
const qs = query.toString();
|
||||
return qs ? `/events?${qs}` : "/events";
|
||||
}
|
||||
|
||||
const all = data?.events;
|
||||
export function useEvents(filter: any = {}) {
|
||||
const { data, error, loading } = useResource(eventsPath(filter));
|
||||
const events = data?.events ?? NO_EVENTS;
|
||||
const scopes = data?.scopes ?? NO_SCOPES;
|
||||
|
||||
/* An array prop is a new identity on every render, which would
|
||||
restart the memo each time. Joining it gives the dependency
|
||||
list something stable to compare. */
|
||||
const typeKey = Array.isArray(type) ? type.join(",") : (type ?? "");
|
||||
|
||||
const events = useMemo(() => {
|
||||
let list = all ?? [];
|
||||
if (scope) list = list.filter(e => e.scope_id === scope);
|
||||
// `host` is an organization or a person slug, and an event can
|
||||
// have several of either, co-hosting puts one event on both
|
||||
// hosts' lists, which is the point.
|
||||
if (host) list = list.filter(e => e.hosts?.some(h => h.id === host));
|
||||
if (status) list = list.filter(e => e.status === status);
|
||||
if (typeKey) {
|
||||
const wanted = new Set(typeKey.split(","));
|
||||
list = list.filter(e => wanted.has(e.event_type));
|
||||
}
|
||||
return list;
|
||||
}, [all, scope, host, status, typeKey]);
|
||||
|
||||
return { events, scopes, loading, error };
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue