@tachybase/plugin-sub-accounts 0.23.8
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/.turbo/turbo-build.log +30 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +1 -0
- package/dist/externalVersion.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/node_modules/minimatch/LICENSE +15 -0
- package/dist/node_modules/minimatch/lib/path.js +4 -0
- package/dist/node_modules/minimatch/minimatch.js +1 -0
- package/dist/node_modules/minimatch/package.json +1 -0
- package/dist/server/acl/RoleActionParamsMerge.d.ts +4 -0
- package/dist/server/acl/RoleActionParamsMerge.js +42 -0
- package/dist/server/acl/RoleSnippets.d.ts +9 -0
- package/dist/server/acl/RoleSnippets.js +127 -0
- package/dist/server/acl/RoleStrategy.d.ts +19 -0
- package/dist/server/acl/RoleStrategy.js +84 -0
- package/dist/server/addMergeRoles.d.ts +5 -0
- package/dist/server/addMergeRoles.js +46 -0
- package/dist/server/collections/roles.d.ts +2 -0
- package/dist/server/collections/roles.js +37 -0
- package/dist/server/collections/users.d.ts +2 -0
- package/dist/server/collections/users.js +37 -0
- package/dist/server/hooks/index.d.ts +5 -0
- package/dist/server/hooks/index.js +29 -0
- package/dist/server/hooks/merge-role-create.d.ts +6 -0
- package/dist/server/hooks/merge-role-create.js +34 -0
- package/dist/server/hooks/refresh-datasources.d.ts +8 -0
- package/dist/server/hooks/refresh-datasources.js +43 -0
- package/dist/server/hooks/source-role-destroy.d.ts +6 -0
- package/dist/server/hooks/source-role-destroy.js +46 -0
- package/dist/server/hooks/source-role-update.d.ts +6 -0
- package/dist/server/hooks/source-role-update.js +57 -0
- package/dist/server/hooks/user-change-roles.d.ts +9 -0
- package/dist/server/hooks/user-change-roles.js +55 -0
- package/dist/server/hooks/user-create.d.ts +2 -0
- package/dist/server/hooks/user-create.js +38 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/middlewares/change-user-roles.d.ts +8 -0
- package/dist/server/middlewares/change-user-roles.js +66 -0
- package/dist/server/middlewares/set-self-role.d.ts +2 -0
- package/dist/server/middlewares/set-self-role.js +54 -0
- package/dist/server/model/MergeRoleModel.d.ts +49 -0
- package/dist/server/model/MergeRoleModel.js +205 -0
- package/dist/server/plugin.d.ts +11 -0
- package/dist/server/plugin.js +85 -0
- package/package.json +24 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var merge_role_create_exports = {};
|
|
19
|
+
__export(merge_role_create_exports, {
|
|
20
|
+
mergeRoleCreate: () => mergeRoleCreate
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(merge_role_create_exports);
|
|
23
|
+
async function mergeRoleCreate(model, options) {
|
|
24
|
+
if (!model.ownerUserId) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const app = this;
|
|
28
|
+
await model.resetAcl({ acl: app.acl, transaction: options.transaction });
|
|
29
|
+
await model.refreshDataSourcesAcl({ acl: app.acl, transaction: options.transaction });
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
mergeRoleCreate
|
|
34
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var refresh_datasources_exports = {};
|
|
19
|
+
__export(refresh_datasources_exports, {
|
|
20
|
+
refreshDataSourcesAcl: () => refreshDataSourcesAcl,
|
|
21
|
+
refreshDataSourcesAclAtAppStart: () => refreshDataSourcesAclAtAppStart
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(refresh_datasources_exports);
|
|
24
|
+
async function refreshDataSourcesAclAtAppStart() {
|
|
25
|
+
const app = this;
|
|
26
|
+
const exists = await app.db.collectionExistsInDb("dataSourcesRoles");
|
|
27
|
+
if (!exists) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const roles = await app.db.getRepository("roles").find({
|
|
31
|
+
filter: { ownerUserId: { $ne: null } }
|
|
32
|
+
});
|
|
33
|
+
for (const role of roles) {
|
|
34
|
+
await role.refreshDataSourcesAcl({ acl: app.acl });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function refreshDataSourcesAcl() {
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
refreshDataSourcesAcl,
|
|
42
|
+
refreshDataSourcesAclAtAppStart
|
|
43
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var source_role_destroy_exports = {};
|
|
19
|
+
__export(source_role_destroy_exports, {
|
|
20
|
+
sourceRoleDestroy: () => sourceRoleDestroy
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(source_role_destroy_exports);
|
|
23
|
+
async function sourceRoleDestroy(model, options) {
|
|
24
|
+
if (model.ownerUserId) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { transaction } = options;
|
|
28
|
+
const affectedUsers = await model.db.getRepository("users").find({
|
|
29
|
+
filter: {
|
|
30
|
+
"roles.name": model.name
|
|
31
|
+
},
|
|
32
|
+
appends: ["selfRole"]
|
|
33
|
+
});
|
|
34
|
+
if (!affectedUsers.length) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const affectedRoles = affectedUsers.map((u) => u.selfRole);
|
|
38
|
+
const acl = this.acl;
|
|
39
|
+
for (const affectedRole of affectedRoles) {
|
|
40
|
+
await affectedRole.resetAcl({ transaction, acl });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
sourceRoleDestroy
|
|
46
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var source_role_update_exports = {};
|
|
19
|
+
__export(source_role_update_exports, {
|
|
20
|
+
sourceRoleUpdate: () => sourceRoleUpdate
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(source_role_update_exports);
|
|
23
|
+
const observeFields = ["snippets", "allowNewMenu"];
|
|
24
|
+
async function sourceRoleUpdate(model, options) {
|
|
25
|
+
if (model.ownerUserId) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let newResetAcl = false;
|
|
29
|
+
for (const field of options.fields) {
|
|
30
|
+
if (observeFields.includes(field)) {
|
|
31
|
+
newResetAcl = true;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!newResetAcl) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const { transaction } = options;
|
|
39
|
+
const affectedUsers = await model.db.getRepository("users").find({
|
|
40
|
+
filter: {
|
|
41
|
+
"roles.name": model.name
|
|
42
|
+
},
|
|
43
|
+
appends: ["selfRole"]
|
|
44
|
+
});
|
|
45
|
+
if (!affectedUsers.length) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const affectedRoles = affectedUsers.map((u) => u.selfRole);
|
|
49
|
+
const acl = this.acl;
|
|
50
|
+
for (const affectedRole of affectedRoles) {
|
|
51
|
+
await affectedRole.resetAcl({ transaction, acl, changedFields: options.fields });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
sourceRoleUpdate
|
|
57
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UpdateOptions } from '@tachybase/database';
|
|
2
|
+
import { MergeRoleModel } from '../model/MergeRoleModel';
|
|
3
|
+
/**
|
|
4
|
+
* 用户新增/删除/设置 角色
|
|
5
|
+
* @param model
|
|
6
|
+
* @param options
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function userChangeRoles(model: MergeRoleModel, options: UpdateOptions): Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var user_change_roles_exports = {};
|
|
19
|
+
__export(user_change_roles_exports, {
|
|
20
|
+
userChangeRoles: () => userChangeRoles
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(user_change_roles_exports);
|
|
23
|
+
async function userChangeRoles(model, options) {
|
|
24
|
+
if (model.dataValues.roles === void 0) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const rolesBefore = await model.getRoles();
|
|
28
|
+
const rolesNameBefore = rolesBefore.map((role) => role.name);
|
|
29
|
+
const rolesNameAfter = model.dataValues.roles || [];
|
|
30
|
+
let changed = false;
|
|
31
|
+
if (rolesNameBefore.length !== rolesNameAfter.length) {
|
|
32
|
+
changed = true;
|
|
33
|
+
} else {
|
|
34
|
+
for (const role of rolesNameAfter) {
|
|
35
|
+
if (!rolesNameBefore.includes(role)) {
|
|
36
|
+
changed = true;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!changed) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const { transaction } = options;
|
|
45
|
+
const selfRole = await model.getSelfRole({ transaction });
|
|
46
|
+
if (selfRole) {
|
|
47
|
+
const acl = this.acl;
|
|
48
|
+
await selfRole.resetAcl({ transaction, acl });
|
|
49
|
+
await selfRole.refreshDataSourcesAcl({ transaction, acl });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
53
|
+
0 && (module.exports = {
|
|
54
|
+
userChangeRoles
|
|
55
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var user_create_exports = {};
|
|
19
|
+
__export(user_create_exports, {
|
|
20
|
+
createMergeRole: () => createMergeRole
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(user_create_exports);
|
|
23
|
+
async function createMergeRole(user, options) {
|
|
24
|
+
const { transaction } = options;
|
|
25
|
+
const roleRepo = user.db.getRepository("roles");
|
|
26
|
+
const roleName = `m_${user.id}`;
|
|
27
|
+
const mergeRole = {
|
|
28
|
+
title: `{{${user.id} + '_' + t("All")}}`,
|
|
29
|
+
name: roleName,
|
|
30
|
+
ownerUserId: user.id
|
|
31
|
+
};
|
|
32
|
+
const mergeRoleModel = await roleRepo.create({ values: mergeRole, transaction });
|
|
33
|
+
await mergeRoleModel.resetAcl({ acl: this.acl, transaction });
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
createMergeRole
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => import_plugin.default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_plugin = __toESM(require("./plugin"));
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var change_user_roles_exports = {};
|
|
19
|
+
__export(change_user_roles_exports, {
|
|
20
|
+
changeUserRolesMiddleware: () => changeUserRolesMiddleware
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(change_user_roles_exports);
|
|
23
|
+
async function changeUserRolesMiddleware(ctx, next) {
|
|
24
|
+
await next();
|
|
25
|
+
const { associatedName, resourceName, actionName, values, associatedIndex } = ctx.action.params;
|
|
26
|
+
if (associatedName === "roles" && resourceName === "users" && ["add", "remove", "set"].includes(actionName) && (values == null ? void 0 : values.length)) {
|
|
27
|
+
const userRepo = ctx.db.getRepository("users");
|
|
28
|
+
const userList = await userRepo.find({
|
|
29
|
+
fields: ["id"],
|
|
30
|
+
filter: {
|
|
31
|
+
id: { $in: values }
|
|
32
|
+
},
|
|
33
|
+
appends: ["selfRole"]
|
|
34
|
+
});
|
|
35
|
+
const userMap = userList.reduce((map, user) => {
|
|
36
|
+
map.set(user.id, user);
|
|
37
|
+
return map;
|
|
38
|
+
}, /* @__PURE__ */ new Map());
|
|
39
|
+
for (const userId of values) {
|
|
40
|
+
const user = userMap.get(userId);
|
|
41
|
+
const selfRole = user.selfRole;
|
|
42
|
+
if (!selfRole) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
await selfRole.resetAcl({ acl: ctx.app.acl });
|
|
46
|
+
}
|
|
47
|
+
} else if (associatedName === "roles" && resourceName === "menuUiSchemas" && ["add", "remove", "set"].includes(actionName)) {
|
|
48
|
+
const affectedUsers = await ctx.db.getRepository("users").find({
|
|
49
|
+
filter: {
|
|
50
|
+
"roles.name": associatedIndex
|
|
51
|
+
},
|
|
52
|
+
appends: ["selfRole"]
|
|
53
|
+
});
|
|
54
|
+
if (!affectedUsers.length) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const affectedRoles = affectedUsers.map((u) => u.selfRole);
|
|
58
|
+
for (const affectedRole of affectedRoles) {
|
|
59
|
+
await affectedRole.resetAcl({ acl: ctx.app.acl, changedFields: ["menuUiSchemas"] });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
changeUserRolesMiddleware
|
|
66
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var set_self_role_exports = {};
|
|
19
|
+
__export(set_self_role_exports, {
|
|
20
|
+
setSelfRole: () => setSelfRole
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(set_self_role_exports);
|
|
23
|
+
async function setSelfRole(ctx, next) {
|
|
24
|
+
if (!ctx.state.currentUser) {
|
|
25
|
+
return next();
|
|
26
|
+
}
|
|
27
|
+
const currentUser = await ctx.db.getRepository("users").findOne({
|
|
28
|
+
filterByTk: ctx.state.currentUser.id,
|
|
29
|
+
appends: ["selfRole"]
|
|
30
|
+
});
|
|
31
|
+
if (!currentUser.selfRole) {
|
|
32
|
+
return next();
|
|
33
|
+
}
|
|
34
|
+
const sourceRoles = await currentUser.selfRole.getSourceRoles();
|
|
35
|
+
if (sourceRoles.find((r) => r.name === "root")) {
|
|
36
|
+
if (!ctx.get("X-Role") || ctx.get("X-Role") === "anonymous") {
|
|
37
|
+
ctx.headers["x-role"] = "root";
|
|
38
|
+
}
|
|
39
|
+
return next();
|
|
40
|
+
}
|
|
41
|
+
if (!ctx.state.attachRoles) {
|
|
42
|
+
ctx.state.attachRoles = [];
|
|
43
|
+
}
|
|
44
|
+
ctx.state.currentRole = currentUser.selfRole.name;
|
|
45
|
+
ctx.state.attachRoles.push(currentUser.selfRole);
|
|
46
|
+
if (!ctx.get("X-Role") || ctx.get("X-Role") === "anonymous") {
|
|
47
|
+
ctx.headers["x-role"] = currentUser.selfRole.name;
|
|
48
|
+
}
|
|
49
|
+
return next();
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
setSelfRole
|
|
54
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ACL } from '@tachybase/acl';
|
|
2
|
+
import { Transaction } from '@tachybase/database';
|
|
3
|
+
import { RoleModel } from '@tachybase/module-acl';
|
|
4
|
+
export declare class MergeRoleModel extends RoleModel {
|
|
5
|
+
rootResource: MergeRoleModel;
|
|
6
|
+
/**
|
|
7
|
+
* 获取源头角色
|
|
8
|
+
* @param transaction
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
getSourceRoles(transaction: Transaction): Promise<any>;
|
|
12
|
+
/**
|
|
13
|
+
* 数据表操作权限更新
|
|
14
|
+
*/
|
|
15
|
+
refreshDataSourcesAcl({ transaction, acl }: {
|
|
16
|
+
transaction?: Transaction;
|
|
17
|
+
acl: ACL;
|
|
18
|
+
}): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* 数据表操作权限更新
|
|
21
|
+
*/
|
|
22
|
+
refreshDataSourcesAclForResource(acl: ACL, resourceName: string, actionName: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* source变动后导致本身属性或者ui有关属性变动
|
|
25
|
+
*/
|
|
26
|
+
resetAcl({ transaction, acl, changedFields, }: {
|
|
27
|
+
transaction?: Transaction;
|
|
28
|
+
acl: ACL;
|
|
29
|
+
changedFields?: string[];
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* role本身属性变动
|
|
33
|
+
*/
|
|
34
|
+
private resetRoleProperty;
|
|
35
|
+
/**
|
|
36
|
+
* 融合策略, 整个系统中这个变量会被主数据库 data-source-manager的DataSourcesRolesModel.writeToAcl方法设置覆盖
|
|
37
|
+
* root为null
|
|
38
|
+
* data-source的actions体现在[权限页面][数据源][配置][通用操作权限] 但是整个role下的
|
|
39
|
+
* FIXME: strategy这个类型设置的很奇怪,目前只找到actions,依据AvailableStrategyOptions应该还有displayName,allowConfigure,resource
|
|
40
|
+
*/
|
|
41
|
+
private mergeStrategy;
|
|
42
|
+
/**
|
|
43
|
+
* 融合短语,体现在[权限页面][系统管理],主要影响[配置页面] [配置插件] [重启应用]
|
|
44
|
+
* 主要是 ui.* pm.* app.* 等短语
|
|
45
|
+
*/
|
|
46
|
+
private mergeSnippets;
|
|
47
|
+
private mergeMenuUiSchemas;
|
|
48
|
+
private mergeDataSource;
|
|
49
|
+
}
|