A1: Permission-Checks fuer delegations, policies, permission_templates, ai_copilot
This commit is contained in:
@@ -8,7 +8,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query, status
|
|||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.core.db import get_db
|
from app.core.db import get_db
|
||||||
from app.deps import get_current_user
|
from app.deps import get_current_user, require_permission
|
||||||
from app.schemas.ai_copilot import (
|
from app.schemas.ai_copilot import (
|
||||||
CopilotExecuteRequest,
|
CopilotExecuteRequest,
|
||||||
CopilotQueryRequest,
|
CopilotQueryRequest,
|
||||||
@@ -22,7 +22,7 @@ router = APIRouter(prefix="/api/v1/ai/copilot", tags=["ai-copilot"])
|
|||||||
async def copilot_query(
|
async def copilot_query(
|
||||||
body: CopilotQueryRequest,
|
body: CopilotQueryRequest,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("ai:write")),
|
||||||
):
|
):
|
||||||
"""Process a natural language query and return proposed actions.
|
"""Process a natural language query and return proposed actions.
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ async def copilot_query(
|
|||||||
async def copilot_execute(
|
async def copilot_execute(
|
||||||
body: CopilotExecuteRequest,
|
body: CopilotExecuteRequest,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("ai:write")),
|
||||||
):
|
):
|
||||||
"""Execute a proposed action after user confirmation.
|
"""Execute a proposed action after user confirmation.
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ async def copilot_history(
|
|||||||
page: int = Query(1, ge=1),
|
page: int = Query(1, ge=1),
|
||||||
page_size: int = Query(20, ge=1, le=100),
|
page_size: int = Query(20, ge=1, le=100),
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("ai:read")),
|
||||||
):
|
):
|
||||||
"""Get paginated conversation history for the current user."""
|
"""Get paginated conversation history for the current user."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from fastapi import APIRouter, Depends, HTTPException, Query, status
|
|||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.core.db import get_db
|
from app.core.db import get_db
|
||||||
from app.deps import get_current_user
|
from app.deps import get_current_user, require_permission
|
||||||
from app.schemas.delegation import DelegationCreate, DelegationUpdate
|
from app.schemas.delegation import DelegationCreate, DelegationUpdate
|
||||||
from app.services import delegation_service
|
from app.services import delegation_service
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ router = APIRouter(prefix="/api/v1/delegations", tags=["delegations"])
|
|||||||
async def list_delegations(
|
async def list_delegations(
|
||||||
direction: str = Query("all", pattern="^(from|to|all)$"),
|
direction: str = Query("all", pattern="^(from|to|all)$"),
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:delegations:read")),
|
||||||
):
|
):
|
||||||
"""List delegations for the current user."""
|
"""List delegations for the current user."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -33,7 +33,7 @@ async def list_delegations(
|
|||||||
async def create_delegation(
|
async def create_delegation(
|
||||||
body: DelegationCreate,
|
body: DelegationCreate,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:delegations:write")),
|
||||||
):
|
):
|
||||||
"""Create a new permission delegation."""
|
"""Create a new permission delegation."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -57,7 +57,7 @@ async def update_delegation(
|
|||||||
delegation_id: str,
|
delegation_id: str,
|
||||||
body: DelegationUpdate,
|
body: DelegationUpdate,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:delegations:write")),
|
||||||
):
|
):
|
||||||
"""Update an existing delegation."""
|
"""Update an existing delegation."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -79,7 +79,7 @@ async def update_delegation(
|
|||||||
async def delete_delegation(
|
async def delete_delegation(
|
||||||
delegation_id: str,
|
delegation_id: str,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:delegations:write")),
|
||||||
):
|
):
|
||||||
"""Delete a delegation."""
|
"""Delete a delegation."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -92,7 +92,7 @@ async def delete_delegation(
|
|||||||
@router.get("/active")
|
@router.get("/active")
|
||||||
async def check_active_delegation(
|
async def check_active_delegation(
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:delegations:read")),
|
||||||
):
|
):
|
||||||
"""Check if the current user has any active delegations."""
|
"""Check if the current user has any active delegations."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
|||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.core.db import get_db
|
from app.core.db import get_db
|
||||||
from app.deps import get_current_user
|
from app.deps import get_current_user, require_permission
|
||||||
from app.schemas.permission_template import (
|
from app.schemas.permission_template import (
|
||||||
PermissionTemplateCreate,
|
PermissionTemplateCreate,
|
||||||
PermissionTemplateUpdate,
|
PermissionTemplateUpdate,
|
||||||
@@ -23,7 +23,7 @@ router = APIRouter(prefix="/api/v1/permission-templates", tags=["permission-temp
|
|||||||
async def list_templates(
|
async def list_templates(
|
||||||
entity_type: str | None = None,
|
entity_type: str | None = None,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:templates:read")),
|
||||||
):
|
):
|
||||||
"""List all permission templates for the current tenant."""
|
"""List all permission templates for the current tenant."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -35,7 +35,7 @@ async def list_templates(
|
|||||||
async def create_template(
|
async def create_template(
|
||||||
body: PermissionTemplateCreate,
|
body: PermissionTemplateCreate,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||||
):
|
):
|
||||||
"""Create a new permission template."""
|
"""Create a new permission template."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -58,7 +58,7 @@ async def update_template(
|
|||||||
template_id: str,
|
template_id: str,
|
||||||
body: PermissionTemplateUpdate,
|
body: PermissionTemplateUpdate,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||||
):
|
):
|
||||||
"""Update an existing permission template."""
|
"""Update an existing permission template."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -81,7 +81,7 @@ async def update_template(
|
|||||||
async def delete_template(
|
async def delete_template(
|
||||||
template_id: str,
|
template_id: str,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||||
):
|
):
|
||||||
"""Delete a permission template."""
|
"""Delete a permission template."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -95,7 +95,7 @@ async def delete_template(
|
|||||||
async def apply_template(
|
async def apply_template(
|
||||||
body: PermissionTemplateApply,
|
body: PermissionTemplateApply,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:templates:write")),
|
||||||
):
|
):
|
||||||
"""Apply a permission template to an entity, creating entity_permissions."""
|
"""Apply a permission template to an entity, creating entity_permissions."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
|||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
from app.core.db import get_db
|
from app.core.db import get_db
|
||||||
from app.deps import get_current_user
|
from app.deps import get_current_user, require_permission
|
||||||
from app.schemas.policy import PolicyCreate, PolicyUpdate
|
from app.schemas.policy import PolicyCreate, PolicyUpdate
|
||||||
from app.services import policy_service
|
from app.services import policy_service
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ router = APIRouter(prefix="/api/v1/policies", tags=["policies"])
|
|||||||
async def list_policies(
|
async def list_policies(
|
||||||
entity_type: str,
|
entity_type: str,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:policies:read")),
|
||||||
):
|
):
|
||||||
"""List all ABAC policies for a given entity type."""
|
"""List all ABAC policies for a given entity type."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -34,7 +34,7 @@ async def list_policies(
|
|||||||
async def create_policy(
|
async def create_policy(
|
||||||
body: PolicyCreate,
|
body: PolicyCreate,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:policies:write")),
|
||||||
):
|
):
|
||||||
"""Create a new ABAC policy."""
|
"""Create a new ABAC policy."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -59,7 +59,7 @@ async def update_policy(
|
|||||||
policy_id: str,
|
policy_id: str,
|
||||||
body: PolicyUpdate,
|
body: PolicyUpdate,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:policies:write")),
|
||||||
):
|
):
|
||||||
"""Update an existing ABAC policy."""
|
"""Update an existing ABAC policy."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
@@ -85,7 +85,7 @@ async def update_policy(
|
|||||||
async def delete_policy(
|
async def delete_policy(
|
||||||
policy_id: str,
|
policy_id: str,
|
||||||
db: AsyncSession = Depends(get_db),
|
db: AsyncSession = Depends(get_db),
|
||||||
current_user: dict = Depends(get_current_user),
|
current_user: dict = Depends(require_permission("permissions:policies:write")),
|
||||||
):
|
):
|
||||||
"""Delete an ABAC policy."""
|
"""Delete an ABAC policy."""
|
||||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||||
|
|||||||
Reference in New Issue
Block a user