feat(shipping-notice): 增强订单抽取功能,添加进度事件和诊断运行管理,优化数据模型和访问控制

This commit is contained in:
hugo committed 2026-07-21 23:17:29 +08:00
1 parent ce26d6d0c4
commit c4095b08da
175 files changed
+13064 -1814

No files matched your search

@@ -6,7 +6,7 @@ tests/services/admin/test_permission_service.py
import pytest
from app import db
from app.core.errors import NotFoundError, ValidationError
from app.core.errors import ForbiddenError, NotFoundError, ValidationError
from app.models import Agent, PermissionRequest, User
from app.services.admin import permission_service
@@ -50,6 +50,31 @@ def test_batch_update_permissions_no_users(app):
permission_service.batch_update_permissions({'user_ids': [], 'agent_ids': [1]})
@pytest.mark.parametrize('operation', ['single', 'batch'])
def test_internal_executor_cannot_be_assigned_to_user(app, operation):
"""授权服务必须在所有写入口拒绝 internal 执行器。"""
with app.app_context():
executor = Agent(
name='internal-executor', type='api', dify_app_id='wf-internal', dify_api_key='key',
dify_app_type='workflow', runtime_provider='dify', exposure_mode='internal',
)
user = User(username=f'internal-{operation}', email=f'internal-{operation}@example.com', role='user')
db.session.add_all([executor, user])
db.session.commit()
with pytest.raises(ValidationError) as caught:
if operation == 'single':
permission_service.update_user_permissions(user.id, {'agent_ids': [executor.id]})
else:
permission_service.batch_update_permissions({
'user_ids': [user.id], 'agent_ids': [executor.id], 'action': 'add',
})
assert caught.value.code == 'AGENT.INTERNAL_EXECUTOR_USER_ACCESS_FORBIDDEN'
db.session.refresh(user)
assert executor not in user.agents
def test_permission_request_approve(app, monkeypatch):
with app.app_context():
agent = Agent(name='req-agent', type='api', dify_app_id='app-r', dify_api_key='key-r')
@@ -77,3 +102,25 @@ def test_permission_request_not_found(app):
with app.app_context():
with pytest.raises(NotFoundError):
permission_service.approve_permission_request(99999)
def test_internal_executor_permission_request_cannot_be_approved(app):
"""历史或伪造的内部执行器权限申请不得转化为用户授权。"""
with app.app_context():
executor = Agent(
name='request-executor', type='api', dify_app_id='wf-request', dify_api_key='key',
dify_app_type='workflow', runtime_provider='dify', exposure_mode='internal',
)
user = User(username='request-internal', email='request-internal@example.com', role='user')
db.session.add_all([executor, user])
db.session.flush()
req = PermissionRequest(user_id=user.id, agent_id=executor.id, reason='invalid', status='pending')
db.session.add(req)
db.session.commit()
with pytest.raises(ForbiddenError) as caught:
permission_service.approve_permission_request(req.id)
assert getattr(caught.value, 'code', None) == 'AGENT.INTERNAL_EXECUTOR_USER_ACCESS_FORBIDDEN'
db.session.refresh(user)
assert executor not in user.agents