feat: phase 2 - migrate all route guards to require_permission (75 guards, 21 files)
This commit is contained in:
+5
-24
@@ -7,9 +7,8 @@ import uuid
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.auth import check_permission
|
||||
from app.core.db import get_db
|
||||
from app.deps import get_current_user
|
||||
from app.deps import require_permission
|
||||
from app.schemas.tax import TaxRateCreate, TaxRateUpdate
|
||||
from app.services import tax_service
|
||||
|
||||
@@ -19,7 +18,7 @@ router = APIRouter(prefix="/api/v1/taxes", tags=["taxes"])
|
||||
@router.get("")
|
||||
async def list_tax_rates(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
current_user: dict = Depends(require_permission("taxes:read")),
|
||||
):
|
||||
"""List all tax rates for the current tenant."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
@@ -30,18 +29,12 @@ async def list_tax_rates(
|
||||
async def create_tax_rate(
|
||||
body: TaxRateCreate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
current_user: dict = Depends(require_permission("taxes:write")),
|
||||
):
|
||||
"""Create a tax rate. Requires admin permission."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
user_id = uuid.UUID(current_user["user_id"])
|
||||
role = current_user.get("role", "viewer")
|
||||
|
||||
if not check_permission(role, "settings", "create"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail={"detail": "Insufficient permissions", "code": "forbidden"},
|
||||
)
|
||||
|
||||
data = body.model_dump()
|
||||
return await tax_service.create_tax_rate(db, tenant_id, user_id, data)
|
||||
@@ -52,18 +45,12 @@ async def update_tax_rate(
|
||||
tax_id: str,
|
||||
body: TaxRateUpdate,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
current_user: dict = Depends(require_permission("taxes:write")),
|
||||
):
|
||||
"""Update a tax rate. Requires admin permission."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
user_id = uuid.UUID(current_user["user_id"])
|
||||
role = current_user.get("role", "viewer")
|
||||
|
||||
if not check_permission(role, "settings", "update"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail={"detail": "Insufficient permissions", "code": "forbidden"},
|
||||
)
|
||||
|
||||
try:
|
||||
tid = uuid.UUID(tax_id)
|
||||
@@ -81,18 +68,12 @@ async def update_tax_rate(
|
||||
async def delete_tax_rate(
|
||||
tax_id: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
current_user: dict = Depends(require_permission("taxes:write")),
|
||||
):
|
||||
"""Delete a tax rate. Requires admin permission."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
user_id = uuid.UUID(current_user["user_id"])
|
||||
role = current_user.get("role", "viewer")
|
||||
|
||||
if not check_permission(role, "settings", "delete"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail={"detail": "Insufficient permissions", "code": "forbidden"},
|
||||
)
|
||||
|
||||
try:
|
||||
tid = uuid.UUID(tax_id)
|
||||
|
||||
Reference in New Issue
Block a user