870b51d054
- 接入平台与企业角色权限,按权限展示菜单、页面及操作。 - 企业成员排行按需加载,翻页沿用同一榜单快照,保留连续名次与前三名样式。 - 更新消费日志的费用明细、超管指标和官方价格汇率设置,补齐翻译与回归测试。
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
normalizeView,
|
|
checkPerm,
|
|
checkAnyPerm,
|
|
buildMenuTree,
|
|
} from './permLogic.js';
|
|
|
|
const view = normalizeView({
|
|
perms: ['org.member', 'org.member.query'],
|
|
enforced_modules: ['member'],
|
|
module_of: {
|
|
'org.member': 'member',
|
|
'org.member.query': 'member',
|
|
'org.member.edit': 'member',
|
|
'org.dept.query': 'dept',
|
|
},
|
|
});
|
|
|
|
test('enforced module follows perms, ignoring the legacy check', () => {
|
|
assert.equal(checkPerm(view, 'org.member.query', false), true);
|
|
assert.equal(checkPerm(view, 'org.member.edit', true), false);
|
|
});
|
|
|
|
test('non-enforced module follows the legacy check', () => {
|
|
assert.equal(checkPerm(view, 'org.dept.query', true), true);
|
|
assert.equal(
|
|
checkPerm(view, 'org.dept.query', () => false),
|
|
false,
|
|
);
|
|
assert.equal(checkPerm(view, 'org.dept.query'), false);
|
|
});
|
|
|
|
test('view not loaded yet', () => {
|
|
assert.equal(checkPerm(null, 'org.member.query'), false);
|
|
assert.equal(checkPerm(null, 'org.member.query', true), true);
|
|
});
|
|
|
|
test('any of several perms', () => {
|
|
assert.equal(
|
|
checkAnyPerm(view, ['org.member.edit', 'org.member.query']),
|
|
true,
|
|
);
|
|
assert.equal(checkAnyPerm(view, ['org.member.edit']), false);
|
|
});
|
|
|
|
test('menu tree keeps visible nodes ordered by sort', () => {
|
|
const tree = buildMenuTree([
|
|
{ code: 'b', parent: '', sort: 20, visible: true },
|
|
{ code: 'a', parent: '', sort: 10, visible: true },
|
|
{ code: 'a.x', parent: 'a', sort: 10, visible: true },
|
|
{ code: 'a.h', parent: 'a', sort: 5, visible: false },
|
|
]);
|
|
assert.deepEqual(
|
|
tree.map((n) => n.code),
|
|
['a', 'b'],
|
|
);
|
|
assert.deepEqual(
|
|
tree[0].children.map((n) => n.code),
|
|
['a.x'],
|
|
);
|
|
});
|