@yongdall/organization-rbac 0.6.5 → 0.6.6
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/index.d.mts +72 -52
- package/index.mjs +2 -2
- package/organization-rbac-CVRP1FKi.mjs +513 -0
- package/organization-rbac-CVRP1FKi.mjs.map +1 -0
- package/package.json +9 -8
- package/yongdall/migration.mjs +9 -3
- package/yongdall/migration.mjs.map +1 -1
- package/yongdall/model.mjs +6 -3
- package/yongdall/model.mjs.map +1 -1
- package/yongdall/user.mjs +2 -15
- package/organization-rbac-BF8uzSCr.mjs +0 -230
- package/organization-rbac-BF8uzSCr.mjs.map +0 -1
- package/yongdall/user.mjs.map +0 -1
package/index.d.mts
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
1
|
+
import * as imodel20 from "imodel";
|
|
2
|
+
import * as _yongdall_model3 from "@yongdall/model";
|
|
3
3
|
|
|
4
|
-
//#region plugins/organization-rbac/models/
|
|
5
|
-
declare const
|
|
6
|
-
id:
|
|
7
|
-
label:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
//#region plugins/organization-rbac/models/CompositeRole.d.mts
|
|
5
|
+
declare const CompositeRole: _yongdall_model3.ModelTable<{
|
|
6
|
+
id: imodel20.FieldDefine<"uuid", false, false>;
|
|
7
|
+
label: imodel20.FieldDefine<"string", false, false>;
|
|
8
|
+
organizationId: imodel20.FieldDefine<"uuid", false, true>;
|
|
9
|
+
description: imodel20.FieldDefine<"text", false, true>;
|
|
10
|
+
createdAt: imodel20.FieldDefine<"date", false, false>;
|
|
11
|
+
updatedAt: imodel20.FieldDefine<"date", false, false>;
|
|
12
|
+
}, "compositeRole">;
|
|
12
13
|
//#endregion
|
|
13
|
-
//#region plugins/organization-rbac/models/
|
|
14
|
+
//#region plugins/organization-rbac/models/OrganizationCompositeRole.d.mts
|
|
14
15
|
/**
|
|
15
16
|
* 组织用户角色模型
|
|
17
|
+
* @typedef {Object} OrganizationUserRole
|
|
18
|
+
* @property {string} userId - 用户ID,主键第一部分
|
|
19
|
+
* @property {string} organizationId - 组织ID,主键第二部分
|
|
20
|
+
* @property {string} roleId - 角色ID,主键第三部分
|
|
21
|
+
* @property {number} no - 编号
|
|
16
22
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
organizationId: string;
|
|
26
|
-
/**
|
|
27
|
-
* - 角色ID,主键第三部分
|
|
28
|
-
*/
|
|
29
|
-
roleId: string;
|
|
30
|
-
/**
|
|
31
|
-
* - 编号
|
|
32
|
-
*/
|
|
33
|
-
no: number;
|
|
34
|
-
};
|
|
23
|
+
declare const OrganizationCompositeRole: _yongdall_model3.ModelTable<{
|
|
24
|
+
compositeRoleId: imodel20.FieldDefine<"uuid", false, false>;
|
|
25
|
+
organizationId: imodel20.FieldDefine<"uuid", false, false>;
|
|
26
|
+
roleId: imodel20.FieldDefine<"uuid", false, false>;
|
|
27
|
+
createdAt: imodel20.FieldDefine<"date", false, false>;
|
|
28
|
+
}, "organizationCompositeRole">;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region plugins/organization-rbac/models/OrganizationUserCompositeRole.d.mts
|
|
35
31
|
/**
|
|
36
32
|
* 组织用户角色模型
|
|
37
33
|
* @typedef {Object} OrganizationUserRole
|
|
@@ -40,36 +36,60 @@ type OrganizationUserRole = {
|
|
|
40
36
|
* @property {string} roleId - 角色ID,主键第三部分
|
|
41
37
|
* @property {number} no - 编号
|
|
42
38
|
*/
|
|
43
|
-
declare const
|
|
44
|
-
userId:
|
|
45
|
-
organizationId:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
39
|
+
declare const OrganizationUserCompositeRole: _yongdall_model3.ModelTable<{
|
|
40
|
+
userId: imodel20.FieldDefine<"uuid", false, false>;
|
|
41
|
+
organizationId: imodel20.FieldDefine<"uuid", false, false>;
|
|
42
|
+
compositeRoleId: imodel20.FieldDefine<"uuid", false, false>;
|
|
43
|
+
createdAt: imodel20.FieldDefine<"date", false, false>;
|
|
44
|
+
updatedAt: imodel20.FieldDefine<"date", false, false>;
|
|
45
|
+
}, "organizationUserCompositeRole">;
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region plugins/organization-rbac/models/OrganizationAppointment.d.mts
|
|
48
|
+
declare const OrganizationAppointment: _yongdall_model3.ModelTable<{
|
|
49
|
+
id: imodel20.FieldDefine<"uuid", false, false>;
|
|
50
|
+
label: imodel20.FieldDefine<"string", false, false>;
|
|
51
|
+
description: imodel20.FieldDefine<"string", false, true>;
|
|
52
|
+
createdAt: imodel20.FieldDefine<"date", false, false>;
|
|
53
|
+
updatedAt: imodel20.FieldDefine<"date", false, false>;
|
|
54
|
+
}, "organizationAppointment">;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region plugins/organization-rbac/models/OrganizationMember.d.mts
|
|
57
|
+
declare const OrganizationMember: _yongdall_model3.ModelTable<{
|
|
58
|
+
id: imodel20.FieldDefine<"uuid", false, false>;
|
|
59
|
+
userId: imodel20.FieldDefine<"uuid", false, false>;
|
|
60
|
+
organizationId: imodel20.FieldDefine<"uuid", false, false>;
|
|
61
|
+
appointmentId: imodel20.FieldDefine<"uuid", false, true>;
|
|
62
|
+
default: imodel20.FieldDefine<"bool", false, false>;
|
|
63
|
+
createdAt: imodel20.FieldDefine<"date", false, false>;
|
|
64
|
+
updatedAt: imodel20.FieldDefine<"date", false, false>;
|
|
65
|
+
}, "organizationMember">;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region plugins/organization-rbac/models/OrganizationUserRole.d.mts
|
|
68
|
+
declare const OrganizationUserRole: _yongdall_model3.ModelTable<{
|
|
69
|
+
userId: imodel20.FieldDefine<"uuid", false, false>;
|
|
70
|
+
organizationId: imodel20.FieldDefine<"uuid", false, false>;
|
|
71
|
+
roleId: imodel20.FieldDefine<"uuid", false, false>;
|
|
72
|
+
createdAt: imodel20.FieldDefine<"date", false, false>;
|
|
73
|
+
}, "organizationUserRole">;
|
|
64
74
|
//#endregion
|
|
65
75
|
//#region plugins/organization-rbac/index.d.mts
|
|
66
76
|
/** 所在组织 */
|
|
67
|
-
declare const
|
|
77
|
+
declare const getOrganizations: (userId: string | null) => Promise<Set<unknown>>;
|
|
68
78
|
/** 角色 */
|
|
79
|
+
declare const getOrganizationRoleIds: (userId: string | null) => Promise<{
|
|
80
|
+
[k: string]: Set<string>;
|
|
81
|
+
}>;
|
|
82
|
+
declare const getOrganizationPermissions: (userId: string | null) => Promise<Record<string, Set<string>>>;
|
|
83
|
+
declare const getOrganizationAllPermissions: (userId: string | null) => Promise<Set<string>>;
|
|
84
|
+
/** @deprecated */
|
|
85
|
+
declare const useOrganizations: () => Promise<Set<unknown>>;
|
|
86
|
+
/** @deprecated */
|
|
69
87
|
declare const useOrganizationRoleIds: () => Promise<{
|
|
70
88
|
[k: string]: Set<string>;
|
|
71
89
|
}>;
|
|
90
|
+
/** @deprecated */
|
|
72
91
|
declare const useOrganizationPermissions: () => Promise<Record<string, Set<string>>>;
|
|
92
|
+
/** @deprecated */
|
|
73
93
|
declare const useOrganizationAllPermissions: () => Promise<Set<string>>;
|
|
74
94
|
//#endregion
|
|
75
|
-
export { OrganizationAppointment, OrganizationMember, OrganizationUserRole, useOrganizationAllPermissions, useOrganizationPermissions, useOrganizationRoleIds, useOrganizations };
|
|
95
|
+
export { CompositeRole, OrganizationAppointment, OrganizationCompositeRole, OrganizationMember, OrganizationUserCompositeRole, OrganizationUserRole, getOrganizationAllPermissions, getOrganizationPermissions, getOrganizationRoleIds, getOrganizations, useOrganizationAllPermissions, useOrganizationPermissions, useOrganizationRoleIds, useOrganizations };
|
package/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as useOrganizationAllPermissions, c as useOrganizations, d as OrganizationAppointment, f as CompositeRole, i as getOrganizations, l as OrganizationUserRole, m as OrganizationCompositeRole, n as getOrganizationPermissions, o as useOrganizationPermissions, p as OrganizationUserCompositeRole, r as getOrganizationRoleIds, s as useOrganizationRoleIds, t as getOrganizationAllPermissions, u as OrganizationMember } from "./organization-rbac-CVRP1FKi.mjs";
|
|
2
2
|
|
|
3
|
-
export { OrganizationAppointment, OrganizationMember, OrganizationUserRole, useOrganizationAllPermissions, useOrganizationPermissions, useOrganizationRoleIds, useOrganizations };
|
|
3
|
+
export { CompositeRole, OrganizationAppointment, OrganizationCompositeRole, OrganizationMember, OrganizationUserCompositeRole, OrganizationUserRole, getOrganizationAllPermissions, getOrganizationPermissions, getOrganizationRoleIds, getOrganizations, useOrganizationAllPermissions, useOrganizationPermissions, useOrganizationRoleIds, useOrganizations };
|
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { createKeyStore } from "@yongdall/context";
|
|
2
|
+
import { Action, Query, Where, actions, createField, createModel, now, uuid } from "@yongdall/model";
|
|
3
|
+
import { ServerError, getModel, getUser } from "@yongdall/core";
|
|
4
|
+
import { useDatabase } from "@yongdall/connection";
|
|
5
|
+
import { findRolePermissions } from "@yongdall/role-permission";
|
|
6
|
+
import PluginMeta from "@yongdall/plugin-meta";
|
|
7
|
+
|
|
8
|
+
//#region plugins/organization-rbac/constants.mts
|
|
9
|
+
const { id: pluginId, database } = PluginMeta();
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region plugins/organization-rbac/models/OrganizationCompositeRole.mts
|
|
13
|
+
/**
|
|
14
|
+
* 组织用户角色模型
|
|
15
|
+
* @typedef {Object} OrganizationUserRole
|
|
16
|
+
* @property {string} userId - 用户ID,主键第一部分
|
|
17
|
+
* @property {string} organizationId - 组织ID,主键第二部分
|
|
18
|
+
* @property {string} roleId - 角色ID,主键第三部分
|
|
19
|
+
* @property {number} no - 编号
|
|
20
|
+
*/
|
|
21
|
+
const OrganizationCompositeRole = createModel("organizationCompositeRole", {
|
|
22
|
+
compositeRoleId: createField("uuid", {
|
|
23
|
+
nullable: false,
|
|
24
|
+
index: true,
|
|
25
|
+
label: "复合角色",
|
|
26
|
+
model: "compositeRole",
|
|
27
|
+
renderer: "document",
|
|
28
|
+
immutable: true,
|
|
29
|
+
primary: 1
|
|
30
|
+
}),
|
|
31
|
+
organizationId: createField("uuid", {
|
|
32
|
+
nullable: false,
|
|
33
|
+
index: true,
|
|
34
|
+
label: "组织",
|
|
35
|
+
model: "organization",
|
|
36
|
+
renderer: "document",
|
|
37
|
+
immutable: true,
|
|
38
|
+
primary: 2
|
|
39
|
+
}),
|
|
40
|
+
roleId: createField("uuid", {
|
|
41
|
+
nullable: false,
|
|
42
|
+
index: true,
|
|
43
|
+
label: "角色",
|
|
44
|
+
model: "role",
|
|
45
|
+
renderer: "document",
|
|
46
|
+
immutable: true,
|
|
47
|
+
primary: 3
|
|
48
|
+
}),
|
|
49
|
+
createdAt: createField("date", {
|
|
50
|
+
nullable: false,
|
|
51
|
+
default: now,
|
|
52
|
+
creating: now,
|
|
53
|
+
label: "创建日期"
|
|
54
|
+
})
|
|
55
|
+
}, {
|
|
56
|
+
permissions: [{
|
|
57
|
+
permission: "system:compositeRole",
|
|
58
|
+
fields: ["*"],
|
|
59
|
+
authorizations: [
|
|
60
|
+
"options",
|
|
61
|
+
"query",
|
|
62
|
+
"read",
|
|
63
|
+
"create",
|
|
64
|
+
"destroy"
|
|
65
|
+
]
|
|
66
|
+
}, {
|
|
67
|
+
permission: "system:compositeRole",
|
|
68
|
+
organizationField: "organizationId",
|
|
69
|
+
fields: ["*"],
|
|
70
|
+
authorizations: [
|
|
71
|
+
"options",
|
|
72
|
+
"query",
|
|
73
|
+
"read",
|
|
74
|
+
"create",
|
|
75
|
+
"update",
|
|
76
|
+
"destroy"
|
|
77
|
+
]
|
|
78
|
+
}],
|
|
79
|
+
database,
|
|
80
|
+
label: "组织复合角色配置",
|
|
81
|
+
hooks: { async afterCreate(conn, model, record) {
|
|
82
|
+
if (!record.organizationId) throw new ServerError("组织不存在");
|
|
83
|
+
if (!record.roleId) throw new ServerError("角色不存在");
|
|
84
|
+
const [compositeRole] = await conn.call(new Query(CompositeRole).where({ id: record.compositeRoleId }).limit(1));
|
|
85
|
+
if (!compositeRole) throw new Error("复合角色不存在");
|
|
86
|
+
if (!compositeRole.organizationId) return;
|
|
87
|
+
const organizationModel = await getModel("organization");
|
|
88
|
+
if (organizationModel) {
|
|
89
|
+
const [organization] = await useDatabase(organizationModel.databaseId).call(new Query(organizationModel).where({
|
|
90
|
+
id: record.organizationId,
|
|
91
|
+
mainId: compositeRole.organizationId
|
|
92
|
+
}).limit(1));
|
|
93
|
+
if (!organization) throw new ServerError("请选择关联组织");
|
|
94
|
+
}
|
|
95
|
+
const roleModel = await getModel("role");
|
|
96
|
+
if (roleModel?.fields.open) {
|
|
97
|
+
const [role] = await useDatabase(roleModel.databaseId).call(new Query(roleModel).where({
|
|
98
|
+
id: record.organizationId,
|
|
99
|
+
open: true
|
|
100
|
+
}).limit(1));
|
|
101
|
+
if (!role) throw new ServerError("请选择有效角色");
|
|
102
|
+
}
|
|
103
|
+
} }
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region plugins/organization-rbac/models/OrganizationUserCompositeRole.mts
|
|
108
|
+
/**
|
|
109
|
+
* 组织用户角色模型
|
|
110
|
+
* @typedef {Object} OrganizationUserRole
|
|
111
|
+
* @property {string} userId - 用户ID,主键第一部分
|
|
112
|
+
* @property {string} organizationId - 组织ID,主键第二部分
|
|
113
|
+
* @property {string} roleId - 角色ID,主键第三部分
|
|
114
|
+
* @property {number} no - 编号
|
|
115
|
+
*/
|
|
116
|
+
const OrganizationUserCompositeRole = createModel("organizationUserCompositeRole", {
|
|
117
|
+
userId: createField("uuid", {
|
|
118
|
+
nullable: false,
|
|
119
|
+
index: true,
|
|
120
|
+
label: "用户",
|
|
121
|
+
model: "user",
|
|
122
|
+
renderer: "document",
|
|
123
|
+
immutable: true,
|
|
124
|
+
primary: 1
|
|
125
|
+
}),
|
|
126
|
+
organizationId: createField("uuid", {
|
|
127
|
+
nullable: false,
|
|
128
|
+
index: true,
|
|
129
|
+
label: "组织",
|
|
130
|
+
model: "organization",
|
|
131
|
+
renderer: "document",
|
|
132
|
+
immutable: true
|
|
133
|
+
}),
|
|
134
|
+
compositeRoleId: createField("uuid", {
|
|
135
|
+
nullable: false,
|
|
136
|
+
index: true,
|
|
137
|
+
label: "角色",
|
|
138
|
+
model: "compositeRole",
|
|
139
|
+
renderer: "document",
|
|
140
|
+
immutable: true,
|
|
141
|
+
primary: 2
|
|
142
|
+
}),
|
|
143
|
+
createdAt: createField("date", {
|
|
144
|
+
nullable: false,
|
|
145
|
+
default: now,
|
|
146
|
+
creating: now,
|
|
147
|
+
label: "创建日期"
|
|
148
|
+
}),
|
|
149
|
+
updatedAt: createField("date", {
|
|
150
|
+
nullable: false,
|
|
151
|
+
default: now,
|
|
152
|
+
updating: now,
|
|
153
|
+
label: "最后更新日期"
|
|
154
|
+
})
|
|
155
|
+
}, {
|
|
156
|
+
database,
|
|
157
|
+
label: "用户复合角色",
|
|
158
|
+
permissions: [{
|
|
159
|
+
permission: "system:compositeRole",
|
|
160
|
+
fields: ["*"],
|
|
161
|
+
authorizations: [
|
|
162
|
+
"options",
|
|
163
|
+
"query",
|
|
164
|
+
"read",
|
|
165
|
+
"create",
|
|
166
|
+
"destroy"
|
|
167
|
+
]
|
|
168
|
+
}, {
|
|
169
|
+
permission: "system:compositeRole",
|
|
170
|
+
organizationField: "organizationId",
|
|
171
|
+
fields: ["*"],
|
|
172
|
+
authorizations: [
|
|
173
|
+
"options",
|
|
174
|
+
"query",
|
|
175
|
+
"read",
|
|
176
|
+
"create",
|
|
177
|
+
"update",
|
|
178
|
+
"destroy"
|
|
179
|
+
]
|
|
180
|
+
}],
|
|
181
|
+
hooks: { async afterCreate(conn, model, record) {
|
|
182
|
+
const [compositeRole] = await conn.call(new Query(CompositeRole).where({ id: record.compositeRoleId }).limit(1));
|
|
183
|
+
if (!compositeRole) throw new ServerError("复合角色不存在");
|
|
184
|
+
if ((compositeRole.organizationId || null) === (record.organizationId || null)) return;
|
|
185
|
+
throw new ServerError("复合角色与组织不匹配");
|
|
186
|
+
} }
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region plugins/organization-rbac/models/CompositeRole.mts
|
|
191
|
+
const CompositeRole = createModel("compositeRole", {
|
|
192
|
+
id: createField("uuid", {
|
|
193
|
+
nullable: false,
|
|
194
|
+
default: uuid,
|
|
195
|
+
primary: 1,
|
|
196
|
+
uncreatable: true,
|
|
197
|
+
layout: { hidden: true }
|
|
198
|
+
}),
|
|
199
|
+
label: createField("string", {
|
|
200
|
+
size: 255,
|
|
201
|
+
nullable: false,
|
|
202
|
+
default: "",
|
|
203
|
+
label: "名称",
|
|
204
|
+
layout: { colSpan: 6 }
|
|
205
|
+
}),
|
|
206
|
+
organizationId: createField("uuid", {
|
|
207
|
+
nullable: true,
|
|
208
|
+
index: true,
|
|
209
|
+
label: "组织",
|
|
210
|
+
model: "organization",
|
|
211
|
+
renderer: "document",
|
|
212
|
+
immutable: true,
|
|
213
|
+
source: { search: "internal=0" }
|
|
214
|
+
}),
|
|
215
|
+
description: createField("text", {
|
|
216
|
+
nullable: true,
|
|
217
|
+
label: "描述"
|
|
218
|
+
}),
|
|
219
|
+
createdAt: createField("date", {
|
|
220
|
+
nullable: false,
|
|
221
|
+
default: now,
|
|
222
|
+
creating: now,
|
|
223
|
+
label: "创建日期"
|
|
224
|
+
}),
|
|
225
|
+
updatedAt: createField("date", {
|
|
226
|
+
nullable: false,
|
|
227
|
+
default: now,
|
|
228
|
+
updating: now,
|
|
229
|
+
label: "最后更新日期"
|
|
230
|
+
})
|
|
231
|
+
}, {
|
|
232
|
+
database,
|
|
233
|
+
labelField: "label",
|
|
234
|
+
label: "复合角色",
|
|
235
|
+
permissions: [{
|
|
236
|
+
permission: "system:compositeRole",
|
|
237
|
+
fields: ["*"],
|
|
238
|
+
authorizations: [
|
|
239
|
+
"options",
|
|
240
|
+
"query",
|
|
241
|
+
"read",
|
|
242
|
+
"create",
|
|
243
|
+
"update",
|
|
244
|
+
"destroy",
|
|
245
|
+
"add",
|
|
246
|
+
"remove"
|
|
247
|
+
]
|
|
248
|
+
}, {
|
|
249
|
+
permission: "system:compositeRole",
|
|
250
|
+
organizationField: "organizationId",
|
|
251
|
+
fields: ["*"],
|
|
252
|
+
authorizations: [
|
|
253
|
+
"options",
|
|
254
|
+
"query",
|
|
255
|
+
"read",
|
|
256
|
+
"create",
|
|
257
|
+
"update",
|
|
258
|
+
"destroy",
|
|
259
|
+
"add",
|
|
260
|
+
"remove"
|
|
261
|
+
]
|
|
262
|
+
}],
|
|
263
|
+
hooks: {
|
|
264
|
+
async afterCreate(conn, model, { organizationId }) {
|
|
265
|
+
if (!organizationId) return;
|
|
266
|
+
const organizationModel = await getModel("organization");
|
|
267
|
+
if (!organizationModel) return;
|
|
268
|
+
const [organization] = await useDatabase(organizationModel.databaseId).call(new Query(organizationModel).where({
|
|
269
|
+
id: organizationId,
|
|
270
|
+
internal: false
|
|
271
|
+
}).limit(1));
|
|
272
|
+
if (organization) return;
|
|
273
|
+
throw new ServerError("请选择外部组织");
|
|
274
|
+
},
|
|
275
|
+
async afterDelete(conn, model, record, update) {
|
|
276
|
+
const list = [conn.call(Action.delete(OrganizationUserCompositeRole, Where.and({ compositeRoleId: record.id })))];
|
|
277
|
+
if (!update) list.push(conn.call(Action.delete(OrganizationCompositeRole, Where.and({ compositeRoleId: record.id }))));
|
|
278
|
+
await Promise.all(list);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region plugins/organization-rbac/models/OrganizationAppointment.mts
|
|
285
|
+
const OrganizationAppointment = createModel("organizationAppointment", {
|
|
286
|
+
id: createField("uuid", {
|
|
287
|
+
nullable: false,
|
|
288
|
+
primary: 1,
|
|
289
|
+
default: uuid,
|
|
290
|
+
uncreatable: true,
|
|
291
|
+
immutable: true
|
|
292
|
+
}),
|
|
293
|
+
label: createField("string", {
|
|
294
|
+
nullable: false,
|
|
295
|
+
label: "职务名称"
|
|
296
|
+
}),
|
|
297
|
+
description: createField("string", {
|
|
298
|
+
nullable: true,
|
|
299
|
+
label: "描述"
|
|
300
|
+
}),
|
|
301
|
+
createdAt: createField("date", {
|
|
302
|
+
nullable: false,
|
|
303
|
+
default: now,
|
|
304
|
+
creating: now,
|
|
305
|
+
label: "创建日期"
|
|
306
|
+
}),
|
|
307
|
+
updatedAt: createField("date", {
|
|
308
|
+
nullable: false,
|
|
309
|
+
default: now,
|
|
310
|
+
updating: now,
|
|
311
|
+
label: "最后更新日期"
|
|
312
|
+
})
|
|
313
|
+
}, {
|
|
314
|
+
database,
|
|
315
|
+
permissions: [{
|
|
316
|
+
permission: "system:organization",
|
|
317
|
+
fields: "*",
|
|
318
|
+
authorizations: [
|
|
319
|
+
"query",
|
|
320
|
+
"read",
|
|
321
|
+
"create",
|
|
322
|
+
"update",
|
|
323
|
+
"destroy",
|
|
324
|
+
"add",
|
|
325
|
+
"remove"
|
|
326
|
+
]
|
|
327
|
+
}]
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region plugins/organization-rbac/models/OrganizationMember.mts
|
|
332
|
+
const OrganizationMember = createModel("organizationMember", {
|
|
333
|
+
id: createField("uuid", {
|
|
334
|
+
nullable: false,
|
|
335
|
+
index: true,
|
|
336
|
+
primary: 1,
|
|
337
|
+
default: uuid,
|
|
338
|
+
uncreatable: true,
|
|
339
|
+
immutable: true
|
|
340
|
+
}),
|
|
341
|
+
userId: createField("uuid", {
|
|
342
|
+
nullable: false,
|
|
343
|
+
index: true,
|
|
344
|
+
label: "用户",
|
|
345
|
+
model: "user",
|
|
346
|
+
renderer: "document",
|
|
347
|
+
immutable: true,
|
|
348
|
+
layout: { rowSpan: 6 }
|
|
349
|
+
}),
|
|
350
|
+
organizationId: createField("uuid", {
|
|
351
|
+
nullable: false,
|
|
352
|
+
index: true,
|
|
353
|
+
label: "组织",
|
|
354
|
+
model: "organization",
|
|
355
|
+
renderer: "document",
|
|
356
|
+
immutable: true,
|
|
357
|
+
layout: { rowSpan: 6 }
|
|
358
|
+
}),
|
|
359
|
+
appointmentId: createField("uuid", {
|
|
360
|
+
nullable: true,
|
|
361
|
+
index: true,
|
|
362
|
+
label: "职务",
|
|
363
|
+
model: "appointment",
|
|
364
|
+
renderer: "document",
|
|
365
|
+
layout: { rowSpan: 6 }
|
|
366
|
+
}),
|
|
367
|
+
default: createField("bool", {
|
|
368
|
+
nullable: false,
|
|
369
|
+
default: false,
|
|
370
|
+
label: "默认职务"
|
|
371
|
+
}),
|
|
372
|
+
createdAt: createField("date", {
|
|
373
|
+
nullable: false,
|
|
374
|
+
default: now,
|
|
375
|
+
creating: now,
|
|
376
|
+
label: "创建日期"
|
|
377
|
+
}),
|
|
378
|
+
updatedAt: createField("date", {
|
|
379
|
+
nullable: false,
|
|
380
|
+
default: now,
|
|
381
|
+
updating: now,
|
|
382
|
+
label: "最后更新日期"
|
|
383
|
+
})
|
|
384
|
+
}, {
|
|
385
|
+
database,
|
|
386
|
+
indexes: [{
|
|
387
|
+
fields: [
|
|
388
|
+
"userId",
|
|
389
|
+
"organizationId",
|
|
390
|
+
"appointmentId"
|
|
391
|
+
],
|
|
392
|
+
unique: true
|
|
393
|
+
}],
|
|
394
|
+
permissions: [{
|
|
395
|
+
permission: "system:user",
|
|
396
|
+
fields: "*",
|
|
397
|
+
authorizations: [
|
|
398
|
+
"query",
|
|
399
|
+
"read",
|
|
400
|
+
"create",
|
|
401
|
+
"update",
|
|
402
|
+
"destroy",
|
|
403
|
+
"add",
|
|
404
|
+
"remove"
|
|
405
|
+
]
|
|
406
|
+
}],
|
|
407
|
+
hooks: {
|
|
408
|
+
async afterCreate(conn, Model, record) {
|
|
409
|
+
if (!record.default) return;
|
|
410
|
+
await conn.call(actions.update(Model, { default: false }, Where.and("organizationId", "=", record.organizationId, true).and("userId", record.userId)));
|
|
411
|
+
},
|
|
412
|
+
async afterUpdate(conn, Model, record, oldRecord) {
|
|
413
|
+
if (!record.default) return;
|
|
414
|
+
if (oldRecord.default) return;
|
|
415
|
+
await conn.call(actions.update(Model, { default: false }, Where.and("organizationId", "=", record.organizationId, true).and("userId", record.userId)));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region plugins/organization-rbac/models/OrganizationUserRole.mts
|
|
422
|
+
const OrganizationUserRole = createModel("organizationUserRole", {
|
|
423
|
+
userId: createField("uuid", {
|
|
424
|
+
nullable: false,
|
|
425
|
+
index: true,
|
|
426
|
+
label: "用户",
|
|
427
|
+
model: "user",
|
|
428
|
+
renderer: "document",
|
|
429
|
+
immutable: true,
|
|
430
|
+
primary: 1
|
|
431
|
+
}),
|
|
432
|
+
organizationId: createField("uuid", {
|
|
433
|
+
nullable: false,
|
|
434
|
+
index: true,
|
|
435
|
+
label: "组织",
|
|
436
|
+
model: "organization",
|
|
437
|
+
renderer: "document",
|
|
438
|
+
immutable: true,
|
|
439
|
+
primary: 2
|
|
440
|
+
}),
|
|
441
|
+
roleId: createField("uuid", {
|
|
442
|
+
nullable: false,
|
|
443
|
+
index: true,
|
|
444
|
+
label: "角色",
|
|
445
|
+
model: "role",
|
|
446
|
+
renderer: "document",
|
|
447
|
+
immutable: true,
|
|
448
|
+
primary: 3
|
|
449
|
+
}),
|
|
450
|
+
createdAt: createField("date", {
|
|
451
|
+
nullable: false,
|
|
452
|
+
default: now,
|
|
453
|
+
creating: now,
|
|
454
|
+
label: "创建日期"
|
|
455
|
+
})
|
|
456
|
+
}, {
|
|
457
|
+
database,
|
|
458
|
+
permissions: [{
|
|
459
|
+
permission: "system:user",
|
|
460
|
+
fields: "*",
|
|
461
|
+
authorizations: [
|
|
462
|
+
"query",
|
|
463
|
+
"read",
|
|
464
|
+
"create",
|
|
465
|
+
"destroy"
|
|
466
|
+
]
|
|
467
|
+
}]
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
//#endregion
|
|
471
|
+
//#region plugins/organization-rbac/index.mts
|
|
472
|
+
/** 所在组织 */
|
|
473
|
+
const getOrganizations = createKeyStore(async (userId) => {
|
|
474
|
+
if (!userId) return /* @__PURE__ */ new Set();
|
|
475
|
+
const relations = await useDatabase(OrganizationMember.databaseId).call(new Query(OrganizationMember).select(["organizationId"]).where("userId", userId));
|
|
476
|
+
return new Set(relations.map((v) => v.organizationId));
|
|
477
|
+
}, (user) => user || "");
|
|
478
|
+
/** 角色 */
|
|
479
|
+
const getOrganizationRoleIds = createKeyStore(async (userId) => {
|
|
480
|
+
const compositeRoleIds = new Query(OrganizationUserCompositeRole).select("compositeRoleId").where("userId", "=", userId);
|
|
481
|
+
const list = await Promise.all([useDatabase(OrganizationUserRole.databaseId).call(new Query(OrganizationUserRole).select(["organizationId", "roleId"]).where("userId", userId)), useDatabase(OrganizationCompositeRole.databaseId).call(new Query(OrganizationCompositeRole).select(["organizationId", "roleId"]).where("compositeRoleId", "in", compositeRoleIds))]);
|
|
482
|
+
return Object.fromEntries(Object.entries(Object.groupBy(list.flat(), (v) => v.organizationId)).map(([organizationId, list]) => [organizationId, new Set(list?.map((v) => v.roleId))]));
|
|
483
|
+
}, (user) => user || "");
|
|
484
|
+
const getOrganizationPermissions = createKeyStore(async (userId) => {
|
|
485
|
+
const roleIds = await getOrganizationRoleIds(userId);
|
|
486
|
+
const allRoleIds = [...new Set(Object.values(roleIds).flatMap((v) => [...v]))];
|
|
487
|
+
const permissions = Object.create(null);
|
|
488
|
+
if (!allRoleIds.length) return permissions;
|
|
489
|
+
const values = await findRolePermissions(allRoleIds);
|
|
490
|
+
const list = Object.fromEntries(Object.entries(Object.groupBy(values, (l) => l.roleId)).map(([k, v]) => [k, v?.map((v) => v.permission)]));
|
|
491
|
+
for (const [organization, roleSet] of Object.entries(roleIds)) {
|
|
492
|
+
const s = new Set([...roleSet].flatMap((v) => list[v] || []));
|
|
493
|
+
if (!s.size) continue;
|
|
494
|
+
permissions[organization] = s;
|
|
495
|
+
}
|
|
496
|
+
return permissions;
|
|
497
|
+
}, (user) => user || "");
|
|
498
|
+
const getOrganizationAllPermissions = createKeyStore(async (userId) => {
|
|
499
|
+
const v = await getOrganizationPermissions(userId);
|
|
500
|
+
return new Set(Object.values(v).flatMap((v) => [...v]));
|
|
501
|
+
}, (user) => user || "");
|
|
502
|
+
/** @deprecated */
|
|
503
|
+
const useOrganizations = () => getUser().then(getOrganizations);
|
|
504
|
+
/** @deprecated */
|
|
505
|
+
const useOrganizationRoleIds = () => getUser().then(getOrganizationRoleIds);
|
|
506
|
+
/** @deprecated */
|
|
507
|
+
const useOrganizationPermissions = () => getUser().then(getOrganizationPermissions);
|
|
508
|
+
/** @deprecated */
|
|
509
|
+
const useOrganizationAllPermissions = () => getUser().then(getOrganizationAllPermissions);
|
|
510
|
+
|
|
511
|
+
//#endregion
|
|
512
|
+
export { useOrganizationAllPermissions as a, useOrganizations as c, OrganizationAppointment as d, CompositeRole as f, getOrganizations as i, OrganizationUserRole as l, OrganizationCompositeRole as m, getOrganizationPermissions as n, useOrganizationPermissions as o, OrganizationUserCompositeRole as p, getOrganizationRoleIds as r, useOrganizationRoleIds as s, getOrganizationAllPermissions as t, OrganizationMember as u };
|
|
513
|
+
//# sourceMappingURL=organization-rbac-CVRP1FKi.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization-rbac-CVRP1FKi.mjs","names":[],"sources":["../../plugins/organization-rbac/constants.mts","../../plugins/organization-rbac/models/OrganizationCompositeRole.mts","../../plugins/organization-rbac/models/OrganizationUserCompositeRole.mts","../../plugins/organization-rbac/models/CompositeRole.mts","../../plugins/organization-rbac/models/OrganizationAppointment.mts","../../plugins/organization-rbac/models/OrganizationMember.mts","../../plugins/organization-rbac/models/OrganizationUserRole.mts","../../plugins/organization-rbac/index.mts"],"sourcesContent":["import PluginMeta from '@yongdall/plugin-meta';\nexport const {\n\tid: pluginId,\n\tdatabase: database,\n} = PluginMeta();\n","import { actions, createField, createModel, now, Query, uuid, Where } from '@yongdall/model';\nimport { database } from '../constants.mts';\nimport { CompositeRole } from './CompositeRole.mts';\nimport { getModel, ServerError } from '@yongdall/core';\nimport { useDatabase } from '@yongdall/connection';\n\n/**\n * 组织用户角色模型\n * @typedef {Object} OrganizationUserRole\n * @property {string} userId - 用户ID,主键第一部分\n * @property {string} organizationId - 组织ID,主键第二部分\n * @property {string} roleId - 角色ID,主键第三部分\n * @property {number} no - 编号\n */\nexport const OrganizationCompositeRole = createModel('organizationCompositeRole', {\n\tcompositeRoleId: createField('uuid', { nullable: false, index: true, label: '复合角色', model: 'compositeRole', renderer: 'document', immutable: true, primary: 1 }),\n\torganizationId: createField('uuid', { nullable: false, index: true, label: '组织', model: 'organization', renderer: 'document', immutable: true, primary: 2 }),\n\troleId: createField('uuid', { nullable: false, index: true, label: '角色', model: 'role', renderer: 'document', immutable: true, primary: 3 }),\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n}, {\n\n\tpermissions: [\n\t\t{ permission: 'system:compositeRole', fields: ['*'], authorizations: ['options', 'query', 'read', 'create', 'destroy'] },\n\t\t{ permission: 'system:compositeRole', organizationField: 'organizationId', fields: ['*'], authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy'] },\n\t],\n\tdatabase,\n\tlabel: '组织复合角色配置',\n\thooks: {\n\t\tasync afterCreate(conn, model, record) {\n\t\t\tif (!record.organizationId) { throw new ServerError('组织不存在') }\n\t\t\tif (!record.roleId) { throw new ServerError('角色不存在') }\n\t\t\tconst [compositeRole] = await conn.call(\n\t\t\t\tnew Query(CompositeRole).where({ id: record.compositeRoleId }).limit(1)\n\t\t\t)\n\t\t\tif (!compositeRole) {\n\t\t\t\tthrow new Error('复合角色不存在')\n\t\t\t}\n\t\t\tif (!compositeRole.organizationId) { return }\n\t\t\tconst organizationModel = await getModel('organization')\n\t\t\tif (organizationModel) {\n\t\t\t\tconst [organization] = await useDatabase(organizationModel.databaseId).call(\n\t\t\t\t\tnew Query(organizationModel).where({ id: record.organizationId, mainId: compositeRole.organizationId }).limit(1)\n\t\t\t\t)\n\t\t\t\tif (!organization) {\n\t\t\t\t\tthrow new ServerError('请选择关联组织');\n\t\t\t\t}\n\n\t\t\t}\n\t\t\tconst roleModel = await getModel('role')\n\t\t\tif (roleModel?.fields.open) {\n\t\t\t\tconst [role] = await useDatabase(roleModel.databaseId).call(\n\t\t\t\t\tnew Query(roleModel).where({ id: record.organizationId, open: true }).limit(1)\n\t\t\t\t)\n\t\t\t\tif (!role) {\n\t\t\t\t\tthrow new ServerError('请选择有效角色');\n\t\t\t\t}\n\n\t\t\t}\n\t\t},\n\t}\n});\n","import { actions, createField, createModel, now, Query, uuid, Where} from '@yongdall/model';\nimport { database } from '../constants.mts';\nimport { CompositeRole } from './CompositeRole.mts';\nimport { ServerError } from '@yongdall/core';\n\n/**\n * 组织用户角色模型\n * @typedef {Object} OrganizationUserRole\n * @property {string} userId - 用户ID,主键第一部分\n * @property {string} organizationId - 组织ID,主键第二部分\n * @property {string} roleId - 角色ID,主键第三部分\n * @property {number} no - 编号\n */\nexport const OrganizationUserCompositeRole = createModel('organizationUserCompositeRole', {\n\tuserId: createField('uuid', { nullable: false, index: true, label: '用户', model: 'user', renderer: 'document', immutable: true, primary: 1 }),\n\torganizationId: createField('uuid', { nullable: false, index: true, label: '组织', model: 'organization', renderer: 'document', immutable: true }),\n\tcompositeRoleId: createField('uuid', { nullable: false, index: true, label: '角色', model: 'compositeRole', renderer: 'document', immutable: true, primary: 2 }),\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('date', { nullable: false, default: now, updating: now, label: '最后更新日期' }),\n},{\n\tdatabase,\n\tlabel: '用户复合角色',\n\n\tpermissions: [\n\t\t{ permission: 'system:compositeRole', fields: ['*'], authorizations: ['options', 'query', 'read', 'create', 'destroy'] },\n\t\t{ permission: 'system:compositeRole', organizationField: 'organizationId', fields: ['*'], authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy'] },\n\t],\n\thooks: {\n\t\tasync afterCreate(conn, model, record) {\n\t\t\tconst [compositeRole] = await conn.call(\n\t\t\t\tnew Query(CompositeRole).where({ id: record.compositeRoleId }).limit(1)\n\t\t\t)\n\t\t\tif (!compositeRole) {\n\t\t\t\tthrow new ServerError('复合角色不存在')\n\t\t\t}\n\t\t\tif ((compositeRole.organizationId || null) === (record.organizationId || null)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new ServerError('复合角色与组织不匹配');\n\t\t},\n\t}\n});\n","import { Action, actions, createField, createModel, now, Query, uuid, Where } from '@yongdall/model';\nimport { database } from '../constants.mts';\nimport { getModel, ServerError } from '@yongdall/core';\nimport { useDatabase } from '@yongdall/connection';\nimport { OrganizationCompositeRole } from './OrganizationCompositeRole.mts';\nimport { OrganizationUserCompositeRole } from './OrganizationUserCompositeRole.mts';\n\n\nexport const CompositeRole = createModel('compositeRole', {\n\tid: createField('uuid', { nullable: false, default: uuid, primary: 1, uncreatable: true, layout: { hidden: true } }),\n\tlabel: createField('string', { size: 255, nullable: false, default: '', label: '名称', layout: { colSpan: 6 } }),\n\torganizationId: createField('uuid', { nullable: true, index: true, label: '组织', model: 'organization', renderer: 'document', immutable: true, source: { search: 'internal=0' } }),\n\tdescription: createField('text', { nullable: true, label: '描述' }),\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('date', { nullable: false, default: now, updating: now, label: '最后更新日期' }),\n}, {\n\tdatabase,\n\tlabelField: 'label',\n\tlabel: '复合角色',\n\n\tpermissions: [\n\t\t{ permission: 'system:compositeRole', fields: ['*'], authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t\t{ permission: 'system:compositeRole', organizationField: 'organizationId', fields: ['*'], authorizations: ['options', 'query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t],\n\thooks: {\n\t\tasync afterCreate(conn, model, { organizationId }) {\n\t\t\tif (!organizationId) { return; }\n\t\t\tconst organizationModel = await getModel('organization')\n\t\t\tif (!organizationModel) { return; }\n\t\t\tconst [organization] = await useDatabase(organizationModel.databaseId).call(\n\t\t\t\tnew Query(organizationModel).where({ id: organizationId, internal: false }).limit(1)\n\t\t\t)\n\t\t\tif (organization) { return; }\n\t\t\tthrow new ServerError('请选择外部组织');\n\t\t},\n\t\tasync afterDelete(conn, model, record, update) {\n\t\t\tconst list = [\n\t\t\t\tconn.call(Action.delete(OrganizationUserCompositeRole, Where.and({ compositeRoleId: record.id })))\n\t\t\t]\n\n\t\t\tif (!update) {\n\t\t\t\tlist.push(\n\t\t\t\t\tconn.call(Action.delete(OrganizationCompositeRole, Where.and({ compositeRoleId: record.id })))\n\t\t\t\t)\n\t\t\t}\n\t\t\tawait Promise.all(list)\n\t\t},\n\t}\n});\n","import { createField, createModel, now, uuid } from '@yongdall/model';\nimport { database } from '../constants.mts';\n\n\n\n// export const OrganizationAppointmentRole = createModel('organizationAppointmentRole', {\n// \tappointmentId: createField('uuid', { nullable: false, index: true, label: '职务', model: 'appointment', renderer: 'document', immutable: true, primary: 1 }),\n// \troleId: createField('uuid', { nullable: false, index: true, label: '角色', model: 'role', renderer: 'document', immutable: true, primary: 2 }),\n// \tno: createField('i32', { nullable: false, default: 0 }),\n// });\n\nexport const OrganizationAppointment = createModel('organizationAppointment', {\n\tid: createField('uuid', { nullable: false, primary: 1, default: uuid, uncreatable: true, immutable: true }),\n\n\tlabel: createField('string', { nullable: false, label: '职务名称' }),\n\tdescription: createField('string', { nullable: true, label: '描述' }),\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('date', { nullable: false, default: now, updating: now, label: '最后更新日期' }),\n\n\t// roles: createField(OrganizationAppointmentRole, { \n\t// \tarray: true, \n\t// \tconstraints: { appointmentId: { field: 'id' }, no: { noField: true } }, \n\t// \tlabel: '角色列表' \n\t// }),\n}, {\n\tdatabase,\n\n\tpermissions: [\n\t\t{ permission: 'system:organization', fields: '*', authorizations: ['query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t],\n});\n","import { actions, createField, createModel, now, uuid, Where} from '@yongdall/model';\nimport { database } from '../constants.mts';\n\n\nexport const OrganizationMember = createModel('organizationMember', {\n\tid: createField('uuid', { nullable: false, index: true, primary: 1, default: uuid, uncreatable: true, immutable: true }),\n\n\tuserId: createField('uuid', { nullable: false, index: true, label: '用户', model: 'user', renderer: 'document', immutable: true, layout: { rowSpan: 6 } }),\n\torganizationId: createField('uuid', { nullable: false, index: true, label: '组织', model: 'organization', renderer: 'document', immutable: true, layout: { rowSpan: 6 } }),\n\tappointmentId: createField('uuid', { nullable: true, index: true, label: '职务', model: 'appointment', renderer: 'document', layout: { rowSpan: 6 } }),\n\n\tdefault: createField('bool', { nullable: false, default: false, label: '默认职务' }),\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('date', { nullable: false, default: now, updating: now, label: '最后更新日期' }),\n\n}, {\n\tdatabase,\n\tindexes: [\n\t\t{ fields: ['userId', 'organizationId', 'appointmentId'], unique: true }\n\t],\n\tpermissions: [\n\t\t{ permission: 'system:user', fields: '*', authorizations: ['query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t],\n\thooks: {\n\t\tasync afterCreate(conn, Model, record) {\n\t\t\tif (!record.default) { return }\n\t\t\tawait conn.call(actions.update(\n\t\t\t\tModel,\n\t\t\t\t{ default: false },\n\t\t\t\tWhere.and('organizationId', '=', record.organizationId, true)\n\t\t\t\t\t.and('userId', record.userId),\n\t\t\t));\n\t\t},\n\n\t\tasync afterUpdate(conn, Model, record, oldRecord) {\n\t\t\tif (!record.default) { return }\n\t\t\tif (oldRecord.default) { return }\n\t\t\tawait conn.call(actions.update(\n\t\t\t\tModel,\n\t\t\t\t{ default: false },\n\t\t\t\tWhere.and('organizationId', '=', record.organizationId, true)\n\t\t\t\t\t.and('userId', record.userId),\n\t\t\t));\n\t\t},\n\t}\n});\n","import { actions, createField, createModel, now, uuid, Where} from '@yongdall/model';\nimport { database } from '../constants.mts';\n\nexport const OrganizationUserRole = createModel('organizationUserRole', {\n\tuserId: createField('uuid', { nullable: false, index: true, label: '用户', model: 'user', renderer: 'document', immutable: true, primary: 1 }),\n\torganizationId: createField('uuid', { nullable: false, index: true, label: '组织', model: 'organization', renderer: 'document', immutable: true, primary: 2 }),\n\troleId: createField('uuid', { nullable: false, index: true, label: '角色', model: 'role', renderer: 'document', immutable: true, primary: 3 }),\n\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n\n},{\n\tdatabase,\n\tpermissions: [\n\t\t{ permission: 'system:user', fields: '*', authorizations: ['query', 'read', 'create', 'destroy'] },\n\t],\n});\n","import { createKeyStore } from '@yongdall/context';\nimport { Query } from '@yongdall/model';\nimport { getUser } from '@yongdall/core';\nimport { useDatabase } from '@yongdall/connection';\nimport { findRolePermissions } from '@yongdall/role-permission';\nimport { OrganizationCompositeRole, OrganizationMember, OrganizationUserCompositeRole, OrganizationUserRole } from './models/index.mts';\n\nexport * from './models/index.mts';\n\n\n/** 所在组织 */\nexport const getOrganizations = createKeyStore(async (userId: string | null) => {\n\tif (!userId) { return new Set(); }\n\tconst relations: { organizationId: string }[] = await useDatabase(OrganizationMember.databaseId).call(\n\t\tnew Query(OrganizationMember).select(['organizationId']).where('userId', userId)\n\t);\n\treturn new Set(relations.map(v => v.organizationId));\n}, user => user || '');\n\n\n/** 角色 */\nexport const getOrganizationRoleIds = createKeyStore(async (userId: string | null) => {\n\tconst compositeRoleIds = new Query(OrganizationUserCompositeRole).select('compositeRoleId').where('userId', '=', userId)\n\tconst list: { organizationId: number; roleId: string; }[][] = await Promise.all([\n\t\tuseDatabase(OrganizationUserRole.databaseId).call(\n\t\t\tnew Query(OrganizationUserRole).select(['organizationId', 'roleId'])\n\t\t\t\t.where('userId', userId)\n\t\t),\n\t\tuseDatabase(OrganizationCompositeRole.databaseId).call(\n\t\t\tnew Query(OrganizationCompositeRole).select(['organizationId', 'roleId'])\n\t\t\t\t.where('compositeRoleId', 'in', compositeRoleIds)\n\t\t)\n\t]);\n\n\treturn Object.fromEntries((Object.entries(Object.groupBy(list.flat(), v => v.organizationId))\n\t\t.map(([organizationId, list]) => [organizationId, new Set(list?.map(v => v.roleId))])))\n}, user => user || '');\n\n\nexport const getOrganizationPermissions = createKeyStore(async (userId: string | null) => {\n\tconst roleIds = await getOrganizationRoleIds(userId)\n\tconst allRoleIds = [...new Set(Object.values(roleIds).flatMap(v => [...v]))];\n\tconst permissions: Record<string, Set<string>> = Object.create(null);\n\tif (!allRoleIds.length) { return permissions; }\n\tconst values = await findRolePermissions(allRoleIds);\n\tconst list = Object.fromEntries(Object.entries(Object.groupBy(values, l => l.roleId)).map(([k, v]) => [k, v?.map(v => v.permission)]));\n\tfor (const [organization, roleSet] of Object.entries(roleIds)) {\n\t\tconst s = new Set([...roleSet].flatMap(v => list[v] || []));\n\t\tif (!s.size) { continue; }\n\t\tpermissions[organization] = s;\n\t}\n\treturn permissions;\n}, user => user || '');\n\n\n\nexport const getOrganizationAllPermissions = createKeyStore(async (userId: string | null) => {\n\tconst v = await getOrganizationPermissions(userId)\n\treturn new Set(Object.values(v).flatMap(v => [...v]));\n}, user => user || '');\n\n/** @deprecated */\nexport const useOrganizations = () => getUser().then(getOrganizations);\n/** @deprecated */\nexport const useOrganizationRoleIds = () => getUser().then(getOrganizationRoleIds);\n/** @deprecated */\nexport const useOrganizationPermissions = () => getUser().then(getOrganizationPermissions);\n/** @deprecated */\nexport const useOrganizationAllPermissions = () => getUser().then(getOrganizationAllPermissions);\n"],"mappings":";;;;;;;;AACA,MAAa,EACZ,IAAI,UACM,aACP,YAAY;;;;;;;;;;;;ACUhB,MAAa,4BAA4B,YAAY,6BAA6B;CACjF,iBAAiB,YAAY,QAAQ;EAAE,UAAU;EAAO,OAAO;EAAM,OAAO;EAAQ,OAAO;EAAiB,UAAU;EAAY,WAAW;EAAM,SAAS;EAAG,CAAC;CAChK,gBAAgB,YAAY,QAAQ;EAAE,UAAU;EAAO,OAAO;EAAM,OAAO;EAAM,OAAO;EAAgB,UAAU;EAAY,WAAW;EAAM,SAAS;EAAG,CAAC;CAC5J,QAAQ,YAAY,QAAQ;EAAE,UAAU;EAAO,OAAO;EAAM,OAAO;EAAM,OAAO;EAAQ,UAAU;EAAY,WAAW;EAAM,SAAS;EAAG,CAAC;CAE5I,WAAW,YAAY,QAAQ;EAAE,UAAU;EAAO,SAAS;EAAK,UAAU;EAAK,OAAO;EAAQ,CAAC;CAC/F,EAAE;CAEF,aAAa,CACZ;EAAE,YAAY;EAAwB,QAAQ,CAAC,IAAI;EAAE,gBAAgB;GAAC;GAAW;GAAS;GAAQ;GAAU;GAAU;EAAE,EACxH;EAAE,YAAY;EAAwB,mBAAmB;EAAkB,QAAQ,CAAC,IAAI;EAAE,gBAAgB;GAAC;GAAW;GAAS;GAAQ;GAAU;GAAU;GAAU;EAAE,CACvK;CACD;CACA,OAAO;CACP,OAAO,EACN,MAAM,YAAY,MAAM,OAAO,QAAQ;AACtC,MAAI,CAAC,OAAO,eAAkB,OAAM,IAAI,YAAY,QAAQ;AAC5D,MAAI,CAAC,OAAO,OAAU,OAAM,IAAI,YAAY,QAAQ;EACpD,MAAM,CAAC,iBAAiB,MAAM,KAAK,KAClC,IAAI,MAAM,cAAc,CAAC,MAAM,EAAE,IAAI,OAAO,iBAAiB,CAAC,CAAC,MAAM,EAAE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 -11,14 +11,15 @@
|
|
|
11
11
|
"author": "",
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@yongdall/connection": "^0.6.
|
|
15
|
-
"@yongdall/context": "^0.6.
|
|
16
|
-
"@yongdall/core": "^0.6.
|
|
17
|
-
"@yongdall/model": "^0.6.
|
|
18
|
-
"@yongdall/
|
|
14
|
+
"@yongdall/connection": "^0.6.6",
|
|
15
|
+
"@yongdall/context": "^0.6.6",
|
|
16
|
+
"@yongdall/core": "^0.6.6",
|
|
17
|
+
"@yongdall/model": "^0.6.6",
|
|
18
|
+
"@yongdall/plugin-meta": "^0.6.6",
|
|
19
|
+
"@yongdall/role-permission": "^0.6.6"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
|
-
"@yongdall/migrate": "^0.6.
|
|
22
|
-
"@yongdall/types": "^0.6.
|
|
22
|
+
"@yongdall/migrate": "^0.6.6",
|
|
23
|
+
"@yongdall/types": "^0.6.6"
|
|
23
24
|
}
|
|
24
25
|
}
|
package/yongdall/migration.mjs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as OrganizationAppointment, f as CompositeRole, m as OrganizationCompositeRole, p as OrganizationUserCompositeRole, u as OrganizationMember } from "../organization-rbac-CVRP1FKi.mjs";
|
|
2
2
|
|
|
3
|
-
//#region plugins/organization-rbac/yongdall/migration.
|
|
3
|
+
//#region plugins/organization-rbac/yongdall/migration.mts
|
|
4
4
|
/** @import { Profile } from '@yongdall/migrate' */
|
|
5
5
|
/** @type {Profile['models']} */
|
|
6
|
-
const models = [
|
|
6
|
+
const models = [
|
|
7
|
+
OrganizationAppointment,
|
|
8
|
+
OrganizationMember,
|
|
9
|
+
CompositeRole,
|
|
10
|
+
OrganizationCompositeRole,
|
|
11
|
+
OrganizationUserCompositeRole
|
|
12
|
+
];
|
|
7
13
|
|
|
8
14
|
//#endregion
|
|
9
15
|
export { models };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.mjs","names":[],"sources":["../../../plugins/organization-rbac/yongdall/migration.
|
|
1
|
+
{"version":3,"file":"migration.mjs","names":[],"sources":["../../../plugins/organization-rbac/yongdall/migration.mts"],"sourcesContent":["/** @import { Profile } from '@yongdall/migrate' */\nimport { CompositeRole, OrganizationAppointment, OrganizationCompositeRole, OrganizationMember, OrganizationUserCompositeRole } from '../index.mts';\n\n\n/** @type {Profile['models']} */\nexport const models = [\n\tOrganizationAppointment,\n\tOrganizationMember,\n\tCompositeRole,\n\tOrganizationCompositeRole,\n\tOrganizationUserCompositeRole,\n];\n"],"mappings":";;;;;AAKA,MAAa,SAAS;CACrB;CACA;CACA;CACA;CACA;CACA"}
|
package/yongdall/model.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as OrganizationAppointment, f as CompositeRole, m as OrganizationCompositeRole, p as OrganizationUserCompositeRole, u as OrganizationMember } from "../organization-rbac-CVRP1FKi.mjs";
|
|
2
2
|
|
|
3
|
-
//#region plugins/organization-rbac/yongdall/model.
|
|
3
|
+
//#region plugins/organization-rbac/yongdall/model.mts
|
|
4
4
|
/** @import { ModelProfile } from '@yongdall/core' */
|
|
5
5
|
/** @type {ModelProfile['models']} */
|
|
6
6
|
const models = {
|
|
7
7
|
organizationAppointment: OrganizationAppointment,
|
|
8
|
-
organizationMember: OrganizationMember
|
|
8
|
+
organizationMember: OrganizationMember,
|
|
9
|
+
compositeRole: CompositeRole,
|
|
10
|
+
organizationCompositeRole: OrganizationCompositeRole,
|
|
11
|
+
organizationUserCompositeRole: OrganizationUserCompositeRole
|
|
9
12
|
};
|
|
10
13
|
|
|
11
14
|
//#endregion
|
package/yongdall/model.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.mjs","names":[],"sources":["../../../plugins/organization-rbac/yongdall/model.
|
|
1
|
+
{"version":3,"file":"model.mjs","names":[],"sources":["../../../plugins/organization-rbac/yongdall/model.mts"],"sourcesContent":["/** @import { ModelProfile } from '@yongdall/core' */\nimport { CompositeRole, OrganizationAppointment, OrganizationCompositeRole, OrganizationMember, OrganizationUserCompositeRole } from '../index.mts';\n\n/** @type {ModelProfile['models']} */\nexport const models = {\n\torganizationAppointment: OrganizationAppointment,\n\torganizationMember: OrganizationMember,\n\t\tcompositeRole: CompositeRole,\n\t\torganizationCompositeRole: OrganizationCompositeRole,\n\t\torganizationUserCompositeRole: OrganizationUserCompositeRole,\n};\n"],"mappings":";;;;;AAIA,MAAa,SAAS;CACrB,yBAAyB;CACzB,oBAAoB;CACnB,eAAe;CACf,2BAA2B;CAC3B,+BAA+B;CAChC"}
|
package/yongdall/user.mjs
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as getOrganizationPermissions, t as getOrganizationAllPermissions } from "../organization-rbac-CVRP1FKi.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
/** @import { UserManager } from '@yongdall/core' */
|
|
5
|
-
/** @type {UserManager['getOrganizationAllPermissions']} */
|
|
6
|
-
const getOrganizationAllPermissions = () => {
|
|
7
|
-
return useOrganizationAllPermissions();
|
|
8
|
-
};
|
|
9
|
-
/** @type {UserManager['getOrganizationPermissions']} */
|
|
10
|
-
const getOrganizationPermissions = () => {
|
|
11
|
-
return useOrganizationPermissions();
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
export { getOrganizationAllPermissions, getOrganizationPermissions };
|
|
16
|
-
//# sourceMappingURL=user.mjs.map
|
|
3
|
+
export { getOrganizationAllPermissions, getOrganizationPermissions };
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { createComputed } from "@yongdall/context";
|
|
2
|
-
import { Query, Where, actions, createField, createModel, now, uuid } from "@yongdall/model";
|
|
3
|
-
import { getUser } from "@yongdall/core";
|
|
4
|
-
import { useDatabase } from "@yongdall/connection";
|
|
5
|
-
import { findRolePermissions } from "@yongdall/role-permission";
|
|
6
|
-
|
|
7
|
-
//#region plugins/organization-rbac/models/OrganizationAppointment.mjs
|
|
8
|
-
const OrganizationAppointment = createModel("organizationAppointment", {
|
|
9
|
-
id: createField("uuid", {
|
|
10
|
-
nullable: false,
|
|
11
|
-
primary: 1,
|
|
12
|
-
default: uuid,
|
|
13
|
-
uncreatable: true,
|
|
14
|
-
immutable: true
|
|
15
|
-
}),
|
|
16
|
-
label: createField("string", {
|
|
17
|
-
nullable: false,
|
|
18
|
-
label: "职务名称"
|
|
19
|
-
}),
|
|
20
|
-
description: createField("string", {
|
|
21
|
-
nullable: true,
|
|
22
|
-
label: "描述"
|
|
23
|
-
}),
|
|
24
|
-
createdAt: createField("date", {
|
|
25
|
-
nullable: false,
|
|
26
|
-
default: now,
|
|
27
|
-
creating: now,
|
|
28
|
-
label: "创建日期"
|
|
29
|
-
}),
|
|
30
|
-
updatedAt: createField("date", {
|
|
31
|
-
nullable: false,
|
|
32
|
-
default: now,
|
|
33
|
-
updating: now,
|
|
34
|
-
label: "最后更新日期"
|
|
35
|
-
})
|
|
36
|
-
}, { permissions: [{
|
|
37
|
-
permission: "system:organization",
|
|
38
|
-
fields: "*",
|
|
39
|
-
authorizations: [
|
|
40
|
-
"query",
|
|
41
|
-
"read",
|
|
42
|
-
"create",
|
|
43
|
-
"update",
|
|
44
|
-
"destroy",
|
|
45
|
-
"add",
|
|
46
|
-
"remove"
|
|
47
|
-
]
|
|
48
|
-
}] });
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region plugins/organization-rbac/models/OrganizationMember.mjs
|
|
52
|
-
/**
|
|
53
|
-
* 组织用户角色模型
|
|
54
|
-
* @typedef {Object} OrganizationUserRole
|
|
55
|
-
* @property {string} userId - 用户ID,主键第一部分
|
|
56
|
-
* @property {string} organizationId - 组织ID,主键第二部分
|
|
57
|
-
* @property {string} roleId - 角色ID,主键第三部分
|
|
58
|
-
* @property {number} no - 编号
|
|
59
|
-
*/
|
|
60
|
-
const OrganizationUserRole = createModel("organizationUserRole", {
|
|
61
|
-
userId: createField("uuid", {
|
|
62
|
-
nullable: false,
|
|
63
|
-
index: true,
|
|
64
|
-
label: "用户",
|
|
65
|
-
model: "user",
|
|
66
|
-
renderer: "document",
|
|
67
|
-
immutable: true,
|
|
68
|
-
primary: 1
|
|
69
|
-
}),
|
|
70
|
-
organizationId: createField("uuid", {
|
|
71
|
-
nullable: false,
|
|
72
|
-
index: true,
|
|
73
|
-
label: "组织",
|
|
74
|
-
model: "organization",
|
|
75
|
-
renderer: "document",
|
|
76
|
-
immutable: true,
|
|
77
|
-
primary: 2
|
|
78
|
-
}),
|
|
79
|
-
roleId: createField("uuid", {
|
|
80
|
-
nullable: false,
|
|
81
|
-
index: true,
|
|
82
|
-
label: "角色",
|
|
83
|
-
model: "role",
|
|
84
|
-
renderer: "document",
|
|
85
|
-
immutable: true,
|
|
86
|
-
primary: 3
|
|
87
|
-
}),
|
|
88
|
-
no: createField("i32", {
|
|
89
|
-
nullable: false,
|
|
90
|
-
default: 0
|
|
91
|
-
})
|
|
92
|
-
});
|
|
93
|
-
const OrganizationMember = createModel("organizationMember", {
|
|
94
|
-
id: createField("uuid", {
|
|
95
|
-
nullable: false,
|
|
96
|
-
index: true,
|
|
97
|
-
primary: 1,
|
|
98
|
-
default: uuid,
|
|
99
|
-
uncreatable: true,
|
|
100
|
-
immutable: true
|
|
101
|
-
}),
|
|
102
|
-
userId: createField("uuid", {
|
|
103
|
-
nullable: false,
|
|
104
|
-
index: true,
|
|
105
|
-
label: "用户",
|
|
106
|
-
model: "user",
|
|
107
|
-
renderer: "document",
|
|
108
|
-
immutable: true,
|
|
109
|
-
layout: { rowSpan: 6 }
|
|
110
|
-
}),
|
|
111
|
-
organizationId: createField("uuid", {
|
|
112
|
-
nullable: false,
|
|
113
|
-
index: true,
|
|
114
|
-
label: "组织",
|
|
115
|
-
model: "organization",
|
|
116
|
-
renderer: "document",
|
|
117
|
-
immutable: true,
|
|
118
|
-
layout: { rowSpan: 6 }
|
|
119
|
-
}),
|
|
120
|
-
appointmentId: createField("uuid", {
|
|
121
|
-
nullable: true,
|
|
122
|
-
index: true,
|
|
123
|
-
label: "职务",
|
|
124
|
-
model: "appointment",
|
|
125
|
-
renderer: "document",
|
|
126
|
-
layout: { rowSpan: 6 }
|
|
127
|
-
}),
|
|
128
|
-
default: createField("bool", {
|
|
129
|
-
nullable: false,
|
|
130
|
-
default: false,
|
|
131
|
-
label: "默认职务"
|
|
132
|
-
}),
|
|
133
|
-
createdAt: createField("date", {
|
|
134
|
-
nullable: false,
|
|
135
|
-
default: now,
|
|
136
|
-
creating: now,
|
|
137
|
-
label: "创建日期"
|
|
138
|
-
}),
|
|
139
|
-
updatedAt: createField("date", {
|
|
140
|
-
nullable: false,
|
|
141
|
-
default: now,
|
|
142
|
-
updating: now,
|
|
143
|
-
label: "最后更新日期"
|
|
144
|
-
}),
|
|
145
|
-
roles: createField(OrganizationUserRole, {
|
|
146
|
-
array: true,
|
|
147
|
-
constraints: {
|
|
148
|
-
organizationId: { field: "organizationId" },
|
|
149
|
-
userId: { field: "userId" },
|
|
150
|
-
no: { noField: true }
|
|
151
|
-
},
|
|
152
|
-
label: "角色列表",
|
|
153
|
-
layout: { columns: [{ actions: ["add", "remove"] }, {
|
|
154
|
-
field: "roleId",
|
|
155
|
-
placeholder: 1
|
|
156
|
-
}] }
|
|
157
|
-
})
|
|
158
|
-
}, {
|
|
159
|
-
indexes: [{
|
|
160
|
-
fields: [
|
|
161
|
-
"userId",
|
|
162
|
-
"organizationId",
|
|
163
|
-
"appointmentId"
|
|
164
|
-
],
|
|
165
|
-
unique: true
|
|
166
|
-
}],
|
|
167
|
-
permissions: [{
|
|
168
|
-
permission: "system:user",
|
|
169
|
-
fields: "*",
|
|
170
|
-
authorizations: [
|
|
171
|
-
"query",
|
|
172
|
-
"read",
|
|
173
|
-
"create",
|
|
174
|
-
"update",
|
|
175
|
-
"destroy",
|
|
176
|
-
"add",
|
|
177
|
-
"remove"
|
|
178
|
-
]
|
|
179
|
-
}],
|
|
180
|
-
hooks: {
|
|
181
|
-
async afterCreate(conn, Model, record) {
|
|
182
|
-
if (!record.default) return;
|
|
183
|
-
await conn.call(actions.update(Model, { default: false }, Where.and("organizationId", "=", record.organizationId, true).and("userId", record.userId)));
|
|
184
|
-
},
|
|
185
|
-
async afterUpdate(conn, Model, record, oldRecord) {
|
|
186
|
-
if (!record.default) return;
|
|
187
|
-
if (oldRecord.default) return;
|
|
188
|
-
await conn.call(actions.update(Model, { default: false }, Where.and("organizationId", "=", record.organizationId, true).and("userId", record.userId)));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
//#endregion
|
|
194
|
-
//#region plugins/organization-rbac/index.mts
|
|
195
|
-
/** 所在组织 */
|
|
196
|
-
const useOrganizations = createComputed(async () => {
|
|
197
|
-
const id = await getUser();
|
|
198
|
-
const relations = await useDatabase().call(actions.select(new Query(OrganizationMember).select(["organizationId"]).where("userId", id)));
|
|
199
|
-
return new Set(relations.map((v) => v.organizationId));
|
|
200
|
-
});
|
|
201
|
-
/** 角色 */
|
|
202
|
-
const useOrganizationRoleIds = createComputed(async () => {
|
|
203
|
-
const organizations = await useOrganizations();
|
|
204
|
-
if (!organizations.size) return {};
|
|
205
|
-
const id = await getUser();
|
|
206
|
-
const list = await useDatabase().call(actions.select(new Query(OrganizationUserRole).select(["organizationId", "roleId"]).where("organizationId", "in", [...organizations]).where("userId", id)));
|
|
207
|
-
return Object.fromEntries(Object.entries(Object.groupBy(list, (v) => v.organizationId)).map(([organizationId, list]) => [organizationId, new Set(list?.map((v) => v.roleId))]));
|
|
208
|
-
});
|
|
209
|
-
const useOrganizationPermissions = createComputed(async () => {
|
|
210
|
-
const roleIds = await useOrganizationRoleIds();
|
|
211
|
-
const allRoleIds = [...new Set(Object.values(roleIds).flatMap((v) => [...v]))];
|
|
212
|
-
const permissions = Object.create(null);
|
|
213
|
-
if (!allRoleIds.length) return permissions;
|
|
214
|
-
const values = await findRolePermissions(allRoleIds);
|
|
215
|
-
const list = Object.fromEntries(Object.entries(Object.groupBy(values, (l) => l.roleId)).map(([k, v]) => [k, v?.map((v) => v.permission)]));
|
|
216
|
-
for (const [organization, roleSet] of Object.entries(roleIds)) {
|
|
217
|
-
const s = new Set([...roleSet].flatMap((v) => list[v] || []));
|
|
218
|
-
if (!s.size) continue;
|
|
219
|
-
permissions[organization] = s;
|
|
220
|
-
}
|
|
221
|
-
return permissions;
|
|
222
|
-
});
|
|
223
|
-
const useOrganizationAllPermissions = createComputed(async () => {
|
|
224
|
-
const v = await useOrganizationPermissions();
|
|
225
|
-
return new Set(Object.values(v).flatMap((v) => [...v]));
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
//#endregion
|
|
229
|
-
export { OrganizationMember as a, useOrganizations as i, useOrganizationPermissions as n, OrganizationUserRole as o, useOrganizationRoleIds as r, OrganizationAppointment as s, useOrganizationAllPermissions as t };
|
|
230
|
-
//# sourceMappingURL=organization-rbac-BF8uzSCr.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"organization-rbac-BF8uzSCr.mjs","names":[],"sources":["../../plugins/organization-rbac/models/OrganizationAppointment.mjs","../../plugins/organization-rbac/models/OrganizationMember.mjs","../../plugins/organization-rbac/index.mts"],"sourcesContent":["import { createField, createModel, now, uuid } from '@yongdall/model';\n\n\n\n// export const OrganizationAppointmentRole = createModel('organizationAppointmentRole', {\n// \tappointmentId: createField('uuid', { nullable: false, index: true, label: '职务', model: 'appointment', renderer: 'document', immutable: true, primary: 1 }),\n// \troleId: createField('uuid', { nullable: false, index: true, label: '角色', model: 'role', renderer: 'document', immutable: true, primary: 2 }),\n// \tno: createField('i32', { nullable: false, default: 0 }),\n// });\n\nexport const OrganizationAppointment = createModel('organizationAppointment', {\n\tid: createField('uuid', { nullable: false, primary: 1, default: uuid, uncreatable: true, immutable: true }),\n\n\tlabel: createField('string', { nullable: false, label: '职务名称' }),\n\tdescription: createField('string', { nullable: true, label: '描述' }),\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('date', { nullable: false, default: now, updating: now, label: '最后更新日期' }),\n\n\t// roles: createField(OrganizationAppointmentRole, { \n\t// \tarray: true, \n\t// \tconstraints: { appointmentId: { field: 'id' }, no: { noField: true } }, \n\t// \tlabel: '角色列表' \n\t// }),\n}, {\n\n\tpermissions: [\n\t\t{ permission: 'system:organization', fields: '*', authorizations: ['query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t],\n});\n","import { actions, createField, createModel, now, uuid, Where} from '@yongdall/model';\n\n/**\n * 组织用户角色模型\n * @typedef {Object} OrganizationUserRole\n * @property {string} userId - 用户ID,主键第一部分\n * @property {string} organizationId - 组织ID,主键第二部分\n * @property {string} roleId - 角色ID,主键第三部分\n * @property {number} no - 编号\n */\nexport const OrganizationUserRole = createModel('organizationUserRole', {\n\tuserId: createField('uuid', { nullable: false, index: true, label: '用户', model: 'user', renderer: 'document', immutable: true, primary: 1 }),\n\torganizationId: createField('uuid', { nullable: false, index: true, label: '组织', model: 'organization', renderer: 'document', immutable: true, primary: 2 }),\n\troleId: createField('uuid', { nullable: false, index: true, label: '角色', model: 'role', renderer: 'document', immutable: true, primary: 3 }),\n\n\tno: createField('i32', { nullable: false, default: 0 }),\n});\n\n\nexport const OrganizationMember = createModel('organizationMember', {\n\tid: createField('uuid', { nullable: false, index: true, primary: 1, default: uuid, uncreatable: true, immutable: true }),\n\n\tuserId: createField('uuid', { nullable: false, index: true, label: '用户', model: 'user', renderer: 'document', immutable: true, layout: { rowSpan: 6 } }),\n\torganizationId: createField('uuid', { nullable: false, index: true, label: '组织', model: 'organization', renderer: 'document', immutable: true, layout: { rowSpan: 6 } }),\n\tappointmentId: createField('uuid', { nullable: true, index: true, label: '职务', model: 'appointment', renderer: 'document', layout: { rowSpan: 6 } }),\n\n\tdefault: createField('bool', { nullable: false, default: false, label: '默认职务' }),\n\n\tcreatedAt: createField('date', { nullable: false, default: now, creating: now, label: '创建日期' }),\n\tupdatedAt: createField('date', { nullable: false, default: now, updating: now, label: '最后更新日期' }),\n\n\troles: createField(OrganizationUserRole, {\n\t\tarray: true,\n\t\tconstraints: {\n\t\t\torganizationId: { field: 'organizationId' },\n\t\t\tuserId: { field: 'userId' },\n\t\t\tno: { noField: true }\n\t\t},\n\t\tlabel: '角色列表',\n\t\tlayout: {\n\t\t\tcolumns: [{ actions: ['add', 'remove'] }, { field: 'roleId', placeholder: 1 }],\n\t\t},\n\t}),\n}, {\n\tindexes: [\n\t\t{ fields: ['userId', 'organizationId', 'appointmentId'], unique: true }\n\t],\n\tpermissions: [\n\t\t{ permission: 'system:user', fields: '*', authorizations: ['query', 'read', 'create', 'update', 'destroy', 'add', 'remove'] },\n\t],\n\thooks: {\n\t\tasync afterCreate(conn, Model, record) {\n\t\t\tif (!record.default) { return }\n\t\t\tawait conn.call(actions.update(\n\t\t\t\tModel,\n\t\t\t\t{ default: false },\n\t\t\t\tWhere.and('organizationId', '=', record.organizationId, true)\n\t\t\t\t\t.and('userId', record.userId),\n\t\t\t));\n\t\t},\n\n\t\tasync afterUpdate(conn, Model, record, oldRecord) {\n\t\t\tif (!record.default) { return }\n\t\t\tif (oldRecord.default) { return }\n\t\t\tawait conn.call(actions.update(\n\t\t\t\tModel,\n\t\t\t\t{ default: false },\n\t\t\t\tWhere.and('organizationId', '=', record.organizationId, true)\n\t\t\t\t\t.and('userId', record.userId),\n\t\t\t));\n\t\t},\n\t}\n});\n","import { createComputed } from '@yongdall/context';\nimport { actions, Query } from '@yongdall/model';\nimport { getUser } from '@yongdall/core';\nimport { useDatabase } from '@yongdall/connection';\nimport { findRolePermissions } from '@yongdall/role-permission';\nimport { OrganizationMember, OrganizationUserRole } from './models/index.mjs';\n\nexport * from './models/index.mjs';\n\n\n/** 所在组织 */\nexport const useOrganizations = createComputed(async () => {\n\tconst id = await getUser();\n\tconst relations: {organizationId: string}[] = await useDatabase().call(actions.select(\n\t\tnew Query(OrganizationMember).select(['organizationId']).where('userId', id)\n\t));\n\treturn new Set(relations.map(v => v.organizationId));\n});\n\n\n/** 角色 */\nexport const useOrganizationRoleIds = createComputed(async () => {\n\tconst organizations = await useOrganizations()\n\tif (!organizations.size) { return {}; }\n\tconst id = await getUser();\n\tconst list: {organizationId: number; roleId: string;}[] = await useDatabase().call(actions.select(\n\t\tnew Query(OrganizationUserRole).select(['organizationId', 'roleId'])\n\t\t\t.where('organizationId', 'in', [...organizations])\n\t\t\t.where('userId', id)\n\t));\n\treturn Object.fromEntries((Object.entries(Object.groupBy(list, v => v.organizationId))\n\t\t.map(([organizationId, list]) => [organizationId, new Set(list?.map(v => v.roleId))])))\n});\n\n\nexport const useOrganizationPermissions = createComputed(async () => {\n\tconst roleIds = await useOrganizationRoleIds()\n\tconst allRoleIds = [...new Set(Object.values(roleIds).flatMap(v =>[...v]))];\n\tconst permissions: Record<string, Set<string>> = Object.create(null);\n\tif (!allRoleIds.length) { return permissions; }\n\tconst values = await findRolePermissions(allRoleIds);\n\tconst list = Object.fromEntries(Object.entries(Object.groupBy(values, l => l.roleId)).map(([k,v]) => [k, v?.map(v => v.permission)]));\n\tfor (const [organization, roleSet] of Object.entries(roleIds)) {\n\t\tconst s = new Set([...roleSet].flatMap(v => list[v] || []));\n\t\tif (!s.size) { continue; }\n\t\tpermissions[organization] = s;\n\t}\n\treturn permissions;\n});\n\n\n\nexport const useOrganizationAllPermissions = createComputed(async () => {\n\tconst v = await useOrganizationPermissions()\n\treturn new Set(Object.values(v).flatMap(v => [...v]));\n});\n"],"mappings":";;;;;;;AAUA,MAAa,0BAA0B,YAAY,2BAA2B;CAC7E,IAAI,YAAY,QAAQ;EAAE,UAAU;EAAO,SAAS;EAAG,SAAS;EAAM,aAAa;EAAM,WAAW;EAAM,CAAC;CAE3G,OAAO,YAAY,UAAU;EAAE,UAAU;EAAO,OAAO;EAAQ,CAAC;CAChE,aAAa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,CAAC;CAC3E,MAAM,cAA2C,OAAO,OAAO,KAAK;AACpE,KAAI,CAAC,WAAW,OAAU,QAAO;CACjC,MAAM,SAAS,MAAM,oBAAoB,WAAW;CACpD,MAAM,OAAO,OAAO,YAAY,OAAO,QAAQ,OAAO,QAAQ,SAAQ,MAAK,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,GAAE,OAAO,CAAC,GAAG,GAAG,KAAI,MAAK,EAAE,WAAW,CAAC,CAAC,CAAC;AACrI,MAAK,MAAM,CAAC,cAAc,YAAY,OAAO,QAAQ,QAAQ,EAAE;EAC9D,MAAM,IAAI,IAAI,IAAI,CAAC,GAAG,QAAQ,CAAC,SAAQ,MAAK,KAAK,MAAM,EAAE,CAAC,CAAC;AAC3D,MAAI,CAAC,EAAE,KAAQ;AACf,cAAY,gBAAgB;;AAE7B,QAAO;EACN;AAIF,MAAa,gCAAgC,eAAe,YAAY;CACvE,MAAM,IAAI,MAAM,4BAA4B;AAC5C,QAAO,IAAI,IAAI,OAAO,OAAO,EAAE,CAAC,SAAQ,MAAK,CAAC,GAAG,EAAE,CAAC,CAAC;EACpD"}
|
package/yongdall/user.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.mjs","names":[],"sources":["../../../plugins/organization-rbac/yongdall/user.mjs"],"sourcesContent":["/** @import { UserManager } from '@yongdall/core' */\nimport { useOrganizationAllPermissions, useOrganizationPermissions } from '../index.mts';\n\n\n/** @type {UserManager['getOrganizationAllPermissions']} */\nexport const getOrganizationAllPermissions = () => {\n\treturn useOrganizationAllPermissions();\n};\n/** @type {UserManager['getOrganizationPermissions']} */\nexport const getOrganizationPermissions = () => {\n\treturn useOrganizationPermissions();\n};\n"],"mappings":";;;;;AAKA,MAAa,sCAAsC;AAClD,QAAO,+BAA+B;;;AAGvC,MAAa,mCAAmC;AAC/C,QAAO,4BAA4B"}
|