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:
@@ -6,8 +6,8 @@ Exposes the MCP client and server config model for other plugins.
|
||||
from __future__ import annotations
|
||||
|
||||
from app.plugins.builtins.contracts import get_contract_registry
|
||||
from app.plugins.builtins.mcp_client.models import McpServerConfig
|
||||
from app.plugins.builtins.mcp_client.client import McpClient
|
||||
from app.plugins.builtins.mcp_client.models import McpServerConfig
|
||||
from app.plugins.builtins.mcp_client.schemas import (
|
||||
McpServerExecuteRequest,
|
||||
McpServerExecuteResponse,
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, String, Text
|
||||
from sqlalchemy import Boolean, DateTime, Index, String, Text
|
||||
from sqlalchemy.dialects.postgresql import UUID as PGUUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
@@ -32,5 +32,5 @@ class McpServerConfig(Base, TenantMixin, OwnedMixin):
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
last_connected_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
created_by: Mapped[uuid.UUID | None] = mapped_column(PGUUID(as_uuid=True), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.now(UTC), nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=datetime.now(UTC), onupdate=datetime.now(UTC), nullable=False)
|
||||
|
||||
@@ -29,11 +29,15 @@ class McpClientPlugin(BasePlugin):
|
||||
"mcp-client:write",
|
||||
"mcp-client:admin",
|
||||
],
|
||||
|
||||
|
||||
author="LeoCRM Team",
|
||||
min_app_version="1.0.0",
|
||||
contract_version="1.0.0")
|
||||
|
||||
def get_entity_models(self) -> dict[str, type]:
|
||||
from app.plugins.builtins.mcp_client.models import McpServerConfig
|
||||
return {"mcp_server_config": McpServerConfig}
|
||||
|
||||
async def on_deactivate(
|
||||
self, db, service_container, event_bus
|
||||
) -> None:
|
||||
|
||||
@@ -7,13 +7,13 @@ import uuid
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy import select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.db import get_db
|
||||
from app.core.visibility import apply_visibility_filter
|
||||
from app.deps import get_current_user, require_permission
|
||||
from app.deps import require_permission
|
||||
from app.plugins.builtins.mcp_client.client import McpClient
|
||||
from app.plugins.builtins.mcp_client.models import McpServerConfig as McpServerConfigModel
|
||||
from app.plugins.builtins.mcp_client.schemas import (
|
||||
@@ -97,7 +97,7 @@ async def update_mcp_server(
|
||||
try:
|
||||
sid = uuid.UUID(server_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"})
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"}) from None
|
||||
|
||||
stmt = select(McpServerConfigModel).where(
|
||||
McpServerConfigModel.id == sid,
|
||||
@@ -127,7 +127,7 @@ async def delete_mcp_server(
|
||||
try:
|
||||
sid = uuid.UUID(server_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"})
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"}) from None
|
||||
|
||||
stmt = select(McpServerConfigModel).where(
|
||||
McpServerConfigModel.id == sid,
|
||||
@@ -152,7 +152,7 @@ async def list_server_tools(
|
||||
try:
|
||||
sid = uuid.UUID(server_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"})
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"}) from None
|
||||
|
||||
stmt = select(McpServerConfigModel).where(
|
||||
McpServerConfigModel.id == sid,
|
||||
@@ -176,7 +176,7 @@ async def list_server_tools(
|
||||
return tools_resp
|
||||
except Exception as exc:
|
||||
logger.exception("Failed to list tools from MCP server %s", cfg.name)
|
||||
raise HTTPException(502, detail={"detail": f"Failed to connect: {exc}", "code": "connection_failed"})
|
||||
raise HTTPException(502, detail={"detail": f"Failed to connect: {exc}", "code": "connection_failed"}) from exc
|
||||
|
||||
|
||||
@router.post("/servers/{server_id}/execute", response_model=McpServerExecuteResponse)
|
||||
@@ -190,7 +190,7 @@ async def execute_server_tool(
|
||||
try:
|
||||
sid = uuid.UUID(server_id)
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"})
|
||||
raise HTTPException(400, detail={"detail": "Invalid server_id", "code": "invalid_id"}) from None
|
||||
|
||||
stmt = select(McpServerConfigModel).where(
|
||||
McpServerConfigModel.id == sid,
|
||||
|
||||
Reference in New Issue
Block a user