Admin hub in /crush33: sidebar, donor lookup, danger-zone actions
Rebuilt the password-gated /crush33 (in-app /comp) screen into an admin
hub with a left sidebar and three sections:
- Comp tickets — the existing entry-only comp creator.
- Donor lookup — admin-only free-text search across the donor master
list + online/offline transaction tables by name / email / phone /
address / bear name (columns discovered per table, deduped by email).
- Actions (danger zone) — heavy warnings, red buttons, and an
"are you sure" modal that spells out exactly what will happen:
• Wipe slate — delete ALL ticket + audit records in the active
event table (donor data untouched, irreversible).
• Switch event table — repoint the app at a different NocoDB
tickets/audit table to start a new event while keeping the old
one intact.
Backend:
- New /api/admin/{status,wipe,switch-table,donor-search}, all gated by
PORTAL_PASSWORD (POST-only so it never lands in a URL/log).
- NocoDBClient + AuditLogger: runtime-switchable tableId, count(),
deleteAll(), probeTable() (reachable + Id-PK check before switching).
- DonorService.search() with adaptive column discovery.
- Table switch persists across redeploys via a small state file on a
new /data volume (Dockerfile creates it owned by node so it's
writable); applied at startup in buildContext.
Also shipped equivalent CLI scripts: scripts/wipe-slate.sh and
scripts/switch-event.sh. Drawer: "Comp tickets" -> "Admin (crush33)".
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
60f0908299
commit
3a3119e324
15 changed files with 1042 additions and 172 deletions
73
scripts/switch-event.sh
Executable file
73
scripts/switch-event.sh
Executable file
|
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
#
|
||||
# switch-event.sh — point the scanner app at a DIFFERENT NocoDB tickets (and
|
||||
# optionally audit) table, e.g. to start a NEW event on a fresh table while
|
||||
# keeping the old table intact for archive. Backs up backend/.env, updates it,
|
||||
# and restarts the app container. The old table is never touched.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/switch-event.sh <TICKETS_TABLE_ID> [AUDIT_TABLE_ID]
|
||||
#
|
||||
# FIRST create the new table(s): in the NocoDB UI, DUPLICATE the current table
|
||||
# with "structure only" (no records). That preserves every column AND the Id
|
||||
# primary key — critical, because updates against a table with no primary key
|
||||
# would hit every row. Then grab the new table id from its URL/API and pass it
|
||||
# here. (The app also fail-safes: it refuses to update a row that has no Id.)
|
||||
#
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
ENV_FILE="$ROOT/backend/.env"
|
||||
CONTAINER="${CONTAINER:-camptickets}"
|
||||
|
||||
NEW_TICKETS="${1:-}"
|
||||
NEW_AUDIT="${2:-}"
|
||||
[ -n "$NEW_TICKETS" ] || { echo "Usage: $0 <TICKETS_TABLE_ID> [AUDIT_TABLE_ID]" >&2; exit 1; }
|
||||
|
||||
get() { grep -E "^$1=" "$ENV_FILE" | head -1 | cut -d= -f2-; }
|
||||
BASE_URL="$(get NOCODB_BASE_URL)"
|
||||
TOKEN="$(get NOCODB_API_TOKEN)"
|
||||
CUR_TICKETS="$(get NOCODB_TABLE_ID)"
|
||||
CUR_AUDIT="$(get NOCODB_AUDIT_TABLE_ID)"
|
||||
|
||||
# Validate a table is reachable and (if it has rows) exposes an Id primary key.
|
||||
check() {
|
||||
local table="$1" tmp http
|
||||
tmp="$(mktemp)"
|
||||
http="$(curl -s -o "$tmp" -w '%{http_code}' -H "xc-token: $TOKEN" \
|
||||
"$BASE_URL/api/v2/tables/$table/records?limit=1")"
|
||||
if [ "$http" != "200" ]; then
|
||||
echo " ✗ $table not reachable (HTTP $http)"; rm -f "$tmp"; return 1
|
||||
fi
|
||||
if ! python3 -c 'import sys,json; l=json.load(open(sys.argv[1]))["list"]; sys.exit(0 if (not l or "Id" in l[0]) else 1)' "$tmp"; then
|
||||
echo " ✗ $table has rows without an Id primary key — refusing"; rm -f "$tmp"; return 1
|
||||
fi
|
||||
rm -f "$tmp"; echo " ✓ $table reachable"
|
||||
}
|
||||
|
||||
echo "Validating new table(s) on $BASE_URL ..."
|
||||
check "$NEW_TICKETS" || exit 1
|
||||
[ -n "$NEW_AUDIT" ] && { check "$NEW_AUDIT" || exit 1; }
|
||||
|
||||
BK="$ENV_FILE.bak.$(date +%Y%m%d-%H%M%S)"
|
||||
cp "$ENV_FILE" "$BK"
|
||||
echo "Backed up env -> $BK"
|
||||
|
||||
echo "Switching tables:"
|
||||
echo " tickets: $CUR_TICKETS -> $NEW_TICKETS"
|
||||
sed -i -E "s|^NOCODB_TABLE_ID=.*|NOCODB_TABLE_ID=$NEW_TICKETS|" "$ENV_FILE"
|
||||
if [ -n "$NEW_AUDIT" ]; then
|
||||
echo " audit: $CUR_AUDIT -> $NEW_AUDIT"
|
||||
sed -i -E "s|^NOCODB_AUDIT_TABLE_ID=.*|NOCODB_AUDIT_TABLE_ID=$NEW_AUDIT|" "$ENV_FILE"
|
||||
else
|
||||
echo " audit: unchanged ($CUR_AUDIT) — pass a second arg to switch it too"
|
||||
fi
|
||||
|
||||
echo "Restarting $CONTAINER ..."
|
||||
( cd "$ROOT" && docker compose up -d --force-recreate >/dev/null )
|
||||
sleep 3
|
||||
|
||||
echo "Now active:"
|
||||
echo " NOCODB_TABLE_ID=$(get NOCODB_TABLE_ID)"
|
||||
echo " NOCODB_AUDIT_TABLE_ID=$(get NOCODB_AUDIT_TABLE_ID)"
|
||||
echo "Old tickets table $CUR_TICKETS kept intact. (env backup: $BK)"
|
||||
57
scripts/wipe-slate.sh
Executable file
57
scripts/wipe-slate.sh
Executable file
|
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
#
|
||||
# wipe-slate.sh — clear ALL ticket + audit records from the tables the scanner
|
||||
# app currently uses, for a clean event run-through. Leaves the table SCHEMAS
|
||||
# intact and does NOT touch donor data. Reads NocoDB creds from backend/.env.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/wipe-slate.sh # prompts for confirmation
|
||||
# scripts/wipe-slate.sh --yes # skip the prompt (for automation)
|
||||
#
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ENV_FILE="${ENV_FILE:-$SCRIPT_DIR/../backend/.env}"
|
||||
|
||||
get() { grep -E "^$1=" "$ENV_FILE" | head -1 | cut -d= -f2-; }
|
||||
BASE_URL="$(get NOCODB_BASE_URL)"
|
||||
TOKEN="$(get NOCODB_API_TOKEN)"
|
||||
TICKETS="$(get NOCODB_TABLE_ID)"
|
||||
AUDIT="$(get NOCODB_AUDIT_TABLE_ID)"
|
||||
|
||||
[ -n "$BASE_URL" ] && [ -n "$TOKEN" ] && [ -n "$TICKETS" ] || {
|
||||
echo "Missing NocoDB config in $ENV_FILE" >&2; exit 1; }
|
||||
|
||||
YES=0
|
||||
case "${1:-}" in -y|--yes) YES=1;; esac
|
||||
|
||||
count() {
|
||||
curl -s -H "xc-token: $TOKEN" "$BASE_URL/api/v2/tables/$1/records?limit=1" \
|
||||
| python3 -c 'import sys,json;print(json.load(sys.stdin).get("pageInfo",{}).get("totalRows",0))'
|
||||
}
|
||||
|
||||
echo "Target: $BASE_URL"
|
||||
echo " tickets ($TICKETS): $(count "$TICKETS") records"
|
||||
[ -n "$AUDIT" ] && echo " audit ($AUDIT): $(count "$AUDIT") records"
|
||||
|
||||
if [ "$YES" -ne 1 ]; then
|
||||
read -rp "Delete ALL of the above? This cannot be undone. [y/N] " ans
|
||||
case "$ans" in y|Y|yes|YES) ;; *) echo "aborted"; exit 1;; esac
|
||||
fi
|
||||
|
||||
wipe() {
|
||||
local label="$1" table="$2" total=0 ids n
|
||||
while :; do
|
||||
ids="$(curl -s -H "xc-token: $TOKEN" "$BASE_URL/api/v2/tables/$table/records?limit=1000&fields=Id" \
|
||||
| python3 -c 'import sys,json;print(json.dumps([{"Id":r["Id"]} for r in json.load(sys.stdin)["list"]]))')"
|
||||
n="$(printf '%s' "$ids" | python3 -c 'import sys,json;print(len(json.load(sys.stdin)))')"
|
||||
[ "$n" -eq 0 ] && break
|
||||
curl -s -o /dev/null -X DELETE -H "xc-token: $TOKEN" -H "Content-Type: application/json" \
|
||||
"$BASE_URL/api/v2/tables/$table/records" --data "$ids"
|
||||
total=$((total + n))
|
||||
done
|
||||
echo " $label: deleted $total"
|
||||
}
|
||||
|
||||
wipe "tickets" "$TICKETS"
|
||||
[ -n "$AUDIT" ] && wipe "audit" "$AUDIT"
|
||||
echo "Done — slate is clean."
|
||||
Loading…
Add table
Add a link
Reference in a new issue