fix(security): 多租户隔离全量修复 security-fix multi-tenant (OpenCode审查P0)
- bot_bridge 18数据端点全部 entity_id 隔离(Depends(get_entity_id)/body),/ping /risk-levels 豁免 - alert_rules 11端点 entity_id 隔离 + KPIAlert/DynamicThresholdCache 写入 entity_id - reports 17端点隔离 + generate_report 写 ReportHistory.entity_id + history 按 entity 过滤 - ai_analysis 移除硬编码默认key,改 _require_deepseek_key() 强制 env 缺失 503 - budget auto-decompose 硬编码 entity_id==1 改请求 entity - kpis update_kpi 加 UPDATE_KPI_WHITELIST 白名单(status/important_flag 不可越权改) - data_quality 收敛:删 MySQL JSON 版 _run_rule_checks,check-governance 复用 _run_governance_checks(SQLite 兼容) - _eval_threshold invert 参数修复(>=↔< 等取反),red 分支不传 invert 保持行为 - 新增 test_security_multitenant.py 13条(bot_bridge/alert_rules/reports 隔离 + invert + SQLite governance) - models 6表加 entity_id 列;生产库已 ALTER + 按真实归属回填(kpi_alerts 472行中216行属entity≠1)
This commit is contained in:
@@ -183,6 +183,7 @@ def auto_decompose_budget(
|
||||
data: dict,
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(require_auth),
|
||||
entity_id: int = Depends(get_entity_id),
|
||||
):
|
||||
"""自动分解年度预算到月度(均分或按历史权重)
|
||||
支持两种模式:
|
||||
@@ -199,7 +200,7 @@ def auto_decompose_budget(
|
||||
if not kpi_id:
|
||||
# 只取年度行(period=YYYY-00)作为年度总额,避免把月度行也加进来导致滚雪球(非幂等bug修复)
|
||||
year_budget_rows = db.query(BudgetPlan).filter(
|
||||
BudgetPlan.entity_id == 1,
|
||||
BudgetPlan.entity_id == entity_id,
|
||||
BudgetPlan.budget_year == year,
|
||||
BudgetPlan.period == f"{year}-00",
|
||||
BudgetPlan.status == "active",
|
||||
@@ -259,7 +260,7 @@ def auto_decompose_budget(
|
||||
existing.updated_at = datetime.now()
|
||||
else:
|
||||
db.add(BudgetPlan(
|
||||
entity_id=1,
|
||||
entity_id=entity_id,
|
||||
kpi_id=kid,
|
||||
period=period,
|
||||
budget_value=monthly_value,
|
||||
|
||||
Reference in New Issue
Block a user