pub async fn team_creation_target(
db: &Db,
ambient: Option<League>,
pending_invite: Option<i64>,
pending_league: Option<i64>,
user: &User,
) -> Result<Option<(League, Option<i64>)>, AppError>Expand description
Resolve where user may create a team, and the invite consumed by doing
so (None invite for the site admin’s commissioner bootstrap). The single
source of truth for team-creation authorization, shared by the bootstrap
guard and the TeamCreator extractor.
The admin creates in the league they just created (pending_league,
session-carried), else the ambient (resolved) league. A non-admin creates
in the league of the invite they accepted (pending_invite,
session-carried, ignored when no longer active for their email), else
their most recent active invite. Someone who already has a team in the
target league gets Ok(None), as does a non-admin with no active invite.