fix(escalations): fall back to account_id when team_id is null
Users without team_id (solo accounts, pro plans) couldn't see escalations because the query filtered by team_id which was NULL. Now falls back to account_id scoping for both the escalation queue endpoint and the sidebar badge count. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -147,13 +147,20 @@ async def get_sidebar_stats(
|
||||
for row in recent_result.all()
|
||||
]
|
||||
|
||||
# --- Escalation count (team-wide pending escalations) ---
|
||||
# --- Escalation count (team/account-wide pending escalations) ---
|
||||
escalation_count = 0
|
||||
if current_user.team_id:
|
||||
esc_scope = AISession.team_id == current_user.team_id
|
||||
elif current_user.account_id:
|
||||
esc_scope = AISession.account_id == current_user.account_id
|
||||
else:
|
||||
esc_scope = None
|
||||
|
||||
if esc_scope is not None:
|
||||
esc_result = await db.execute(
|
||||
select(func.count()).where(
|
||||
and_(
|
||||
AISession.team_id == current_user.team_id,
|
||||
esc_scope,
|
||||
AISession.status == "requesting_escalation",
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user