Spaces:
Running on T4
Running on T4
File size: 757 Bytes
ae2c68f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | """Whether the player's analysis consent allows running an analysis."""
from uuid import UUID
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.modules.settings.models import ConsentEvent
async def analysis_consent_blocked(db: AsyncSession, account_id: UUID, require_accepted: bool) -> bool:
"""True when the latest analysis consent is a withdrawal, or (when required) there is no acceptance."""
action = await db.scalar(
select(ConsentEvent.action)
.where(ConsentEvent.account_id == account_id, ConsentEvent.category == "analysis")
.order_by(ConsentEvent.created_at.desc(), ConsentEvent.id.desc()).limit(1))
return action == "withdrawn" or (require_accepted and action is None)
|