@@ -4283,26 +4283,17 @@ def _get_user_by_email_sync(self, email: str) -> dict[str, Any] | None:
42834283 "email" : row [7 ],
42844284 }
42854285
4286-
42874286 # ------------------------------------------------------------------
42884287 # AS-1 (#200) — persona_assignments CRUD
42894288 # ------------------------------------------------------------------
42904289
4291- async def list_persona_assignments (
4292- self , limit : int = 50 , offset : int = 0
4293- ) -> tuple [list [dict ], int ]:
4290+ async def list_persona_assignments (self , limit : int = 50 , offset : int = 0 ) -> tuple [list [dict ], int ]:
42944291 """Return paginated persona assignments joined with user email."""
4295- return await asyncio .get_event_loop ().run_in_executor (
4296- None , self ._list_persona_assignments_sync , limit , offset
4297- )
4292+ return await asyncio .get_event_loop ().run_in_executor (None , self ._list_persona_assignments_sync , limit , offset )
42984293
4299- def _list_persona_assignments_sync (
4300- self , limit : int = 50 , offset : int = 0
4301- ) -> tuple [list [dict ], int ]:
4294+ def _list_persona_assignments_sync (self , limit : int = 50 , offset : int = 0 ) -> tuple [list [dict ], int ]:
43024295 with self ._engine .connect () as conn :
4303- total_row = conn .execute (
4304- text ("SELECT COUNT(*) FROM persona_assignments" )
4305- ).fetchone ()
4296+ total_row = conn .execute (text ("SELECT COUNT(*) FROM persona_assignments" )).fetchone ()
43064297 total = total_row [0 ] if total_row else 0
43074298 rows = conn .execute (
43084299 text (
@@ -4332,9 +4323,7 @@ def _list_persona_assignments_sync(
43324323
43334324 async def get_persona_assignment (self , username : str ) -> dict | None :
43344325 """Return the persona assignment for a user, or None."""
4335- return await asyncio .get_event_loop ().run_in_executor (
4336- None , self ._get_persona_assignment_sync , username
4337- )
4326+ return await asyncio .get_event_loop ().run_in_executor (None , self ._get_persona_assignment_sync , username )
43384327
43394328 def _get_persona_assignment_sync (self , username : str ) -> dict | None :
43404329 with self ._engine .connect () as conn :
@@ -4506,11 +4495,12 @@ def _disable_persona_assignment_sync(
45064495 # ------------------------------------------------------------------
45074496
45084497 async def count_active_admins (self ) -> int :
4509- """Return count of persona_assignments rows with persona='admin'
4510- and disabled_at IS NULL. Used by the last-admin guard."""
4511- return await asyncio .get_event_loop ().run_in_executor (
4512- None , self ._count_active_admins_sync
4513- )
4498+ """Return count of active admin persona assignments.
4499+
4500+ Counts rows where persona='admin' and disabled_at IS NULL. Used
4501+ by the last-admin guard on the disable endpoint.
4502+ """
4503+ return await asyncio .get_event_loop ().run_in_executor (None , self ._count_active_admins_sync )
45144504
45154505 def _count_active_admins_sync (self ) -> int :
45164506 with self ._engine .connect () as conn :
@@ -4524,18 +4514,17 @@ def _count_active_admins_sync(self) -> int:
45244514 ).fetchone ()
45254515 return int (row [0 ]) if row else 0
45264516
4527- async def count_invites_by_admin (
4528- self , admin_username : str , since : str
4529- ) -> int :
4530- """Count persona_assignments rows assigned by this admin since
4531- the given ISO-8601 timestamp. Used as a proxy for invite-rate."""
4517+ async def count_invites_by_admin (self , admin_username : str , since : str ) -> int :
4518+ """Count persona assignments minted by this admin since a timestamp.
4519+
4520+ Used as a proxy for invite-rate-limit accounting on the persona
4521+ create endpoint (M-5).
4522+ """
45324523 return await asyncio .get_event_loop ().run_in_executor (
45334524 None , self ._count_invites_by_admin_sync , admin_username , since
45344525 )
45354526
4536- def _count_invites_by_admin_sync (
4537- self , admin_username : str , since : str
4538- ) -> int :
4527+ def _count_invites_by_admin_sync (self , admin_username : str , since : str ) -> int :
45394528 with self ._engine .connect () as conn :
45404529 row = conn .execute (
45414530 text (
@@ -4550,9 +4539,7 @@ def _count_invites_by_admin_sync(
45504539
45514540 async def list_persona_audit (self , username : str ) -> list [dict ]:
45524541 """Return audit rows for a username, oldest-first (test helper)."""
4553- return await asyncio .get_event_loop ().run_in_executor (
4554- None , self ._list_persona_audit_sync , username
4555- )
4542+ return await asyncio .get_event_loop ().run_in_executor (None , self ._list_persona_audit_sync , username )
45564543
45574544 def _list_persona_audit_sync (self , username : str ) -> list [dict ]:
45584545 with self ._engine .connect () as conn :
@@ -4582,9 +4569,7 @@ def _list_persona_audit_sync(self, username: str) -> list[dict]:
45824569
45834570 async def set_user_email (self , username : str , email : str ) -> None :
45844571 """Update the email on a users row (used when creating persona assignments)."""
4585- await asyncio .get_event_loop ().run_in_executor (
4586- None , self ._set_user_email_sync , username , email
4587- )
4572+ await asyncio .get_event_loop ().run_in_executor (None , self ._set_user_email_sync , username , email )
45884573
45894574 def _set_user_email_sync (self , username : str , email : str ) -> None :
45904575 with self ._engine .begin () as conn :
0 commit comments