feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -3,9 +3,9 @@ services/shipping_notice/fulfillment_audit.py
|
||||
|
||||
用途:履约关键节点与敏感访问写入统一审计事件的轻量封装。
|
||||
依赖:audit_service.append_shipping_audit_event、Flask g.request_id / request、AppError。
|
||||
逻辑:由 candidate / decision / fulfillment_workflow / workspace 读取与导出 / 工作项写路径调用;
|
||||
逻辑:由 candidate / decision / fulfillment_workflow / workspace 读取与导出 / Workflow 写路径调用;
|
||||
默认 strict=True,审计写入失败时抛错,禁止业务成功而审计缺失;访问审计逐次留痕;
|
||||
自动附带 request_id 与客户端 IP/UA(仅哈希入库)。
|
||||
自动附带 request_id 与客户端 IP/UA(仅哈希入库);透传 Workflow 软引用字段。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -74,26 +74,34 @@ def record_fulfillment_audit(
|
||||
document_id: str | int | None = None,
|
||||
review_case_no: str | None = None,
|
||||
conversation_id: str | None = None,
|
||||
session_item_id: str | None = None,
|
||||
workflow_id: str | None = None,
|
||||
workflow_item_id: str | None = None,
|
||||
workflow_item_version_id: str | None = None,
|
||||
version_no: int | None = None,
|
||||
owner_user_id: str | int | None = None,
|
||||
reason_code: str | None = None,
|
||||
reason: str | None = None,
|
||||
result: str = 'success',
|
||||
error_code: str | None = None,
|
||||
before: dict[str, Any] | None = None,
|
||||
after: dict[str, Any] | None = None,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
source: str = 'api',
|
||||
strict: bool = True,
|
||||
sensitivity_level: str | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
追加履约审计。
|
||||
|
||||
核心逻辑:默认与业务同事务写入;strict=True 时失败抛错,保证必须留存;
|
||||
自动附带 request_id 与客户端 IP/UA 哈希。
|
||||
自动附带 request_id 与客户端 IP/UA 哈希;透传 Workflow 软引用。
|
||||
|
||||
Args:
|
||||
event_type/action: 稳定事件与动作码。
|
||||
workflow_id/workflow_item_id/workflow_item_version_id/version_no: Workflow 软引用。
|
||||
before/after: 必须已是白名单可投影的状态摘要。
|
||||
error_code: 拒绝/失败时的稳定业务错误码。
|
||||
sensitivity_level: 可选敏感分级(如 sensitive),透传审计表。
|
||||
strict: True 时审计失败阻断调用方;False 时仅记日志(仅限显式降级场景)。
|
||||
"""
|
||||
request_id = _request_id()
|
||||
@@ -113,17 +121,22 @@ def record_fulfillment_audit(
|
||||
document_id=document_id,
|
||||
review_case_no=review_case_no,
|
||||
conversation_id=conversation_id,
|
||||
session_item_id=session_item_id,
|
||||
workflow_id=workflow_id,
|
||||
workflow_item_id=workflow_item_id,
|
||||
workflow_item_version_id=workflow_item_version_id,
|
||||
version_no=version_no,
|
||||
owner_user_id=owner_user_id,
|
||||
client_ip=client_ip,
|
||||
user_agent=user_agent,
|
||||
reason_code=reason_code,
|
||||
reason=reason,
|
||||
result=result,
|
||||
error_code=error_code,
|
||||
before=before,
|
||||
after=after,
|
||||
metadata=metadata or {},
|
||||
source=source,
|
||||
sensitivity_level=sensitivity_level,
|
||||
)
|
||||
except Exception as exc:
|
||||
_LOGGER.exception('fulfillment audit append failed event_type=%s aggregate_id=%s', event_type, aggregate_id)
|
||||
@@ -147,7 +160,10 @@ def record_access_audit(
|
||||
document_id: str | int | None = None,
|
||||
review_case_no: str | None = None,
|
||||
conversation_id: str | None = None,
|
||||
session_item_id: str | None = None,
|
||||
workflow_id: str | None = None,
|
||||
workflow_item_id: str | None = None,
|
||||
workflow_item_version_id: str | None = None,
|
||||
version_no: int | None = None,
|
||||
owner_user_id: str | int | None = None,
|
||||
metadata: dict[str, Any] | None = None,
|
||||
strict: bool = True,
|
||||
@@ -179,7 +195,10 @@ def record_access_audit(
|
||||
document_id=document_id,
|
||||
review_case_no=review_case_no,
|
||||
conversation_id=conversation_id,
|
||||
session_item_id=session_item_id,
|
||||
workflow_id=workflow_id,
|
||||
workflow_item_id=workflow_item_id,
|
||||
workflow_item_version_id=workflow_item_version_id,
|
||||
version_no=version_no,
|
||||
owner_user_id=owner_user_id,
|
||||
client_ip=client_ip,
|
||||
user_agent=user_agent,
|
||||
@@ -187,6 +206,7 @@ def record_access_audit(
|
||||
metadata=metadata or {'access': True},
|
||||
source='api',
|
||||
persist_snapshots=False,
|
||||
sensitivity_level='sensitive',
|
||||
)
|
||||
db.session.commit()
|
||||
return True
|
||||
|
||||
Reference in new issue
Block a user