feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -2,11 +2,17 @@
|
||||
backend/app/models/shipping_audit_event.py
|
||||
|
||||
用途:定义货代领域统一、仅追加的审计事件。
|
||||
依赖:SQLAlchemy Base、货代 Run/Task/Intake/会话 PDF 工作项的稳定业务编号。
|
||||
依赖:SQLAlchemy Base;Workflow / Run / Task / Intake 等稳定业务编号(软引用)。
|
||||
逻辑:各业务服务通过 audit_service 追加事件;事件不依赖可级联删除的业务外键,保留跨生命周期追溯事实。
|
||||
进度审计阶段扩展 operation_id、对象关联、白名单前后快照、证据引用、结果与保留到期时间;
|
||||
会话工作项阶段追加 owner_user_id、session_item_id 与脱敏 client_ip_hash/user_agent_hash;
|
||||
Workflow 阶段以 workflow_id / workflow_item_id / workflow_item_version_id 软引用批次与 PDF 项,
|
||||
并写入 previous_event_hash / event_hash 哈希链与 diff_json;另含 owner_user_id 与脱敏
|
||||
client_ip_hash/user_agent_hash;
|
||||
项次派生阶段使用 LINE_DERIVATION_AUDIT_EVENT_TYPES(FIELD_DERIVED / LINE_NO_OVERRIDDEN /
|
||||
DERIVATION_SIMULATED / EXPORT_GENERATED 等),元数据仅存脱敏摘要与规则校验和;
|
||||
禁止存储 PDF/邮件正文、模型原文、对象存储 URL、原始 IP/UA 或密钥。
|
||||
ORM before_update/before_delete 拒绝改删;PostgreSQL 另有 append-only 触发器
|
||||
(迁移 a0e1f2b3c4d5);到期清理须 set_config('hxops.shipping_audit_purge','1')。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -45,7 +51,9 @@ class ShippingAuditEvent(Base):
|
||||
Index('ix_shipping_audit_events_actor_created', 'actor_type', 'actor_id', 'created_at'),
|
||||
Index('ix_shipping_audit_events_event_type_created', 'event_type', 'created_at'),
|
||||
Index('ix_shipping_audit_events_retention_expires', 'retention_expires_at', 'id'),
|
||||
Index('ix_shipping_audit_events_session_item_created', 'session_item_id', 'created_at'),
|
||||
Index('ix_shipping_audit_events_workflow_created', 'workflow_id', 'created_at'),
|
||||
Index('ix_shipping_audit_events_workflow_item_created', 'workflow_item_id', 'created_at'),
|
||||
Index('ix_shipping_audit_events_event_hash', 'event_hash'),
|
||||
Index('ix_shipping_audit_events_owner_created', 'owner_user_id', 'created_at'),
|
||||
)
|
||||
|
||||
@@ -59,6 +67,8 @@ class ShippingAuditEvent(Base):
|
||||
actor_type: Mapped[str] = mapped_column(String(16), nullable=False, default='system', server_default='system')
|
||||
actor_id: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
actor_role: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
# 操作者展示名(可选);与 actor_id 并存,禁止写入敏感联系方式。
|
||||
actor_display: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
request_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
operation_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
correlation_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
@@ -69,8 +79,11 @@ class ShippingAuditEvent(Base):
|
||||
unit_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
document_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
review_case_no: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
# 会话 PDF 工作项稳定编号(item_no);软引用,避免级联删除抹除审计。
|
||||
session_item_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
# Workflow 软引用:workflow_no / item_no / version id(字符串),避免级联删除抹除审计。
|
||||
workflow_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
workflow_item_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
workflow_item_version_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
version_no: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
# 业务属主(非操作者);代操作场景与 actor_id 区分。
|
||||
owner_user_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
# 仅存哈希,禁止写入原始 IP / User-Agent。
|
||||
@@ -84,6 +97,12 @@ class ShippingAuditEvent(Base):
|
||||
after_hash: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
before_snapshot_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
|
||||
after_snapshot_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
|
||||
# 白名单前后快照差异;与哈希链一并支撑离线校验。
|
||||
diff_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
|
||||
previous_event_hash: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
event_hash: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
# 敏感等级:normal | sensitive;用于查询脱敏与访问审计分级。
|
||||
sensitivity_level: Mapped[str | None] = mapped_column(String(16), nullable=True)
|
||||
evidence_refs_json: Mapped[Optional[list[dict[str, Any]]]] = mapped_column(JSON, nullable=True)
|
||||
artifact_refs_json: Mapped[Optional[list[dict[str, Any]]]] = mapped_column(JSON, nullable=True)
|
||||
context_refs_json: Mapped[Optional[dict[str, Any]]] = mapped_column(JSON, nullable=True)
|
||||
|
||||
Reference in new issue
Block a user