"""Generate the admin-panel API doc's route and permission tables from source. The reason this script exists: those tables drifted ~40% out of date without anyone noticing, because nothing checked them. They are generated from web/src/nav.ts, web/src/permissions.tsx and cmd/telesrv-admin/server.go instead, and the doc carries the generated marker so a hand edit is visible in review as a diff against the next regeneration. Usage: python3 scripts/gen_admin_panel_doc_tables.py # print python3 scripts/gen_admin_panel_doc_tables.py --check # exit 1 if stale """ from __future__ import annotations import argparse import pathlib import re import sys ROOT = pathlib.Path(__file__).resolve().parent.parent WEB = ROOT / "cmd/telesrv-admin/web/src" WEB_PAGES = WEB / "pages" SERVER_GO = ROOT / "cmd/telesrv-admin/server.go" # ---------------------------------------------------------------- nav sections # The section header is matched on its own and the tabs array is then read out by # bracket matching. It used to be captured by one non-greedy (?P.*?) # terminated with `\]\s*\}`, which stops at the first `]` that happens to be # followed by a `}` -- i.e. the closing bracket of an entry's own # `aliases: [...]` -- so a section whose tabs carry aliases lost its tabs and # dropped out of the table with no error at all. /messages/private is that # entry, and the docs silently lost the Messages section because of it. SECTION_RE = re.compile( r'\{\s*(?://[^\n]*\n\s*)*id:\s*"(?P[a-z0-9-]+)",\s*labelKey:\s*"(?P