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:
@@ -406,14 +406,19 @@ async def get_escalation_queue(
|
|||||||
db: Annotated[AsyncSession, Depends(get_db)],
|
db: Annotated[AsyncSession, Depends(get_db)],
|
||||||
_: None = Depends(require_engineer_or_admin),
|
_: None = Depends(require_engineer_or_admin),
|
||||||
):
|
):
|
||||||
"""List sessions requesting escalation for the current user's team."""
|
"""List sessions requesting escalation for the current user's team/account."""
|
||||||
if not current_user.team_id:
|
# Match by team_id if available, otherwise fall back to account_id
|
||||||
|
if current_user.team_id:
|
||||||
|
scope_filter = AISession.team_id == current_user.team_id
|
||||||
|
elif current_user.account_id:
|
||||||
|
scope_filter = AISession.account_id == current_user.account_id
|
||||||
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
result = await db.execute(
|
result = await db.execute(
|
||||||
select(AISession)
|
select(AISession)
|
||||||
.where(
|
.where(
|
||||||
AISession.team_id == current_user.team_id,
|
scope_filter,
|
||||||
AISession.status == "requesting_escalation",
|
AISession.status == "requesting_escalation",
|
||||||
)
|
)
|
||||||
.order_by(AISession.created_at.desc())
|
.order_by(AISession.created_at.desc())
|
||||||
|
|||||||
@@ -147,13 +147,20 @@ async def get_sidebar_stats(
|
|||||||
for row in recent_result.all()
|
for row in recent_result.all()
|
||||||
]
|
]
|
||||||
|
|
||||||
# --- Escalation count (team-wide pending escalations) ---
|
# --- Escalation count (team/account-wide pending escalations) ---
|
||||||
escalation_count = 0
|
escalation_count = 0
|
||||||
if current_user.team_id:
|
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(
|
esc_result = await db.execute(
|
||||||
select(func.count()).where(
|
select(func.count()).where(
|
||||||
and_(
|
and_(
|
||||||
AISession.team_id == current_user.team_id,
|
esc_scope,
|
||||||
AISession.status == "requesting_escalation",
|
AISession.status == "requesting_escalation",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user