Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394"""Who is allowed into the admin site and who counts as a member — theprivate members list.
private/members.json (gitignored, written by hand on the host) is a JSONobject with two arrays:
{"admins": ["did:plc:…", "…"], "members": ["did:plc:…"]}
`admins` may open the admin site and use its writes. `members` (adminsincluded) get the product's member surfaces — for now the fit/no-fitbuttons under posts inside topics, the ground truth the judge will learnfrom. An entry is an atproto DID, or a handle — a handle is resolved lazilyagainst the public directory the first time it is checked and the resultcached, so the file can be edited by hand with handles and kept stable withDIDs.
This file is the only allowlist in the product, and it is deliberately a filenext to the store, not a table: it lists people, not posts, and editing it isan operator act on the host — exactly the same trust level as editing .env."""
import jsonimport threadingfrom pathlib import Path
ROOT = Path(__file__).parentMEMBERS_FILE = ROOT.parent / "private" / "members.json"
_load_lock = threading.Lock()# resolved handle -> did, so a handle entry is only ever resolved once_handle_cache: dict[str, str] = {}
def _load() -> dict[str, list[str]]: """The raw `admins` and `members` entries (DIDs and handles, as written).""" try: data = json.loads(MEMBERS_FILE.read_text()) except (json.JSONDecodeError, OSError, FileNotFoundError): return {"admins": [], "members": []} out = {"admins": [], "members": []} for key in out: out[key] = [str(x).strip() for x in (data.get(key) or []) if str(x).strip()] return out
def _resolve(entries: list[str]) -> set[str]: """Entries as resolved DIDs. Handles are resolved once and cached; a handle that cannot be resolved is dropped, not fatal — a directory hiccup must not lock a member out, and the next check re-tries.""" out: set[str] = set() for entry in entries: if entry.startswith("did:"): out.add(entry) continue with _load_lock: if entry in _handle_cache: out.add(_handle_cache[entry]) continue try: from shared.identity import handle_to_did did = handle_to_did(entry) except Exception: # noqa: BLE001 — an unresolvable entry is just absent continue if did: with _load_lock: _handle_cache[entry] = did out.add(did) return out
def admin_dids() -> set[str]: return _resolve(_load()["admins"])
def member_dids() -> set[str]: lists = _load() return _resolve(lists["admins"] + lists["members"])
def is_admin(did: str) -> bool: """Whether this DID may use the admin site. The empty string (no session, or a request that did not come through the proxy) is never an admin.""" if not did: return False return did in admin_dids()
def is_member(did: str) -> bool: """Whether this DID counts as a member — admins and members both. Members get the product's member surfaces (the fit/no-fit buttons).""" if not did: return False return did in member_dids()