openyida 2026.8.19-2 → 2026.8.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/core/query-data.js
CHANGED
|
@@ -18,6 +18,7 @@ const { CliError } = require('./cli-error');
|
|
|
18
18
|
const { createAuthRef, createYidaClient, isAuthRefReady } = require('./yida-client');
|
|
19
19
|
|
|
20
20
|
const { buildComponentAliasMaps } = require('../app/get-schema');
|
|
21
|
+
const { getProcessCodeFromFormBinding } = require('../app/services/form-mode-service');
|
|
21
22
|
|
|
22
23
|
const USAGE = `openyida data - Unified Yida data CLI
|
|
23
24
|
|
|
@@ -25,6 +26,7 @@ Usage:
|
|
|
25
26
|
openyida data query form <appType> <formUuid> [--page N] [--size N] [--all] [--max-pages N] [--search-json JSON|--search-file .cache/openyida/search.json] [--resolve-aliases] [--inst-id ID] [--no-hydrate-subforms]
|
|
26
27
|
openyida data get form <appType> --inst-id <formInstId> [--form-uuid <formUuid>] [--no-hydrate-subforms]
|
|
27
28
|
openyida data create form <appType> <formUuid> (--data-json <JSON>|--data-file .cache/openyida/data.json) [--dept-id ID] [--resolve-aliases]
|
|
29
|
+
说明:若目标表单为流程表单,会自动使用 /v1/process/startInstance.json 发起流程。
|
|
28
30
|
openyida data update form <appType> --inst-id <formInstId> (--data-json <JSON>|--data-file .cache/openyida/data.json) [--form-uuid <formUuid>] [--use-latest-version y] [--resolve-aliases]
|
|
29
31
|
openyida data query subform <appType> <formUuid> --inst-id <formInstId> --table-field-id <fieldId|alias> [--page N] [--size N] [--resolve-aliases]
|
|
30
32
|
|
|
@@ -592,6 +594,15 @@ async function getForm(positionals, options, session) {
|
|
|
592
594
|
}));
|
|
593
595
|
}
|
|
594
596
|
|
|
597
|
+
async function resolveProcessCode(session, appType, formUuid) {
|
|
598
|
+
try {
|
|
599
|
+
return await getProcessCodeFromFormBinding(session, appType, formUuid);
|
|
600
|
+
} catch (err) {
|
|
601
|
+
console.warn(`⚠️ 无法判断表单 ${formUuid} 是否为流程表单,将使用 saveFormData 提交:${err.message}`);
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
595
606
|
async function createForm(positionals, options, session) {
|
|
596
607
|
requirePositionals(positionals, 2, ['appType', 'formUuid']);
|
|
597
608
|
const dataJson = requireJsonOption(options, 'data_json', 'data_file', '数据');
|
|
@@ -603,6 +614,16 @@ async function createForm(positionals, options, session) {
|
|
|
603
614
|
formDataJson: translateJsonWithAliases(dataJson, aliasContext, translateFormDataObject),
|
|
604
615
|
};
|
|
605
616
|
if (options.dept_id) {params.deptId = options.dept_id;}
|
|
617
|
+
|
|
618
|
+
const processCode = await resolveProcessCode(session, appType, formUuid);
|
|
619
|
+
if (processCode) {
|
|
620
|
+
printResult(await sendPost(session, appType, `/dingtalk/web/${appType}/v1/process/startInstance.json`, {
|
|
621
|
+
...params,
|
|
622
|
+
processCode,
|
|
623
|
+
}));
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
|
|
606
627
|
printResult(await sendPost(session, appType, `/dingtalk/web/${appType}/v1/form/saveFormData.json`, params));
|
|
607
628
|
}
|
|
608
629
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* matrix-service.js - 宜搭权限矩阵查询服务
|
|
3
|
+
*
|
|
4
|
+
* 提供权限矩阵列表查询与单个矩阵详情查询,供 save-permission 等命令使用。
|
|
5
|
+
*/
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const { createAuthRef, createYidaClient } = require('../core/yida-client');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 查询权限矩阵列表
|
|
12
|
+
*
|
|
13
|
+
* @param {object} authRef - 认证引用对象
|
|
14
|
+
* @param {object} options - 查询选项
|
|
15
|
+
* @param {string} [options.keyword] - 搜索关键词
|
|
16
|
+
* @param {number} [options.page=1] - 页码
|
|
17
|
+
* @param {number} [options.limit=10] - 每页条数
|
|
18
|
+
* @returns {Promise<Array>} 权限矩阵列表
|
|
19
|
+
*/
|
|
20
|
+
async function getMatrixList(authRef, options = {}) {
|
|
21
|
+
const ref = authRef || createAuthRef();
|
|
22
|
+
const { keyword = '', page = 1, limit = 10 } = options;
|
|
23
|
+
const client = createYidaClient({ authRef: ref });
|
|
24
|
+
const result = await client.getContent('/query/matrix/getMatrixList.json', {
|
|
25
|
+
keyword,
|
|
26
|
+
page,
|
|
27
|
+
limit,
|
|
28
|
+
}, {
|
|
29
|
+
action: 'getMatrixList',
|
|
30
|
+
failMessage: '获取权限矩阵列表失败',
|
|
31
|
+
});
|
|
32
|
+
return (result && result.data) || [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 根据 ID 查询单个权限矩阵详情
|
|
37
|
+
*
|
|
38
|
+
* @param {object} authRef - 认证引用对象
|
|
39
|
+
* @param {string} matrixId - 权限矩阵 ID
|
|
40
|
+
* @returns {Promise<object>} 权限矩阵详情
|
|
41
|
+
*/
|
|
42
|
+
async function getMatrixById(authRef, matrixId) {
|
|
43
|
+
const ref = authRef || createAuthRef();
|
|
44
|
+
const client = createYidaClient({ authRef: ref });
|
|
45
|
+
return client.getContent('/query/matrix/getMatrixById.json', {
|
|
46
|
+
matrixId,
|
|
47
|
+
}, {
|
|
48
|
+
action: 'getMatrixById',
|
|
49
|
+
failMessage: `获取权限矩阵 ${matrixId} 详情失败`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = {
|
|
54
|
+
getMatrixList,
|
|
55
|
+
getMatrixById,
|
|
56
|
+
};
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* openyida save-permission <appType> <formUuid> --action-permission <json>
|
|
7
7
|
* openyida save-permission <appType> <formUuid> --field-permission <json>
|
|
8
8
|
* openyida save-permission <appType> <formUuid> --members <userIds> --data-permission <json>
|
|
9
|
+
* openyida save-permission <appType> <formUuid> --matrix <json> --data-permission <json>
|
|
9
10
|
*
|
|
10
11
|
* 用法(新增权限组):
|
|
11
12
|
* openyida save-permission <appType> <formUuid> --create --name <权限组名称> [--members <userIds>] [--data-permission <json>] [--action-permission <json>] [--field-permission <json>]
|
|
@@ -13,6 +14,9 @@
|
|
|
13
14
|
* --members 参数:指定权限组成员,多个钉钉 userId 用逗号分隔
|
|
14
15
|
* 示例:--members "54255850977641,12345678901234"
|
|
15
16
|
* 不传则保持原有成员配置不变(更新模式)或仅包含管理员(新增模式)
|
|
17
|
+
* --all-members 参数:新增/更新权限组时设置为「全员可见」(roleType=DEFAULT, roleValue=ALL)
|
|
18
|
+
* --matrix 参数:使用权限矩阵作为权限成员,JSON 格式 {"matrixId":"MATRIX-XXX","columnId":"column_YYY"}
|
|
19
|
+
* 与 --members / --all-members 互斥
|
|
16
20
|
*
|
|
17
21
|
* 注意:--field-permission 透传宜搭 fieldPermit 原始 JSON,使用前建议先通过 get-permission 查看现有结构。
|
|
18
22
|
*/
|
|
@@ -39,6 +43,7 @@ const DATA_RANGE_TO_PERMIT_TYPE = {
|
|
|
39
43
|
FREE_LOGIN: 'FREE_LOGIN',
|
|
40
44
|
CUSTOM_DEPARTMENT: 'CUSTOM_DEPARTMENT',
|
|
41
45
|
FORMULA: 'FORMULA',
|
|
46
|
+
MATRIX: 'MATRIX',
|
|
42
47
|
};
|
|
43
48
|
|
|
44
49
|
// 所有支持的操作权限 key
|
|
@@ -62,9 +67,11 @@ const VALID_OPERATE_KEYS = [
|
|
|
62
67
|
function parseArgs(args) {
|
|
63
68
|
if (args.length < 2) {
|
|
64
69
|
throw new CliError([
|
|
65
|
-
'用法: openyida save-permission <appType> <formUuid> [--create --name <名称>] [--data-permission <json>] [--action-permission <json>] [--field-permission <json>] [--members <userIds>]',
|
|
70
|
+
'用法: openyida save-permission <appType> <formUuid> [--create --name <名称>] [--data-permission <json>] [--action-permission <json>] [--field-permission <json>] [--members <userIds>] [--all-members] [--matrix <json>]',
|
|
66
71
|
'示例(更新): openyida save-permission APP_XXX FORM-XXX --data-permission \'{"role":"DEFAULT","dataRange":"SELF"}\'',
|
|
67
|
-
'
|
|
72
|
+
'示例(新增全员): openyida save-permission APP_XXX FORM-XXX --create --name "全部人员看全部数据" --all-members --data-permission \'{"dataRange":"ALL"}\'',
|
|
73
|
+
'示例(新增指定人员): openyida save-permission APP_XXX FORM-XXX --create --name "只读权限组" --members "54255850977641"',
|
|
74
|
+
'示例(新增矩阵): openyida save-permission APP_XXX FORM-XXX --create --name "矩阵权限组" --matrix \'{"matrixId":"MATRIX-XXX","columnId":"column_YYY"}\' --data-permission \'{"rule":[{"type":"ORIGINATOR","value":"y"},{"type":"MATRIX","value":"y"}]}\'',
|
|
68
75
|
].join('\n'), {
|
|
69
76
|
code: 'SAVE_PERMISSION_INVALID_ARGUMENTS',
|
|
70
77
|
});
|
|
@@ -76,6 +83,8 @@ function parseArgs(args) {
|
|
|
76
83
|
let actionPermission = null;
|
|
77
84
|
let fieldPermission = null;
|
|
78
85
|
let members = null;
|
|
86
|
+
let allMembers = false;
|
|
87
|
+
let matrix = null;
|
|
79
88
|
let createMode = false;
|
|
80
89
|
let groupName = null;
|
|
81
90
|
|
|
@@ -116,6 +125,17 @@ function parseArgs(args) {
|
|
|
116
125
|
// 多个钉钉 userId 用逗号分隔,如 "54255850977641,12345678901234"
|
|
117
126
|
members = args[index + 1].split(',').map((id) => id.trim()).filter(Boolean);
|
|
118
127
|
index++;
|
|
128
|
+
} else if (args[index] === '--all-members') {
|
|
129
|
+
allMembers = true;
|
|
130
|
+
} else if (args[index] === '--matrix' && args[index + 1]) {
|
|
131
|
+
try {
|
|
132
|
+
matrix = JSON.parse(args[index + 1]);
|
|
133
|
+
} catch {
|
|
134
|
+
throw new CliError(`--matrix 参数 JSON 解析失败: ${args[index + 1]},格式: {"matrixId":"MATRIX-XXX","columnId":"column_YYY"}`, {
|
|
135
|
+
code: 'SAVE_PERMISSION_INVALID_ARGUMENTS',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
index++;
|
|
119
139
|
}
|
|
120
140
|
}
|
|
121
141
|
|
|
@@ -125,16 +145,39 @@ function parseArgs(args) {
|
|
|
125
145
|
});
|
|
126
146
|
}
|
|
127
147
|
|
|
128
|
-
if (!createMode && !dataPermission && !actionPermission && !fieldPermission && !members) {
|
|
129
|
-
throw new CliError('请至少提供 --data-permission、--action-permission、--field-permission 或 --
|
|
148
|
+
if (!createMode && !dataPermission && !actionPermission && !fieldPermission && !members && !matrix) {
|
|
149
|
+
throw new CliError('请至少提供 --data-permission、--action-permission、--field-permission、--members 或 --matrix 参数之一', {
|
|
130
150
|
code: 'SAVE_PERMISSION_INVALID_ARGUMENTS',
|
|
131
151
|
});
|
|
132
152
|
}
|
|
133
153
|
|
|
134
|
-
return { appType, formUuid, dataPermission, actionPermission, fieldPermission, members, createMode, groupName };
|
|
154
|
+
return { appType, formUuid, dataPermission, actionPermission, fieldPermission, members, allMembers, matrix, createMode, groupName };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function buildDataPermit(dataPermission) {
|
|
158
|
+
if (dataPermission && Array.isArray(dataPermission.rule)) {
|
|
159
|
+
return JSON.stringify(dataPermission);
|
|
160
|
+
}
|
|
161
|
+
const dataRange = (dataPermission && dataPermission.dataRange) || 'ALL';
|
|
162
|
+
const permitType = DATA_RANGE_TO_PERMIT_TYPE[dataRange] || dataRange;
|
|
163
|
+
return JSON.stringify({ rule: [{ type: permitType, value: 'y' }] });
|
|
135
164
|
}
|
|
136
165
|
|
|
137
166
|
function validateDataPermission(dataPermission) {
|
|
167
|
+
if (dataPermission && Array.isArray(dataPermission.rule)) {
|
|
168
|
+
const validTypes = new Set([
|
|
169
|
+
...Object.keys(DATA_RANGE_TO_PERMIT_TYPE),
|
|
170
|
+
...Object.values(DATA_RANGE_TO_PERMIT_TYPE),
|
|
171
|
+
]);
|
|
172
|
+
for (const item of dataPermission.rule) {
|
|
173
|
+
if (item.type && !validTypes.has(item.type)) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
`无效的 rule type: ${item.type},有效值: ${Array.from(validTypes).join(', ')}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
138
181
|
const validRanges = Object.keys(DATA_RANGE_TO_PERMIT_TYPE);
|
|
139
182
|
if (dataPermission.dataRange && !validRanges.includes(dataPermission.dataRange)) {
|
|
140
183
|
throw new Error(
|
|
@@ -143,6 +186,18 @@ function validateDataPermission(dataPermission) {
|
|
|
143
186
|
}
|
|
144
187
|
}
|
|
145
188
|
|
|
189
|
+
function validateMatrix(matrix) {
|
|
190
|
+
if (!matrix || typeof matrix !== 'object') {
|
|
191
|
+
throw new Error('--matrix 参数必须是 JSON 对象');
|
|
192
|
+
}
|
|
193
|
+
if (!matrix.matrixId || typeof matrix.matrixId !== 'string') {
|
|
194
|
+
throw new Error('--matrix 参数必须包含 matrixId 字符串');
|
|
195
|
+
}
|
|
196
|
+
if (!matrix.columnId || typeof matrix.columnId !== 'string') {
|
|
197
|
+
throw new Error('--matrix 参数必须包含 columnId 字符串');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
146
201
|
function validateActionPermission(actionPermission) {
|
|
147
202
|
if (!actionPermission.operations || typeof actionPermission.operations !== 'object') {
|
|
148
203
|
throw new Error(
|
|
@@ -280,7 +335,7 @@ function savePermitPackage(appType, formUuid, permitPackage, overrideMembers, au
|
|
|
280
335
|
}
|
|
281
336
|
|
|
282
337
|
async function run(args) {
|
|
283
|
-
const { appType, formUuid, dataPermission, actionPermission, fieldPermission, members, createMode, groupName } = parseArgs(args);
|
|
338
|
+
const { appType, formUuid, dataPermission, actionPermission, fieldPermission, members, allMembers, matrix, createMode, groupName } = parseArgs(args);
|
|
284
339
|
|
|
285
340
|
warn(SEP);
|
|
286
341
|
warn(' save-permission - 宜搭表单权限配置保存');
|
|
@@ -296,10 +351,17 @@ async function run(args) {
|
|
|
296
351
|
// Step 0: 参数校验
|
|
297
352
|
warn('\n📋 Step 0: 验证参数');
|
|
298
353
|
try {
|
|
354
|
+
if (matrix && (members || allMembers)) {
|
|
355
|
+
throw new Error('--matrix 与 --members / --all-members 互斥,请勿同时指定');
|
|
356
|
+
}
|
|
299
357
|
if (dataPermission) {
|
|
300
358
|
validateDataPermission(dataPermission);
|
|
301
359
|
warn(` ✅ 数据权限验证通过(dataRange: ${dataPermission.dataRange || 'ALL'})`);
|
|
302
360
|
}
|
|
361
|
+
if (matrix) {
|
|
362
|
+
validateMatrix(matrix);
|
|
363
|
+
warn(` ✅ 权限矩阵验证通过(matrixId: ${matrix.matrixId}, columnId: ${matrix.columnId})`);
|
|
364
|
+
}
|
|
303
365
|
if (actionPermission) {
|
|
304
366
|
validateActionPermission(actionPermission);
|
|
305
367
|
warn(' ✅ 操作权限验证通过');
|
|
@@ -335,6 +397,7 @@ async function run(args) {
|
|
|
335
397
|
// 构建新权限组数据
|
|
336
398
|
const dataRange = (dataPermission && dataPermission.dataRange) || 'ALL';
|
|
337
399
|
const permitType = DATA_RANGE_TO_PERMIT_TYPE[dataRange] || dataRange;
|
|
400
|
+
const dataPermitStr = buildDataPermit(dataPermission);
|
|
338
401
|
|
|
339
402
|
const newOperatePermit = {};
|
|
340
403
|
if (actionPermission) {
|
|
@@ -346,10 +409,19 @@ async function run(args) {
|
|
|
346
409
|
newOperatePermit['OPERATE_VIEW'] = 'y';
|
|
347
410
|
}
|
|
348
411
|
|
|
349
|
-
// 构建 roleData
|
|
350
|
-
|
|
351
|
-
if (
|
|
352
|
-
roleInclude
|
|
412
|
+
// 构建 roleData:--matrix / --all-members / --members / 默认管理员 四选一
|
|
413
|
+
let roleInclude;
|
|
414
|
+
if (matrix) {
|
|
415
|
+
roleInclude = [{ roleType: 'MATRIX', roleValue: [{ matrixId: matrix.matrixId, columnId: matrix.columnId }] }];
|
|
416
|
+
} else if (allMembers) {
|
|
417
|
+
roleInclude = [{ roleType: 'DEFAULT', roleValue: 'ALL' }];
|
|
418
|
+
} else if (members && members.length > 0) {
|
|
419
|
+
roleInclude = [
|
|
420
|
+
{ roleType: 'MANAGER', roleValue: 'appMainAdminRole,corpAdminRole' },
|
|
421
|
+
{ roleType: 'PERSONS', roleValue: members.join(',') },
|
|
422
|
+
];
|
|
423
|
+
} else {
|
|
424
|
+
roleInclude = [{ roleType: 'MANAGER', roleValue: 'appMainAdminRole,corpAdminRole' }];
|
|
353
425
|
}
|
|
354
426
|
|
|
355
427
|
const newPkg = {
|
|
@@ -357,7 +429,7 @@ async function run(args) {
|
|
|
357
429
|
packageName: { zh_CN: groupName, en_US: groupName, type: 'i18n' },
|
|
358
430
|
description: { zh_CN: groupName, en_US: groupName, type: 'i18n' },
|
|
359
431
|
roleData: JSON.stringify({ include: roleInclude }),
|
|
360
|
-
dataPermit:
|
|
432
|
+
dataPermit: dataPermitStr,
|
|
361
433
|
operatePermit: JSON.stringify(newOperatePermit),
|
|
362
434
|
customButtonPermit: '[]',
|
|
363
435
|
fieldPermit: JSON.stringify(normalizedFieldPermission || { fieldRange: 'FORM' }),
|
|
@@ -366,10 +438,18 @@ async function run(args) {
|
|
|
366
438
|
};
|
|
367
439
|
|
|
368
440
|
warn(` → 权限组名称: ${groupName}`);
|
|
369
|
-
|
|
441
|
+
if (dataPermission && Array.isArray(dataPermission.rule)) {
|
|
442
|
+
warn(` → 数据范围: 自定义规则(${dataPermission.rule.length} 条)`);
|
|
443
|
+
} else {
|
|
444
|
+
warn(` → 数据范围: ${dataRange} → ${permitType}`);
|
|
445
|
+
}
|
|
370
446
|
warn(` → 操作权限: ${Object.keys(newOperatePermit).join(', ') || '(无)'}`);
|
|
371
447
|
if (normalizedFieldPermission) {warn(' → 字段权限: 自定义 fieldPermit');}
|
|
372
|
-
if (
|
|
448
|
+
if (matrix) {
|
|
449
|
+
warn(` → 权限矩阵: ${matrix.matrixId} / ${matrix.columnId}`);
|
|
450
|
+
} else if (members) {
|
|
451
|
+
warn(` → 成员: ${members.join(', ')}`);
|
|
452
|
+
}
|
|
373
453
|
|
|
374
454
|
const createResult = await savePermitPackage(appType, formUuid, newPkg, null, authRef);
|
|
375
455
|
|
|
@@ -378,15 +458,28 @@ async function run(args) {
|
|
|
378
458
|
const newPackageUuid = createResult.content || '';
|
|
379
459
|
warn(' ✅ 权限组新增成功!');
|
|
380
460
|
warn(SEP);
|
|
461
|
+
const dataPermissionSummary = (dataPermission && Array.isArray(dataPermission.rule))
|
|
462
|
+
? `数据范围: 自定义规则(${dataPermission.rule.length} 条)`
|
|
463
|
+
: `数据范围: ${dataRange}`;
|
|
464
|
+
let membersSummary;
|
|
465
|
+
if (matrix) {
|
|
466
|
+
membersSummary = `权限矩阵: ${matrix.matrixId} / ${matrix.columnId}`;
|
|
467
|
+
} else if (allMembers) {
|
|
468
|
+
membersSummary = '成员: 全员';
|
|
469
|
+
} else if (members) {
|
|
470
|
+
membersSummary = `成员: ${members.join(', ')}`;
|
|
471
|
+
} else {
|
|
472
|
+
membersSummary = '仅管理员';
|
|
473
|
+
}
|
|
381
474
|
console.log(JSON.stringify({
|
|
382
475
|
success: true,
|
|
383
476
|
packageUuid: newPackageUuid,
|
|
384
477
|
summary: {
|
|
385
478
|
name: groupName,
|
|
386
|
-
dataPermission:
|
|
479
|
+
dataPermission: dataPermissionSummary,
|
|
387
480
|
actionPermission: `操作权限: ${Object.keys(newOperatePermit).join(', ') || '(无)'}`,
|
|
388
481
|
fieldPermission: normalizedFieldPermission ? '自定义 fieldPermit' : '全部字段',
|
|
389
|
-
members:
|
|
482
|
+
members: membersSummary,
|
|
390
483
|
},
|
|
391
484
|
message: '权限组已新增',
|
|
392
485
|
}, null, 2));
|
|
@@ -424,7 +517,10 @@ async function run(args) {
|
|
|
424
517
|
warn(` ✅ 获取到 ${packages.length} 个权限组`);
|
|
425
518
|
|
|
426
519
|
// 根据 role 筛选要更新的权限组
|
|
427
|
-
|
|
520
|
+
let targetRole = (dataPermission || actionPermission || fieldPermission || {}).role || 'DEFAULT';
|
|
521
|
+
if (matrix) {
|
|
522
|
+
targetRole = 'MATRIX';
|
|
523
|
+
}
|
|
428
524
|
const packagesToUpdate = packages.filter((pkg) => {
|
|
429
525
|
if (targetRole === 'DEFAULT') {
|
|
430
526
|
return pkg.roleMembers && pkg.roleMembers.some((rm) => rm.roleType === 'DEFAULT');
|
|
@@ -432,6 +528,9 @@ async function run(args) {
|
|
|
432
528
|
if (targetRole === 'MANAGER') {
|
|
433
529
|
return pkg.roleMembers && pkg.roleMembers.some((rm) => rm.roleType === 'MANAGER');
|
|
434
530
|
}
|
|
531
|
+
if (targetRole === 'MATRIX') {
|
|
532
|
+
return pkg.roleMembers && pkg.roleMembers.some((rm) => rm.roleType === 'MATRIX');
|
|
533
|
+
}
|
|
435
534
|
return true;
|
|
436
535
|
});
|
|
437
536
|
|
|
@@ -447,8 +546,12 @@ async function run(args) {
|
|
|
447
546
|
let permitType = null;
|
|
448
547
|
const stepParts = [];
|
|
449
548
|
if (dataPermission) {
|
|
450
|
-
|
|
451
|
-
|
|
549
|
+
if (Array.isArray(dataPermission.rule)) {
|
|
550
|
+
stepParts.push(`数据权限: 自定义规则(${dataPermission.rule.length} 条)`);
|
|
551
|
+
} else {
|
|
552
|
+
permitType = DATA_RANGE_TO_PERMIT_TYPE[dataPermission.dataRange] || dataPermission.dataRange;
|
|
553
|
+
stepParts.push(`数据权限: ${dataPermission.dataRange} → ${permitType}`);
|
|
554
|
+
}
|
|
452
555
|
}
|
|
453
556
|
if (actionPermission) {
|
|
454
557
|
stepParts.push('操作权限: 同步更新');
|
|
@@ -456,6 +559,9 @@ async function run(args) {
|
|
|
456
559
|
if (normalizedFieldPermission) {
|
|
457
560
|
stepParts.push('字段权限: 同步更新');
|
|
458
561
|
}
|
|
562
|
+
if (matrix) {
|
|
563
|
+
stepParts.push(`权限矩阵: ${matrix.matrixId} / ${matrix.columnId}`);
|
|
564
|
+
}
|
|
459
565
|
if (members) {
|
|
460
566
|
stepParts.push(`成员: ${members.join(', ')}`);
|
|
461
567
|
}
|
|
@@ -469,7 +575,7 @@ async function run(args) {
|
|
|
469
575
|
const updatedPkg = { ...pkg };
|
|
470
576
|
|
|
471
577
|
if (dataPermission) {
|
|
472
|
-
updatedPkg.dataPermit =
|
|
578
|
+
updatedPkg.dataPermit = buildDataPermit(dataPermission);
|
|
473
579
|
}
|
|
474
580
|
|
|
475
581
|
if (actionPermission) {
|
|
@@ -487,6 +593,18 @@ async function run(args) {
|
|
|
487
593
|
updatedPkg.fieldPermit = JSON.stringify(normalizedFieldPermission);
|
|
488
594
|
}
|
|
489
595
|
|
|
596
|
+
// --all-members 时强制将权限组改为全员可见
|
|
597
|
+
if (allMembers) {
|
|
598
|
+
updatedPkg.roleData = JSON.stringify({ include: [{ roleType: 'DEFAULT', roleValue: 'ALL' }] });
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// --matrix 时强制将权限组改为权限矩阵
|
|
602
|
+
if (matrix) {
|
|
603
|
+
updatedPkg.roleData = JSON.stringify({
|
|
604
|
+
include: [{ roleType: 'MATRIX', roleValue: [{ matrixId: matrix.matrixId, columnId: matrix.columnId }] }],
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
|
|
490
608
|
// members 参数传给 savePermitPackage,null 表示不修改成员
|
|
491
609
|
const overrideMembers = members || null;
|
|
492
610
|
|
|
@@ -524,7 +642,9 @@ module.exports = {
|
|
|
524
642
|
parseArgs,
|
|
525
643
|
validateDataPermission,
|
|
526
644
|
validateActionPermission,
|
|
645
|
+
validateMatrix,
|
|
527
646
|
normalizeFieldPermission,
|
|
647
|
+
buildDataPermit,
|
|
528
648
|
fetchPermitPackages,
|
|
529
649
|
buildRoleData,
|
|
530
650
|
savePermitPackage,
|
package/package.json
CHANGED
|
@@ -110,6 +110,7 @@ openyida data query form <appType> <formUuid> [--page 1 --size 20] [--search-jso
|
|
|
110
110
|
openyida data get form <appType> --inst-id <formInstId>
|
|
111
111
|
openyida data create form <appType> <formUuid> --data-json '<json>' [--resolve-aliases]
|
|
112
112
|
openyida data create form <appType> <formUuid> --data-file .cache/openyida/<项目名或任务名>/data-import/record.json [--resolve-aliases]
|
|
113
|
+
> `create form` 会自动探测表单类型;当目标表单为流程表单时,会改用 `/v1/process/startInstance.json` 发起流程。若已知 `processCode`,仍推荐显式使用 `create process`。
|
|
113
114
|
openyida data update form <appType> --inst-id <formInstId> --form-uuid <formUuid> --data-json '<json>' [--resolve-aliases]
|
|
114
115
|
openyida data update form <appType> --inst-id <formInstId> --form-uuid <formUuid> --data-file .cache/openyida/<项目名或任务名>/data-import/patch.json [--resolve-aliases]
|
|
115
116
|
openyida data query subform <appType> <formUuid> --inst-id <formInstId> --table-field-id <fieldId|alias> [--page 1 --size 100] [--resolve-aliases]
|
|
@@ -55,6 +55,8 @@ openyida save-permission <appType> <formUuid> [选项]
|
|
|
55
55
|
| `--action-permission <json>` | 修改操作权限(完全替换,只保留 true 的项) |
|
|
56
56
|
| `--field-permission <json>` | 修改字段权限,传入宜搭 `fieldPermit` 对象或 `{ "role": "DEFAULT", "fieldPermit": {...} }` |
|
|
57
57
|
| `--members <userIds>` | 修改成员,多个 userId 逗号分隔 |
|
|
58
|
+
| `--all-members` | 设置权限组为「全员可见」(`roleData.include` 为 `DEFAULT/ALL`) |
|
|
59
|
+
| `--matrix <json>` | 使用权限矩阵作为权限成员,JSON 格式 `{"matrixId":"MATRIX-XXX","columnId":"column_YYY"}`,与 `--members` / `--all-members` 互斥 |
|
|
58
60
|
|
|
59
61
|
### 数据权限 `dataRange` 可选值
|
|
60
62
|
|
|
@@ -65,6 +67,42 @@ openyida save-permission <appType> <formUuid> [选项]
|
|
|
65
67
|
| `DEPARTMENT` / `ORIGINATOR_DEPARTMENT` | 本部门提交 |
|
|
66
68
|
| `SAME_LEVEL_DEPARTMENT` | 同级部门 |
|
|
67
69
|
| `SUBORDINATE_DEPARTMENT` | 下级部门 |
|
|
70
|
+
| `MATRIX` | 权限矩阵条件 |
|
|
71
|
+
|
|
72
|
+
> 如需同时设置多个数据范围、自定义部门或自定义过滤条件,可直接传入宜搭完整的 `dataPermit` JSON(必须包含 `rule` 数组)。例如截图中的「本人提交 + 本部门 + 同级部门 + 下级部门 + 免登 + 自定义部门 + 自定义过滤条件」可表示为:
|
|
73
|
+
>
|
|
74
|
+
> ```json
|
|
75
|
+
> {
|
|
76
|
+
> "rule": [
|
|
77
|
+
> { "type": "ORIGINATOR", "value": "y" },
|
|
78
|
+
> { "type": "ORIGINATOR_DEPARTMENT", "value": "y" },
|
|
79
|
+
> { "type": "SAME_LEVEL_DEPARTMENT", "value": "y" },
|
|
80
|
+
> { "type": "SUBORDINATE_DEPARTMENT", "value": "y" },
|
|
81
|
+
> { "type": "FREE_LOGIN", "value": "y" },
|
|
82
|
+
> { "type": "CUSTOM_DEPARTMENT", "value": "y" },
|
|
83
|
+
> { "type": "FORMULA", "value": "y" }
|
|
84
|
+
> ],
|
|
85
|
+
> "customDepartmentData": {
|
|
86
|
+
> "departmentIds": ["637215248"],
|
|
87
|
+
> "drillDown": "n"
|
|
88
|
+
> },
|
|
89
|
+
> "formulaData": {
|
|
90
|
+
> "condition": "OR",
|
|
91
|
+
> "ruleId": "group-xxx",
|
|
92
|
+
> "rules": []
|
|
93
|
+
> }
|
|
94
|
+
> }
|
|
95
|
+
> ```
|
|
96
|
+
>
|
|
97
|
+
> 命令示例:
|
|
98
|
+
>
|
|
99
|
+
> ```bash
|
|
100
|
+
> openyida save-permission APP_XXX FORM_XXX \
|
|
101
|
+
> --create --name "全部成员可查看本人提交数据" \
|
|
102
|
+
> --all-members \
|
|
103
|
+
> --data-permission '{"rule":[{"type":"ORIGINATOR","value":"y"},{"type":"ORIGINATOR_DEPARTMENT","value":"y"},{"type":"SAME_LEVEL_DEPARTMENT","value":"y"},{"type":"SUBORDINATE_DEPARTMENT","value":"y"},{"type":"FREE_LOGIN","value":"y"},{"type":"CUSTOM_DEPARTMENT","value":"y"},{"type":"FORMULA","value":"y"}],"customDepartmentData":{"departmentIds":["637215248"],"drillDown":"n"},"formulaData":{"condition":"OR","ruleId":"group-xxx","rules":[]}}' \
|
|
104
|
+
> --action-permission '{"operations":{"OPERATE_VIEW":true,"OPERATE_EDIT":true,"OPERATE_DELETE":true,"OPERATE_HISTORY":true,"OPERATE_COMMENT":true,"OPERATE_PRINT":true}}'
|
|
105
|
+
> ```
|
|
68
106
|
|
|
69
107
|
### 操作权限 key
|
|
70
108
|
|
|
@@ -79,7 +117,7 @@ openyida save-permission <appType> <formUuid> --create --name <名称> [选项]
|
|
|
79
117
|
示例:
|
|
80
118
|
|
|
81
119
|
```bash
|
|
82
|
-
openyida save-permission APP_XXX
|
|
120
|
+
openyida save-permission APP_XXX FORM_XXX \
|
|
83
121
|
--create --name "部门数据查看组" \
|
|
84
122
|
--members "54255850977641" \
|
|
85
123
|
--data-permission '{"dataRange":"ORIGINATOR_DEPARTMENT"}' \
|
|
@@ -87,6 +125,30 @@ openyida save-permission APP_XXX FORM-XXX \
|
|
|
87
125
|
--field-permission '{"fieldRange":"FORM"}'
|
|
88
126
|
```
|
|
89
127
|
|
|
128
|
+
> 设置「全部人员看全部数据」时,必须加上 `--all-members`,确保 `roleData.include` 为 `DEFAULT/ALL`:
|
|
129
|
+
>
|
|
130
|
+
> ```bash
|
|
131
|
+
> openyida save-permission APP_XXX FORM_XXX \
|
|
132
|
+
> --create --name "全部人员看全部数据" \
|
|
133
|
+
> --all-members \
|
|
134
|
+
> --data-permission '{"dataRange":"ALL"}' \
|
|
135
|
+
> --action-permission '{"operations":{"OPERATE_VIEW":true}}'
|
|
136
|
+
> ```
|
|
137
|
+
>
|
|
138
|
+
> 若目标表单已存在 DEFAULT 权限组,也可直接用 `--all-members --data-permission '{"dataRange":"ALL"}'` 更新该组。
|
|
139
|
+
>
|
|
140
|
+
> ### 使用权限矩阵
|
|
141
|
+
> 1. 先在宜搭后台「权限矩阵」中获取目标矩阵 ID 与结果列 columnId;或调用底层服务 `/query/matrix/getMatrixList.json` / `/query/matrix/getMatrixById.json` 查询。
|
|
142
|
+
> 2. 创建/更新权限组时指定 `--matrix '{"matrixId":"MATRIX-XXX","columnId":"column_YYY"}'`,并配合 `--data-permission` 设置包含 `MATRIX` 的数据范围。
|
|
143
|
+
>
|
|
144
|
+
> ```bash
|
|
145
|
+
> openyida save-permission APP_XXX FORM_XXX \
|
|
146
|
+
> --create --name "使用权限矩阵的权限组" \
|
|
147
|
+
> --matrix '{"matrixId":"MATRIX-XNCVJYB60YW7L0HPY9HE","columnId":"column_1767839664612"}' \
|
|
148
|
+
> --data-permission '{"rule":[{"type":"ORIGINATOR","value":"y"},{"type":"MATRIX","value":"y"}]}' \
|
|
149
|
+
> --action-permission '{"operations":{"OPERATE_VIEW":true,"OPERATE_EDIT":true,"OPERATE_DELETE":true,"OPERATE_HISTORY":true,"OPERATE_COMMENT":true,"OPERATE_PRINT":true}}'
|
|
150
|
+
> ```
|
|
151
|
+
|
|
90
152
|
## 字段权限
|
|
91
153
|
|
|
92
154
|
- 默认结构通常是 `{ "fieldRange": "FORM" }`,表示继承表单设计中组件状态。
|