feat(shipping-notice): 增强发货通知与审计功能,支持敏感数据控制与哈希链校验
- 更新发货通知工具 API,剥离不可信的操作人身份字段,确保审计安全 - 引入审计事件的哈希链校验机制,支持数据完整性验证 - 增强订单抽取与审计功能,支持敏感快照的访问控制 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 完善文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
95cdfe66b0
commit
d0fe084999
225 files changed
+25923
-6653
No files matched your search
@@ -0,0 +1,80 @@
|
||||
"""
|
||||
tests/test_shipping_cancelled_task_readonly.py
|
||||
|
||||
用途:验收建单后取消将 Task 置 pending_void、Excel/Version 只读,禁止物理删除。
|
||||
依赖:freight_cancellation_service、workflow_ledger_service、_seed_run_input。
|
||||
逻辑:断言 lifecycle、void_reason、version.is_readonly、审计 before/after、文件路径保留。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app import db
|
||||
from app.models import ShippingTask
|
||||
from app.models.shipping_notice_workflow import ShippingNoticeWorkflowItemVersion
|
||||
from app.services.shipping_notice.freight_cancellation_service import mark_cancelled_task_readonly
|
||||
from app.services.shipping_notice.workflow_ledger_service import (
|
||||
ensure_open_workflow,
|
||||
ensure_workflow_item_for_document,
|
||||
)
|
||||
from tests.test_shipping_order_extraction_runs import _seed_run_input
|
||||
|
||||
|
||||
def test_mark_cancelled_task_readonly_sets_pending_void_without_delete(app):
|
||||
"""取消后 Task 为 pending_void,导出路径保留,Version 只读。"""
|
||||
with app.app_context():
|
||||
user, agent, session, _intake, document = _seed_run_input(suffix='CANCEL-RO')
|
||||
workflow = ensure_open_workflow(
|
||||
conversation_id=session.session_id,
|
||||
owner_user_id=int(user.id),
|
||||
owner_agent_id=int(agent.id),
|
||||
)
|
||||
item = ensure_workflow_item_for_document(
|
||||
workflow=workflow,
|
||||
conversation_id=session.session_id,
|
||||
owner_user_id=int(user.id),
|
||||
document_id=int(document.id),
|
||||
)
|
||||
task = ShippingTask(
|
||||
task_no='SN-CANCEL-RO-1',
|
||||
user_id=int(user.id),
|
||||
conversation_id=session.session_id,
|
||||
process_status='waiting_upload',
|
||||
lifecycle_status='active',
|
||||
export_file_path='/tmp/keep-excel.xlsx',
|
||||
export_file_name='keep-excel.xlsx',
|
||||
source_type='review_confirmation',
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
item.current_task_no = task.task_no
|
||||
version = (
|
||||
ShippingNoticeWorkflowItemVersion.query
|
||||
.filter_by(workflow_item_id=int(item.id), is_current=True)
|
||||
.first()
|
||||
)
|
||||
assert version is not None
|
||||
version.task_id = int(task.id)
|
||||
version.task_no = task.task_no
|
||||
version.excel_artifact_no = 'ART-1'
|
||||
version.is_readonly = False
|
||||
db.session.commit()
|
||||
|
||||
result = mark_cancelled_task_readonly(
|
||||
task=task,
|
||||
actor_id=int(user.id),
|
||||
reason='user cancelled after excel',
|
||||
workflow_item_no=item.item_no,
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
# 关键断言:软作废 + 文件保留 + Version 只读。
|
||||
assert task.lifecycle_status == 'pending_void'
|
||||
assert task.void_reason == 'user cancelled after excel'
|
||||
assert task.export_file_path == '/tmp/keep-excel.xlsx'
|
||||
assert result['physical_delete'] is False
|
||||
assert result['readonly'] is True
|
||||
assert result['before']['lifecycle_status'] == 'active'
|
||||
assert result['after']['lifecycle_status'] == 'pending_void'
|
||||
refreshed = db.session.get(ShippingNoticeWorkflowItemVersion, int(version.id))
|
||||
assert refreshed is not None
|
||||
assert refreshed.is_readonly is True
|
||||
Reference in new issue
Block a user