feat(server): expose marks_as_test on InviteCode
Adds the field to the dataclass, SELECT list in get_invite_codes, and a new get_invite_code_details helper that the register flow will use to discover whether an invite should flag new accounts as test accounts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -123,6 +123,7 @@ class InviteCode:
|
||||
max_uses: int
|
||||
use_count: int
|
||||
is_active: bool
|
||||
marks_as_test: bool = False
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
@@ -135,6 +136,7 @@ class InviteCode:
|
||||
"use_count": self.use_count,
|
||||
"is_active": self.is_active,
|
||||
"remaining_uses": max(0, self.max_uses - self.use_count),
|
||||
"marks_as_test": self.marks_as_test,
|
||||
}
|
||||
|
||||
|
||||
@@ -1117,6 +1119,7 @@ class AdminService:
|
||||
query = """
|
||||
SELECT c.code, c.created_by, c.created_at, c.expires_at,
|
||||
c.max_uses, c.use_count, c.is_active,
|
||||
COALESCE(c.marks_as_test, FALSE) as marks_as_test,
|
||||
u.username as created_by_username
|
||||
FROM invite_codes c
|
||||
JOIN users_v2 u ON c.created_by = u.id
|
||||
@@ -1138,6 +1141,7 @@ class AdminService:
|
||||
max_uses=row["max_uses"],
|
||||
use_count=row["use_count"],
|
||||
is_active=row["is_active"],
|
||||
marks_as_test=row["marks_as_test"],
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
@@ -1213,6 +1217,34 @@ class AdminService:
|
||||
|
||||
return True
|
||||
|
||||
async def get_invite_code_details(self, code: str) -> Optional[dict]:
|
||||
"""
|
||||
Look up an invite code's row including marks_as_test.
|
||||
|
||||
Returns None if the code does not exist. Does NOT validate expiry
|
||||
or usage — use validate_invite_code for that. This is purely a
|
||||
helper for the register flow to discover the test-seed flag.
|
||||
"""
|
||||
async with self.pool.acquire() as conn:
|
||||
row = await conn.fetchrow(
|
||||
"""
|
||||
SELECT code, max_uses, use_count, is_active,
|
||||
COALESCE(marks_as_test, FALSE) as marks_as_test
|
||||
FROM invite_codes
|
||||
WHERE code = $1
|
||||
""",
|
||||
code,
|
||||
)
|
||||
if not row:
|
||||
return None
|
||||
return {
|
||||
"code": row["code"],
|
||||
"max_uses": row["max_uses"],
|
||||
"use_count": row["use_count"],
|
||||
"is_active": row["is_active"],
|
||||
"marks_as_test": row["marks_as_test"],
|
||||
}
|
||||
|
||||
async def use_invite_code(self, code: str) -> bool:
|
||||
"""
|
||||
Use an invite code (increment use count).
|
||||
|
||||
Reference in New Issue
Block a user