Skip to content

Commit d5c1014

Browse files
author
funcodingdev
committed
feat: 更新文档加入规则的权限设置,增加企业内外成员的加入规则选项
1 parent ee47808 commit d5c1014

4 files changed

Lines changed: 199 additions & 83 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ npm install n8n-nodes-wecom
643643
#### 设置文档权限
644644

645645
-[获取文档权限信息](https://developer.work.weixin.qq.com/document/path/97461)
646-
-[修改文档查看规则](https://developer.work.weixin.qq.com/document/path/97778)
646+
-[修改文档加入规则](https://developer.work.weixin.qq.com/document/path/97778)
647647
-[修改文档通知范围及权限](https://developer.work.weixin.qq.com/document/path/97781)
648648
-[修改文档安全设置](https://developer.work.weixin.qq.com/document/path/97782)
649649
-[管理智能表格内容权限](https://developer.work.weixin.qq.com/document/path/99935)

nodes/WeCom/resources/wedoc/execute.ts

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,9 @@ export async function executeWedoc(
761761
try {
762762
const parsed = JSON.parse(trimmed) as unknown;
763763
if (!parsed || Array.isArray(parsed) || typeof parsed !== 'object') {
764-
throw new NodeOperationError(
765-
this.getNode(),
766-
`${parameterName} 必须是 JSON 对象`,
767-
{ itemIndex },
768-
);
764+
throw new NodeOperationError(this.getNode(), `${parameterName} 必须是 JSON 对象`, {
765+
itemIndex,
766+
});
769767
}
770768
return parsed as IDataObject;
771769
} catch (error) {
@@ -1742,24 +1740,92 @@ export async function executeWedoc(
17421740
response = await weComApiRequest.call(this, 'POST', '/cgi-bin/wedoc/mod_doc_member', body);
17431741
} else if (operation === 'modDocShareScope') {
17441742
const docid = this.getNodeParameter('docid', i) as string;
1745-
const coAuthCollection = this.getNodeParameter('coAuthCollection', i, {}) as IDataObject;
1746-
const enable_readonly_copy = this.getNodeParameter(
1747-
'enable_readonly_copy',
1743+
const body: IDataObject = { docid };
1744+
const updateInternalJoinRule = this.getNodeParameter(
1745+
'updateInternalJoinRule',
17481746
i,
1749-
true,
1747+
false,
17501748
) as boolean;
1751-
const ban_share_external = this.getNodeParameter('ban_share_external', i, false) as boolean;
1752-
const share_scope = this.getNodeParameter('share_scope', i, 1) as number;
1749+
const updateExternalJoinRule = this.getNodeParameter(
1750+
'updateExternalJoinRule',
1751+
i,
1752+
false,
1753+
) as boolean;
1754+
const updateBanShareExternal = this.getNodeParameter(
1755+
'updateBanShareExternal',
1756+
i,
1757+
false,
1758+
) as boolean;
1759+
const updateCoAuthList = this.getNodeParameter('update_co_auth_list', i, false) as boolean;
17531760

1754-
const body: IDataObject = {
1755-
docid,
1756-
enable_readonly_copy,
1757-
ban_share_external,
1758-
share_scope,
1759-
};
1761+
if (updateInternalJoinRule) {
1762+
body.enable_corp_internal = this.getNodeParameter(
1763+
'enable_corp_internal',
1764+
i,
1765+
true,
1766+
) as boolean;
1767+
body.corp_internal_auth = this.getNodeParameter('corp_internal_auth', i, 2) as number;
1768+
body.corp_internal_approve_only_by_admin = this.getNodeParameter(
1769+
'corp_internal_approve_only_by_admin',
1770+
i,
1771+
false,
1772+
) as boolean;
1773+
}
1774+
1775+
if (updateExternalJoinRule) {
1776+
body.enable_corp_external = this.getNodeParameter(
1777+
'enable_corp_external',
1778+
i,
1779+
false,
1780+
) as boolean;
1781+
body.corp_external_auth = this.getNodeParameter('corp_external_auth', i, 1) as number;
1782+
body.corp_external_approve_only_by_admin = this.getNodeParameter(
1783+
'corp_external_approve_only_by_admin',
1784+
i,
1785+
true,
1786+
) as boolean;
1787+
}
17601788

1761-
if (coAuthCollection.members && Array.isArray(coAuthCollection.members)) {
1762-
body.co_auth_list = (coAuthCollection.members as IDataObject[]).map(buildMemberInfo);
1789+
if (updateBanShareExternal) {
1790+
body.ban_share_external = this.getNodeParameter(
1791+
'ban_share_external',
1792+
i,
1793+
false,
1794+
) as boolean;
1795+
}
1796+
1797+
if (updateCoAuthList) {
1798+
const coAuthCollection = this.getNodeParameter('coAuthCollection', i, {}) as IDataObject;
1799+
const rawDepartments = Array.isArray(coAuthCollection.departments)
1800+
? (coAuthCollection.departments as IDataObject[])
1801+
: Array.isArray(coAuthCollection.members)
1802+
? (coAuthCollection.members as IDataObject[])
1803+
: [];
1804+
1805+
body.update_co_auth_list = true;
1806+
body.co_auth_list = rawDepartments.map((department) => {
1807+
const type = department.type ?? 2;
1808+
1809+
if (type !== 2) {
1810+
throw new NodeOperationError(
1811+
this.getNode(),
1812+
'修改文档加入规则的特定权限列表目前只支持部门类型',
1813+
{ itemIndex: i },
1814+
);
1815+
}
1816+
1817+
return {
1818+
departmentid: department.departmentid,
1819+
auth: department.auth,
1820+
type: 2,
1821+
};
1822+
});
1823+
}
1824+
1825+
if (Object.keys(body).length === 1) {
1826+
throw new NodeOperationError(this.getNode(), '请至少开启一项要更新的加入规则设置', {
1827+
itemIndex: i,
1828+
});
17631829
}
17641830

17651831
response = await weComApiRequest.call(

nodes/WeCom/resources/wedoc/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ export const wedocDescription: INodeProperties[] = [
274274
description: '修改文档的成员权限规则',
275275
},
276276
{
277-
name: '[权限设置] 修改文档查看规则',
277+
name: '[权限设置] 修改文档加入规则',
278278
value: 'modDocShareScope',
279-
action: '[权限设置] 修改文档查看规则',
280-
description: '修改文档的查看范围规则',
279+
action: '[权限设置] 修改文档加入规则',
280+
description: '修改文档、表格、智能表格的加入规则',
281281
},
282282
{
283283
name: '[权限设置] 修改文档安全设置',
Lines changed: 110 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,143 @@
11
import type { INodeProperties } from 'n8n-workflow';
2+
23
const showOnly = { resource: ['wedoc'], operation: ['modDocShareScope'] };
34

45
const authOptions = [
5-
{ name: '只读', value: 1, description: '只能查看' },
6-
{ name: '可编辑', value: 2, description: '可以编辑内容' },
6+
{ name: '只读', value: 1, description: '成员仅可查看内容' },
7+
{ name: '可编辑', value: 2, description: '成员可编辑内容,数据可被接口获取' },
78
];
89

910
export const modDocShareScopeDescription: INodeProperties[] = [
10-
{ displayName: '文档ID', name: 'docid', type: 'string', required: true, displayOptions: { show: showOnly }, default: '', description: '文档的docid' },
1111
{
12-
displayName: '协作者权限列表',
12+
displayName: '文档ID',
13+
name: 'docid',
14+
type: 'string',
15+
required: true,
16+
displayOptions: { show: showOnly },
17+
default: '',
18+
description: '操作的 docid,可用于文档、表格、智能表格',
19+
},
20+
{
21+
displayName: '更新企业内成员加入规则',
22+
name: 'updateInternalJoinRule',
23+
type: 'boolean',
24+
displayOptions: { show: showOnly },
25+
default: false,
26+
description: '开启后覆盖企业内成员的加入规则',
27+
},
28+
{
29+
displayName: '允许企业内成员浏览',
30+
name: 'enable_corp_internal',
31+
type: 'boolean',
32+
displayOptions: { show: { ...showOnly, updateInternalJoinRule: [true] } },
33+
default: true,
34+
description: '企业内成员主动查看文档后是否允许加入',
35+
},
36+
{
37+
displayName: '企业内成员加入后权限',
38+
name: 'corp_internal_auth',
39+
type: 'options',
40+
displayOptions: { show: { ...showOnly, updateInternalJoinRule: [true] } },
41+
default: 2,
42+
options: authOptions,
43+
description: '企业内成员主动查看后获得的权限',
44+
},
45+
{
46+
displayName: '企业内成员仅管理员审批',
47+
name: 'corp_internal_approve_only_by_admin',
48+
type: 'boolean',
49+
displayOptions: { show: { ...showOnly, updateInternalJoinRule: [true] } },
50+
default: false,
51+
description: '是否要求企业内成员加入时必须由管理员审批',
52+
},
53+
{
54+
displayName: '更新企业外成员加入规则',
55+
name: 'updateExternalJoinRule',
56+
type: 'boolean',
57+
displayOptions: { show: showOnly },
58+
default: false,
59+
description: '开启后覆盖企业外成员的加入规则',
60+
},
61+
{
62+
displayName: '允许企业外成员浏览',
63+
name: 'enable_corp_external',
64+
type: 'boolean',
65+
displayOptions: { show: { ...showOnly, updateExternalJoinRule: [true] } },
66+
default: false,
67+
description: '企业外成员主动查看文档后是否允许加入',
68+
},
69+
{
70+
displayName: '企业外成员加入后权限',
71+
name: 'corp_external_auth',
72+
type: 'options',
73+
displayOptions: { show: { ...showOnly, updateExternalJoinRule: [true] } },
74+
default: 1,
75+
options: authOptions,
76+
description: '企业外成员主动查看后获得的权限',
77+
},
78+
{
79+
displayName: '企业外成员仅管理员审批',
80+
name: 'corp_external_approve_only_by_admin',
81+
type: 'boolean',
82+
displayOptions: { show: { ...showOnly, updateExternalJoinRule: [true] } },
83+
default: true,
84+
description: '是否要求企业外成员加入时必须由管理员审批',
85+
},
86+
{
87+
displayName: '更新禁止对外分享设置',
88+
name: 'updateBanShareExternal',
89+
type: 'boolean',
90+
displayOptions: { show: showOnly },
91+
default: false,
92+
description: '开启后覆盖是否允许分享给企业外部人员',
93+
},
94+
{
95+
displayName: '禁止对外分享',
96+
name: 'ban_share_external',
97+
type: 'boolean',
98+
displayOptions: { show: { ...showOnly, updateBanShareExternal: [true] } },
99+
default: false,
100+
description: '是否禁止文档分享到企业外',
101+
},
102+
{
103+
displayName: '更新特定部门加入权限',
104+
name: 'update_co_auth_list',
105+
type: 'boolean',
106+
displayOptions: { show: showOnly },
107+
default: false,
108+
description: '开启后覆盖特定部门列表,留空列表时清空',
109+
},
110+
{
111+
displayName: '特定部门列表',
13112
name: 'coAuthCollection',
14113
type: 'fixedCollection',
15-
displayOptions: { show: showOnly },
114+
displayOptions: { show: { ...showOnly, update_co_auth_list: [true] } },
16115
default: {},
17-
placeholder: '添加协作者',
116+
placeholder: '添加部门',
18117
typeOptions: { multipleValues: true },
19-
description: '设置协作者的权限',
118+
description: '指定文档查看权限的部门列表,留空表示清空',
20119
options: [
21120
{
22-
displayName: '协作者',
23-
name: 'members',
121+
displayName: '部门',
122+
name: 'departments',
24123
values: [
25-
{
26-
displayName: '类型',
27-
name: 'type',
28-
type: 'options',
29-
default: 1,
30-
options: [
31-
{ name: '成员', value: 1, description: '企业成员' },
32-
{ name: '部门', value: 2, description: '企业部门' },
33-
],
34-
description: '协作者类型',
35-
},
36-
{
37-
displayName: '成员UserID',
38-
name: 'userid',
39-
type: 'string',
40-
default: '',
41-
displayOptions: { show: { type: [1] } },
42-
description: '企业成员的UserID',
43-
},
44124
{
45125
displayName: '部门ID',
46126
name: 'departmentid',
47127
type: 'number',
48128
default: 0,
49-
displayOptions: { show: { type: [2] } },
50-
129+
description: '部门 ID',
51130
},
52131
{
53132
displayName: '权限',
54133
name: 'auth',
55134
type: 'options',
56135
default: 1,
57136
options: authOptions,
58-
description: '协作权限级别',
137+
description: '部门加入后获得的权限',
59138
},
60139
],
61140
},
62141
],
63142
},
64-
{
65-
displayName: '只读时允许复制',
66-
name: 'enable_readonly_copy',
67-
type: 'boolean',
68-
displayOptions: { show: showOnly },
69-
default: true,
70-
description: '是否允许在只读情况下复制内容',
71-
},
72-
{
73-
displayName: '禁止对外分享',
74-
name: 'ban_share_external',
75-
type: 'boolean',
76-
displayOptions: { show: showOnly },
77-
default: false,
78-
description: '是否禁止将文档分享给企业外部人员',
79-
},
80-
{
81-
displayName: '链接分享范围',
82-
name: 'share_scope',
83-
type: 'options',
84-
displayOptions: { show: showOnly },
85-
default: 1,
86-
options: [
87-
{ name: '仅指定成员可访问', value: 1 },
88-
{ name: '企业内获得链接的人可访问', value: 2 },
89-
{ name: '任何人获得链接都可访问', value: 3 },
90-
],
91-
description: '通过链接分享时的访问范围',
92-
},
93143
];

0 commit comments

Comments
 (0)