2026-03-03 13:31:07 -07:00
|
|
|
"""Access control helpers for actor-type checks."""
|
2026-02-09 15:49:50 +05:30
|
|
|
|
2026-02-04 02:28:51 +05:30
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-02-09 15:49:50 +05:30
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
2026-02-04 02:28:51 +05:30
|
|
|
from fastapi import HTTPException, status
|
|
|
|
|
|
2026-02-09 15:49:50 +05:30
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from app.core.auth import AuthContext
|
2026-02-04 02:28:51 +05:30
|
|
|
|
|
|
|
|
|
2026-03-03 13:31:07 -07:00
|
|
|
def require_user_actor(auth: AuthContext) -> None:
|
|
|
|
|
"""Raise HTTP 403 unless the authenticated actor is a human user (not an agent).
|
|
|
|
|
|
|
|
|
|
NOTE: This is an actor-type check, NOT a privilege/role check.
|
|
|
|
|
For admin privilege enforcement, use ``require_org_admin`` (organization-level)
|
|
|
|
|
or check ``user.is_super_admin`` (global-level).
|
|
|
|
|
"""
|
2026-02-04 02:28:51 +05:30
|
|
|
if auth.actor_type != "user" or auth.user is None:
|
|
|
|
|
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
|