You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
688 B
Python
17 lines
688 B
Python
# backend/app/auth/scope.py — per-user 쿼리 스코프 헬퍼 (전 라우터 공용)
|
|
from fastapi import HTTPException
|
|
|
|
|
|
def scoped(stmt, model, user_id: str):
|
|
"""user_id 컬럼이 있는 모델 쿼리에 소유자 필터 강제. 없으면(공유 마스터) 그대로."""
|
|
if hasattr(model, "user_id"):
|
|
return stmt.where(model.user_id == user_id)
|
|
return stmt
|
|
|
|
|
|
def owned_or_404(obj, user_id: str):
|
|
"""단건 조회 시 소유자 검증. 타인 데이터면 404(존재 자체를 숨김 — IDOR 방어)."""
|
|
if obj is None or (hasattr(obj, "user_id") and obj.user_id != user_id):
|
|
raise HTTPException(status_code=404, detail="not found")
|
|
return obj
|