fix(audit): P0-P3 audit fixes — 838 ruff errors → 0, 30 F821 bugs fixed, 118 files changed
- P0: hooks.py 3-tuple fix, trigger_dispatcher Contract, contacts/plugin unregister_actions_by_owner - P0: 5 test files — check_permission mocks removed, hardcoded DB credential → env var - P1: attachment_service DmsFile via Contract helper, restore_registry/history_hooks dedup - P1: mail/plugin restore unregister, mcp_client datetime.now(UTC), saved_views/filters patterns - P1: ProtectedRoute fail-closed, 13 test assertion fixes (bcrypt, DB-URLs, SECRET_KEYs) - P2: deprecated notifications → post_system_message (3 files), forgejo Base, report_generator lazy import - P2: webhooks permissions, deps.py/roles.py plugin perms removed, import_export default - P2: address/tags/entity_links patterns removed, worker.py Contract-Umgehungen fixed - P2: 28 frontend TODOs (hardcoded constants, deprecated notification API) - P3: dead code, duplicates, deprecated imports, private attr, __import__ inline - P3: 8 frontend TODOs (LucideIcons, inline styles, XSS, i18n) - ruff: 838 → 0 (612 auto-fix + 246 manual + 27 F821 regression fix) - F821: 30 → 0 (AutomationDefinition, DmsFile, user_id, Path, Any, String) - Contract-Umgehungen: 2 neue gefunden (worker.py:169, worker.py:280) und gefixt
This commit is contained in:
@@ -7,13 +7,13 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
from datetime import UTC
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.db import get_db, set_tenant_context
|
||||
from app.core.visibility import apply_visibility_filter
|
||||
from app.core.db import get_db
|
||||
from app.deps import get_current_user, require_permission
|
||||
from app.plugins.builtins.automation.models import (
|
||||
AutomationDefinition,
|
||||
@@ -253,9 +253,10 @@ async def get_automation_settings(
|
||||
):
|
||||
"""Get automation settings (persisted in system_settings metadata)."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
from app.models.system_settings import SystemSettings
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.models.system_settings import SystemSettings
|
||||
|
||||
result = await db.execute(
|
||||
select(SystemSettings).where(SystemSettings.tenant_id == tenant_id)
|
||||
)
|
||||
@@ -285,9 +286,9 @@ async def update_automation_settings(
|
||||
):
|
||||
"""Update automation settings (persisted in system_settings metadata)."""
|
||||
tenant_id = uuid.UUID(current_user["tenant_id"])
|
||||
from app.models.system_settings import SystemSettings
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
from app.models.system_settings import SystemSettings
|
||||
|
||||
result = await db.execute(
|
||||
select(SystemSettings).where(SystemSettings.tenant_id == tenant_id)
|
||||
@@ -345,7 +346,7 @@ async def get_automation(
|
||||
try:
|
||||
aid = uuid.UUID(automation_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID") from None
|
||||
|
||||
automation = await AutomationService.get_by_id(db, tenant_id, aid)
|
||||
if automation is None:
|
||||
@@ -370,7 +371,7 @@ async def update_automation(
|
||||
try:
|
||||
aid = uuid.UUID(automation_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID") from None
|
||||
|
||||
automation = await AutomationService.update(
|
||||
db, tenant_id, aid, data.model_dump(exclude_none=True), user_id=user_id
|
||||
@@ -394,7 +395,7 @@ async def delete_automation(
|
||||
try:
|
||||
aid = uuid.UUID(automation_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID") from None
|
||||
|
||||
success = await AutomationService.delete(db, tenant_id, aid)
|
||||
if not success:
|
||||
@@ -419,7 +420,7 @@ async def execute_automation(
|
||||
try:
|
||||
aid = uuid.UUID(automation_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID") from None
|
||||
|
||||
automation = await AutomationService.get_by_id(db, tenant_id, aid)
|
||||
if automation is None:
|
||||
@@ -441,7 +442,6 @@ async def execute_automation(
|
||||
await db.flush()
|
||||
|
||||
# Execute automation via execution engine
|
||||
import asyncio
|
||||
from app.plugins.builtins.automation.execution_engine import run_automation
|
||||
|
||||
run_id = str(run.id)
|
||||
@@ -456,9 +456,10 @@ async def execute_automation(
|
||||
)
|
||||
|
||||
# Update run with results
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import update as sa_update
|
||||
from datetime import datetime, timezone
|
||||
now = datetime.now(timezone.utc)
|
||||
now = datetime.now(UTC)
|
||||
async with db.begin():
|
||||
await db.execute(
|
||||
sa_update(AutomationRun)
|
||||
@@ -489,14 +490,16 @@ async def dry_run_automation(
|
||||
try:
|
||||
aid = uuid.UUID(automation_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID") from None
|
||||
|
||||
automation = await AutomationService.get_by_id(db, tenant_id, aid)
|
||||
if automation is None:
|
||||
raise HTTPException(status_code=404, detail="Automation not found")
|
||||
|
||||
# Execute dry-run via execution engine
|
||||
from app.plugins.builtins.automation.execution_engine import run_automation as execute_automation_engine
|
||||
from app.plugins.builtins.automation.execution_engine import (
|
||||
run_automation as execute_automation_engine,
|
||||
)
|
||||
|
||||
result = await execute_automation_engine(
|
||||
ctx={},
|
||||
@@ -558,7 +561,7 @@ async def list_automation_runs(
|
||||
try:
|
||||
aid = uuid.UUID(automation_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID") from None
|
||||
|
||||
items, total = await RunLogService.list_automation_runs(
|
||||
db, tenant_id, automation_id=aid, status=status, limit=limit, offset=offset
|
||||
@@ -589,7 +592,7 @@ async def list_automation_versions(
|
||||
try:
|
||||
aid = uuid.UUID(automation_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid automation ID") from None
|
||||
|
||||
items, total = await AutomationService.get_versions(
|
||||
db, tenant_id, aid, limit=limit, offset=offset
|
||||
@@ -618,7 +621,7 @@ async def restore_automation_version(
|
||||
aid = uuid.UUID(automation_id)
|
||||
vid = uuid.UUID(version_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid ID") from None
|
||||
|
||||
automation = await AutomationService.restore_version(
|
||||
db, tenant_id, aid, vid, user_id=user_id
|
||||
@@ -653,7 +656,7 @@ async def list_subtasks(
|
||||
parent_id = uuid.UUID(parent_agent_id) if parent_agent_id else None
|
||||
child_id = uuid.UUID(child_agent_id) if child_agent_id else None
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid agent ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid agent ID") from None
|
||||
|
||||
from app.plugins.builtins.automation.agent_coordinator import AgentCoordinator
|
||||
|
||||
@@ -688,7 +691,7 @@ async def create_subtask(
|
||||
parent_id = uuid.UUID(data.parent_agent_id)
|
||||
child_id = uuid.UUID(data.child_agent_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid agent ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid agent ID") from None
|
||||
|
||||
from app.plugins.builtins.automation.agent_coordinator import AgentCoordinator
|
||||
|
||||
@@ -718,10 +721,11 @@ async def get_subtask(
|
||||
try:
|
||||
sid = uuid.UUID(subtask_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID") from None
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.plugins.builtins.automation.models import AgentSubtask
|
||||
from sqlalchemy import select
|
||||
|
||||
result = await db.execute(
|
||||
select(AgentSubtask)
|
||||
@@ -751,10 +755,11 @@ async def update_subtask(
|
||||
try:
|
||||
sid = uuid.UUID(subtask_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID") from None
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.plugins.builtins.automation.models import AgentSubtask
|
||||
from sqlalchemy import select
|
||||
|
||||
result = await db.execute(
|
||||
select(AgentSubtask)
|
||||
@@ -795,7 +800,7 @@ async def cancel_subtask(
|
||||
try:
|
||||
sid = uuid.UUID(subtask_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID") from None
|
||||
|
||||
from app.plugins.builtins.automation.agent_coordinator import AgentCoordinator
|
||||
|
||||
@@ -823,7 +828,7 @@ async def wait_for_subtask(
|
||||
try:
|
||||
sid = uuid.UUID(subtask_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID")
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID") from None
|
||||
|
||||
from app.plugins.builtins.automation.agent_coordinator import AgentCoordinator
|
||||
|
||||
@@ -845,7 +850,7 @@ async def aggregate_subtasks(
|
||||
try:
|
||||
ids = [uuid.UUID(sid) for sid in subtask_ids]
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID in list")
|
||||
raise HTTPException(status_code=400, detail="Invalid subtask ID in list") from None
|
||||
|
||||
from app.plugins.builtins.automation.agent_coordinator import AgentCoordinator
|
||||
|
||||
|
||||
Reference in New Issue
Block a user