feat: phase 2 - migrate all route guards to require_permission (75 guards, 21 files)

This commit is contained in:
Agent Zero
2026-07-15 22:35:50 +02:00
parent 8ca6dfee88
commit 08fd3ab72c
18 changed files with 132 additions and 265 deletions
+5 -30
View File
@@ -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.sequence import SequenceCreate, SequenceUpdate
from app.services import sequence_service
@@ -19,17 +18,11 @@ router = APIRouter(prefix="/api/v1/sequences", tags=["sequences"])
@router.get("")
async def list_sequences(
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user),
current_user: dict = Depends(require_permission("sequences:read")),
):
"""List all sequences for the current tenant. Admin only."""
tenant_id = uuid.UUID(current_user["tenant_id"])
role = current_user.get("role", "viewer")
if not check_permission(role, "settings", "read"):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail={"detail": "Insufficient permissions", "code": "forbidden"},
)
return await sequence_service.list_sequences(db, tenant_id)
@@ -38,18 +31,12 @@ async def list_sequences(
async def create_sequence(
body: SequenceCreate,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user),
current_user: dict = Depends(require_permission("sequences:write")),
):
"""Create a new sequence. Admin only."""
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 sequence_service.create_sequence(db, tenant_id, user_id, data)
@@ -60,18 +47,12 @@ async def update_sequence(
sequence_id: str,
body: SequenceUpdate,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user),
current_user: dict = Depends(require_permission("sequences:write")),
):
"""Update a sequence (name, prefix, padding only). Admin only."""
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:
sid = uuid.UUID(sequence_id)
@@ -89,18 +70,12 @@ async def update_sequence(
async def delete_sequence(
sequence_id: str,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user),
current_user: dict = Depends(require_permission("sequences:write")),
):
"""Delete a sequence (soft-delete). Admin only."""
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:
sid = uuid.UUID(sequence_id)