TT-007.1: establish module-owned authorization boundary
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Authentication dependencies for platform integration."""
|
||||
|
||||
from typing import List
|
||||
from fastapi import Depends, HTTPException, status
|
||||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -114,3 +115,28 @@ def require_role(role_name: str):
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=f"Role '{role_name}' required")
|
||||
return user
|
||||
return _check_role
|
||||
|
||||
|
||||
def require_permission(permission_id: str):
|
||||
"""Dependency factory: require a specific permission.
|
||||
|
||||
Authorization decision is made LOCALLY by Module.
|
||||
Module is the authority for its own permissions.
|
||||
|
||||
Uses the single Module authorization engine from permissions.py.
|
||||
"""
|
||||
from request_app.api.v1.routes.permissions import compute_effective_policy
|
||||
|
||||
def _check_permission(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> User:
|
||||
# Use the single Module authorization engine
|
||||
user_permissions = set(compute_effective_policy(current_user))
|
||||
|
||||
if permission_id not in user_permissions:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail=f"Permission '{permission_id}' required",
|
||||
)
|
||||
return current_user
|
||||
return _check_permission
|
||||
|
||||
Reference in New Issue
Block a user