fix(agent-assets): allow admin access to platform rules

This commit is contained in:
caoxiaozhu
2026-07-20 10:30:22 +08:00
parent 74fafc86d3
commit 140efd1a2a
4 changed files with 92 additions and 3 deletions

View File

@@ -693,6 +693,9 @@ def test_platform_spreadsheet_onlyoffice_requires_platform_admin_to_edit(monkeyp
admin_callback_token = parse_qs(
urlsplit(admin_config.config["editorConfig"]["callbackUrl"]).query
)["access_token"][0]
admin_content_token = parse_qs(
urlsplit(admin_config.config["document"]["url"]).query
)["access_token"][0]
finance_session = service.validate_rule_spreadsheet_access_token(
rule.id,
finance_callback_token,
@@ -708,6 +711,33 @@ def test_platform_spreadsheet_onlyoffice_requires_platform_admin_to_edit(monkeyp
assert admin_session.tenant_id == "platform"
assert admin_session.resource_scope == "platform"
assert admin_session.actor == "username:platform_admin"
content_session = service.validate_rule_spreadsheet_access_token(
rule.id,
admin_content_token,
)
onlyoffice_service = AgentAssetService(
db,
current_user=CurrentUserContext(
username=content_session.actor,
name="ONLYOFFICE",
role_codes=["manager"],
is_admin=True,
tenant_id=content_session.tenant_id,
),
)
content_path, content_type, content_name = (
onlyoffice_service.get_rule_spreadsheet_content(
rule.id,
validated_session=content_session,
)
)
assert content_path.exists()
assert content_type == (
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
assert content_name.endswith(".xlsx")
with pytest.raises(AgentAssetOnlyOfficeSecurityError, match="不匹配"):
service.validate_rule_spreadsheet_access_token(
"different-asset",