Files
platforms/frontend/platform_admin/scripts/check-staff-relation-policy.mjs
czl231 6bcde94388 功能:完善用户服务关系展示与组织联动
统一平台、气站和配送点后台的服务关系业务名称展示。
新增气站、配送点、服务人员三级联动及暂未分配语义。
后端补充组织归属、人员角色和启用状态的严格校验。
补充前后端测试、项目文档、操作日志及本机日志忽略规则。
2026-08-12 00:37:58 +08:00

128 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 功能:验证工作人员关联字段过滤、资质来源校验和路由上下文传递契约。
* 版本v1.1.0
*/
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { transformWithOxc } from 'vite';
const policyURL = new URL(
'../src/api/resource-staff-relation.ts',
import.meta.url,
);
const source = await readFile(policyURL, 'utf8');
const transformed = await transformWithOxc(source, policyURL.pathname);
const moduleURL = `data:text/javascript;base64,${Buffer.from(transformed.code).toString('base64')}`;
const {
credentialOwnerValidationMessage,
resolveCredentialStaffRole,
staffRelationFilters,
staffRoleFromReturnPath,
} = await import(moduleURL);
assert.deepEqual(
staffRelationFilters(
{
relation: '/staff_account',
staffRelation: {
roles: ['delivery'],
enabledOnly: true,
workStatus: 'on_duty',
},
},
{},
),
{ role_code: 'delivery', status: '1', work_status: 'on_duty' },
'订单分配必须只查询启用且在岗的配送人员',
);
assert.deepEqual(
staffRelationFilters(
{
relation: '/staff_account',
staffRelation: {
roles: ['installer', 'delivery', 'operations'],
enabledOnly: true,
},
},
{},
),
{ role_codes: 'installer,delivery,operations', status: '1' },
'用户服务关系必须查询全部角色中的启用人员',
);
assert.deepEqual(
staffRelationFilters(
{
relation: '/staff_account',
staffRelation: { roles: 'context' },
},
{ staffType: 'installer' },
),
{ role_code: 'installer' },
'人员资质必须继承当前工作人员菜单角色',
);
assert.throws(
() => staffRelationFilters({ relation: '/staff_account' }, {}),
/缺少显式过滤策略/,
'未声明策略的工作人员关系必须立即失败',
);
assert.equal(
staffRoleFromReturnPath(
'/staff/credential?return_to=%2Fstaff%2Foperations%3Fpage%3D2',
),
'operations',
'返回路径必须能回退解析工作人员角色',
);
assert.equal(
resolveCredentialStaffRole(
'installer',
'/staff/credential?staff_type=delivery',
).error,
'工作人员角色与来源菜单不一致',
);
assert.equal(
credentialOwnerValidationMessage('staff-a', 'installer', {
identity: 'staff-a',
role_code: 'delivery',
status: 1,
}),
'工作人员角色已变化,请从当前角色菜单重新进入',
);
const resourcesSource = await readFile(
new URL('../src/api/resources.ts', import.meta.url),
'utf8',
);
assert.match(resourcesSource, /organizationScoped: true/);
assert.equal(
(resourcesSource.match(/staffRelation:/g) ?? []).length,
3,
'三个工作人员关联场景都必须显式声明策略',
);
const relationsSource = await readFile(
new URL('../src/views/resource/use-resource-relations.ts', import.meta.url),
'utf8',
);
assert.doesNotMatch(
relationsSource,
/resource === ['"]\/staff_account['"].*delivery/,
'关系加载器不得恢复全局配送人员特例',
);
const listSource = await readFile(
new URL('../src/views/shared/CrudListPage.vue', import.meta.url),
'utf8',
);
assert.match(listSource, /staff_type: staffType\.value/);
const listSearchSource = await readFile(
new URL('../src/views/shared/use-resource-list-search.ts', import.meta.url),
'utf8',
);
assert.match(listSearchSource, /'staff_type'/);
console.log('工作人员关联与资质上下文检查通过');