feat: 新增8BF多智能体会商页面
This commit is contained in:
1 parent
239b798c5d
commit
1ab3329f6d
10 files changed
+552
-13
No files matched your search
@@ -21,6 +21,8 @@ from datetime import datetime
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from deerflow.runtime.user_context import get_effective_user_id
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter(prefix="/api/business-mapping", tags=["business-mapping"])
|
||||
|
||||
@@ -62,6 +64,54 @@ def _get_store(request: Request):
|
||||
return store
|
||||
|
||||
|
||||
def _is_admin(request: Request) -> bool:
|
||||
"""Treat no-auth deployments as the single administrative workspace."""
|
||||
user = getattr(request.state, "user", None)
|
||||
return user is None or getattr(user, "system_role", None) == "admin"
|
||||
|
||||
|
||||
def _current_user_id(request: Request) -> str:
|
||||
user = getattr(request.state, "user", None)
|
||||
if user is not None:
|
||||
return str(user.id)
|
||||
return get_effective_user_id()
|
||||
|
||||
|
||||
async def _validate_public_chain_mapping(
|
||||
request: Request,
|
||||
fields: dict[str, object],
|
||||
) -> None:
|
||||
"""Require globally mapped chains to remain readable by every account."""
|
||||
if "chain_id" not in fields:
|
||||
return
|
||||
|
||||
raw_chain_id = fields["chain_id"]
|
||||
chain_id = raw_chain_id.strip() if isinstance(raw_chain_id, str) else ""
|
||||
if not chain_id:
|
||||
fields["chain_id"] = None
|
||||
fields["chain_title"] = None
|
||||
return
|
||||
|
||||
chain_store = getattr(request.app.state, "roundtable_chain_store", None)
|
||||
if chain_store is None:
|
||||
raise HTTPException(status_code=503, detail="Business chain store not available")
|
||||
|
||||
chain = await chain_store.get_chain(
|
||||
chain_id,
|
||||
_current_user_id(request),
|
||||
is_admin=True,
|
||||
)
|
||||
if chain is None:
|
||||
raise HTTPException(status_code=400, detail="Business chain not found")
|
||||
if not chain.get("is_public"):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Global business mappings require a public business chain",
|
||||
)
|
||||
fields["chain_id"] = chain_id
|
||||
fields["chain_title"] = str(chain.get("title") or "") or None
|
||||
|
||||
|
||||
# ── routes ───────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -78,9 +128,12 @@ async def list_mappings(request: Request) -> BusinessMappingListResponse:
|
||||
async def update_mapping(
|
||||
request: Request, business_code: str, body: BusinessMappingUpdateRequest
|
||||
) -> BusinessMappingResponse:
|
||||
if not _is_admin(request):
|
||||
raise HTTPException(status_code=403, detail="Only administrators can update business mappings")
|
||||
store = _get_store(request)
|
||||
# Only forward fields the caller explicitly sent (distinguish omitted vs null).
|
||||
fields = body.model_dump(exclude_unset=True)
|
||||
await _validate_public_chain_mapping(request, fields)
|
||||
row = await store.update_mapping(business_code, **fields)
|
||||
if row is None:
|
||||
raise HTTPException(status_code=404, detail="Business mapping not found")
|
||||
|
||||
Reference in new issue
Block a user