"""Shared "who is a real, active, non-suspended human" predicate. Used wherever a user must be filtered out of a directory / recipient list or rejected as a target: the messaging directory AND the download share-by-email / recipient-picker endpoints. Kept in one place so the two forms (SQL clauses for a query, Python check for a loaded row) can't drift apart, and so a route module doesn't have to import another route module just to reuse the rule. """ from app.models import User def messageable_clauses() -> list: """SQL clauses for "a real, active, non-suspended human" — splat into a directory/recipient query.""" return [ User.is_demo.is_(False), User.is_active.is_(True), User.is_suspended.is_(False), ] def is_messageable_user(u: User | None) -> bool: """Python mirror of `messageable_clauses()` for an already-loaded row (WS auth, send recipient).""" return bool(u and not u.is_demo and u.is_active and not u.is_suspended)