@yongdall/organization-rbac 0.6.5 → 0.7.0

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