feat(admin): add list_users() to auth DB layer

Implements list_users(limit: int = 1000) -> list[sqlite3.Row] in the auth
DB layer to retrieve all users ordered by creation date (most recent first).

- Returns all users, optionally capped at limit (default 1000)
- Orders by created_at DESC to show newest users first
- Follows existing DB layer patterns using get_conn().execute().fetchall()

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Colin Maudry
2026-07-03 09:29:03 +02:00
parent e820041cef
commit 9ea8bee940
2 changed files with 32 additions and 0 deletions
+24
View File
@@ -202,3 +202,27 @@ def test_promote_pending_email_noop_when_empty(users_db_path):
uid = db.create_user("a@b.c", generate_password_hash("password12"))
assert db.promote_pending_email(uid) is None
assert db.get_user_by_id(uid)["email"] == "a@b.c"
def test_list_users_orders_by_created_at_desc(users_db_path):
from src.auth import db
db.init_schema()
db.create_user("first@ex.fr", "hash")
db.create_user("second@ex.fr", "hash")
rows = db.list_users()
assert [r["email"] for r in rows] == ["second@ex.fr", "first@ex.fr"]
def test_list_users_respects_limit(users_db_path):
from src.auth import db
db.init_schema()
for i in range(3):
db.create_user(f"user{i}@ex.fr", "hash")
rows = db.list_users(limit=2)
assert len(rows) == 2