页面嵌套修改
This commit is contained in:
1 parent
213dd841b5
commit
4450f342d8
38 files changed
+2020
-309
No files matched your search
@@ -26,6 +26,9 @@ from deerflow.runtime.user_context import get_effective_user_id
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter(prefix="/api/business-mapping", tags=["business-mapping"])
|
||||
|
||||
_EIGHTBF_BUSINESS_CODE = "8BF"
|
||||
_EIGHTBF_MANAGER_USERNAME = "lqq"
|
||||
|
||||
|
||||
# ── schemas ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -70,6 +73,20 @@ def _is_admin(request: Request) -> bool:
|
||||
return user is None or getattr(user, "system_role", None) == "admin"
|
||||
|
||||
|
||||
def _username_of(request: Request) -> str:
|
||||
"""Read the trusted login account name, not an externally supplied username."""
|
||||
user = getattr(request.state, "user", None)
|
||||
email = str(getattr(user, "email", "") or "")
|
||||
return email.split("@", 1)[0].strip().lower()
|
||||
|
||||
|
||||
def _can_update_mapping(request: Request, business_code: str) -> bool:
|
||||
"""8BF's public chain is maintained exclusively by the lqq account."""
|
||||
if business_code.strip().upper() == _EIGHTBF_BUSINESS_CODE:
|
||||
return _username_of(request) == _EIGHTBF_MANAGER_USERNAME
|
||||
return _is_admin(request)
|
||||
|
||||
|
||||
def _current_user_id(request: Request) -> str:
|
||||
user = getattr(request.state, "user", None)
|
||||
if user is not None:
|
||||
@@ -119,17 +136,14 @@ async def _validate_public_chain_mapping(
|
||||
async def list_mappings(request: Request) -> BusinessMappingListResponse:
|
||||
store = _get_store(request)
|
||||
rows = await store.list_mappings()
|
||||
return BusinessMappingListResponse(
|
||||
mappings=[BusinessMappingResponse(**r) for r in rows]
|
||||
)
|
||||
return BusinessMappingListResponse(mappings=[BusinessMappingResponse(**r) for r in rows])
|
||||
|
||||
|
||||
@router.put("/{business_code}", response_model=BusinessMappingResponse)
|
||||
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")
|
||||
async def update_mapping(request: Request, business_code: str, body: BusinessMappingUpdateRequest) -> BusinessMappingResponse:
|
||||
if not _can_update_mapping(request, business_code):
|
||||
detail = "Only the lqq account can update the 8BF business mapping" if business_code.strip().upper() == _EIGHTBF_BUSINESS_CODE else "Only administrators can update business mappings"
|
||||
raise HTTPException(status_code=403, detail=detail)
|
||||
store = _get_store(request)
|
||||
# Only forward fields the caller explicitly sent (distinguish omitted vs null).
|
||||
fields = body.model_dump(exclude_unset=True)
|
||||
|
||||
Reference in new issue
Block a user