@flusys/nestjs-iam 5.3.1 → 5.4.1
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/cjs/entities/action.entity.js +112 -2
- package/cjs/entities/index.js +1 -2
- package/cjs/entities/permission-base.entity.js +6 -31
- package/cjs/entities/permission-with-company.entity.js +2 -2
- package/cjs/entities/user-iam-permission.entity.js +3 -14
- package/cjs/enums/iam-entity-type.enum.js +17 -0
- package/cjs/enums/iam-permission-type.enum.js +17 -0
- package/cjs/enums/index.js +2 -0
- package/cjs/services/permission.service.js +66 -64
- package/entities/action.entity.d.ts +15 -2
- package/entities/index.d.ts +3 -4
- package/entities/permission-base.entity.d.ts +0 -12
- package/entities/user-iam-permission.entity.d.ts +0 -1
- package/enums/iam-entity-type.enum.d.ts +6 -0
- package/enums/iam-permission-type.enum.d.ts +6 -0
- package/enums/index.d.ts +2 -0
- package/fesm/entities/action.entity.js +113 -3
- package/fesm/entities/index.js +3 -4
- package/fesm/entities/permission-base.entity.js +3 -17
- package/fesm/entities/permission-with-company.entity.js +2 -2
- package/fesm/entities/role-base.entity.js +1 -4
- package/fesm/entities/user-iam-permission.entity.js +0 -2
- package/fesm/enums/iam-entity-type.enum.js +7 -0
- package/fesm/enums/iam-permission-type.enum.js +7 -0
- package/fesm/enums/index.js +2 -0
- package/fesm/services/action.service.js +1 -1
- package/fesm/services/permission.service.js +3 -1
- package/package.json +3 -3
- package/services/action.service.d.ts +8 -8
- package/cjs/entities/action-base.entity.js +0 -130
- package/entities/action-base.entity.d.ts +0 -16
- package/fesm/entities/action-base.entity.js +0 -123
|
@@ -8,16 +8,126 @@ Object.defineProperty(exports, "Action", {
|
|
|
8
8
|
return Action;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _nestjsshared = require("@flusys/nestjs-shared");
|
|
11
12
|
const _typeorm = require("typeorm");
|
|
12
|
-
const
|
|
13
|
+
const _enums = require("../enums");
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
13
27
|
function _ts_decorate(decorators, target, key, desc) {
|
|
14
28
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
29
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
30
|
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
17
31
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
32
|
}
|
|
19
|
-
|
|
33
|
+
function _ts_metadata(k, v) {
|
|
34
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
35
|
+
}
|
|
36
|
+
let Action = class Action extends _nestjsshared.Identity {
|
|
37
|
+
constructor(...args){
|
|
38
|
+
super(...args), _define_property(this, "readOnly", void 0), _define_property(this, "name", void 0), _define_property(this, "description", void 0), _define_property(this, "code", void 0), _define_property(this, "actionType", void 0), _define_property(this, "permissionLogic", void 0), _define_property(this, "serial", void 0), _define_property(this, "isActive", void 0), _define_property(this, "parent", void 0), _define_property(this, "parentId", void 0), _define_property(this, "children", void 0);
|
|
39
|
+
}
|
|
20
40
|
};
|
|
41
|
+
_ts_decorate([
|
|
42
|
+
(0, _typeorm.Column)({
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
nullable: false,
|
|
45
|
+
default: false,
|
|
46
|
+
name: 'read_only'
|
|
47
|
+
}),
|
|
48
|
+
_ts_metadata("design:type", Boolean)
|
|
49
|
+
], Action.prototype, "readOnly", void 0);
|
|
50
|
+
_ts_decorate([
|
|
51
|
+
(0, _typeorm.Column)({
|
|
52
|
+
type: 'varchar',
|
|
53
|
+
length: 255,
|
|
54
|
+
nullable: false
|
|
55
|
+
}),
|
|
56
|
+
_ts_metadata("design:type", String)
|
|
57
|
+
], Action.prototype, "name", void 0);
|
|
58
|
+
_ts_decorate([
|
|
59
|
+
(0, _typeorm.Column)({
|
|
60
|
+
type: 'varchar',
|
|
61
|
+
length: 500,
|
|
62
|
+
nullable: true
|
|
63
|
+
}),
|
|
64
|
+
_ts_metadata("design:type", Object)
|
|
65
|
+
], Action.prototype, "description", void 0);
|
|
66
|
+
_ts_decorate([
|
|
67
|
+
(0, _typeorm.Column)({
|
|
68
|
+
type: 'varchar',
|
|
69
|
+
length: 255,
|
|
70
|
+
nullable: true,
|
|
71
|
+
unique: true
|
|
72
|
+
}),
|
|
73
|
+
_ts_metadata("design:type", Object)
|
|
74
|
+
], Action.prototype, "code", void 0);
|
|
75
|
+
_ts_decorate([
|
|
76
|
+
(0, _typeorm.Column)({
|
|
77
|
+
type: 'varchar',
|
|
78
|
+
length: 50,
|
|
79
|
+
nullable: false,
|
|
80
|
+
default: 'BACKEND',
|
|
81
|
+
name: 'action_type'
|
|
82
|
+
}),
|
|
83
|
+
_ts_metadata("design:type", typeof _enums.ActionType === "undefined" ? Object : _enums.ActionType)
|
|
84
|
+
], Action.prototype, "actionType", void 0);
|
|
85
|
+
_ts_decorate([
|
|
86
|
+
(0, _typeorm.Column)({
|
|
87
|
+
type: (0, _nestjsshared.getJsonColumnType)(),
|
|
88
|
+
nullable: true,
|
|
89
|
+
name: 'permission_logic'
|
|
90
|
+
}),
|
|
91
|
+
_ts_metadata("design:type", Object)
|
|
92
|
+
], Action.prototype, "permissionLogic", void 0);
|
|
93
|
+
_ts_decorate([
|
|
94
|
+
(0, _typeorm.Column)({
|
|
95
|
+
type: 'int',
|
|
96
|
+
nullable: true
|
|
97
|
+
}),
|
|
98
|
+
_ts_metadata("design:type", Object)
|
|
99
|
+
], Action.prototype, "serial", void 0);
|
|
100
|
+
_ts_decorate([
|
|
101
|
+
(0, _typeorm.Column)({
|
|
102
|
+
type: 'boolean',
|
|
103
|
+
nullable: false,
|
|
104
|
+
default: true,
|
|
105
|
+
name: 'is_active'
|
|
106
|
+
}),
|
|
107
|
+
_ts_metadata("design:type", Boolean)
|
|
108
|
+
], Action.prototype, "isActive", void 0);
|
|
109
|
+
_ts_decorate([
|
|
110
|
+
(0, _typeorm.ManyToOne)('Action', 'children', {
|
|
111
|
+
nullable: true,
|
|
112
|
+
onDelete: 'CASCADE'
|
|
113
|
+
}),
|
|
114
|
+
(0, _typeorm.JoinColumn)({
|
|
115
|
+
name: 'parent_id'
|
|
116
|
+
}),
|
|
117
|
+
_ts_metadata("design:type", Object)
|
|
118
|
+
], Action.prototype, "parent", void 0);
|
|
119
|
+
_ts_decorate([
|
|
120
|
+
(0, _typeorm.Column)({
|
|
121
|
+
type: 'uuid',
|
|
122
|
+
nullable: true,
|
|
123
|
+
name: 'parent_id'
|
|
124
|
+
}),
|
|
125
|
+
_ts_metadata("design:type", Object)
|
|
126
|
+
], Action.prototype, "parentId", void 0);
|
|
127
|
+
_ts_decorate([
|
|
128
|
+
(0, _typeorm.OneToMany)('Action', 'parent'),
|
|
129
|
+
_ts_metadata("design:type", Array)
|
|
130
|
+
], Action.prototype, "children", void 0);
|
|
21
131
|
Action = _ts_decorate([
|
|
22
132
|
(0, _typeorm.Entity)({
|
|
23
133
|
name: 'action'
|
package/cjs/entities/index.js
CHANGED
|
@@ -22,11 +22,10 @@ _export(exports, {
|
|
|
22
22
|
return getIAMEntitiesByConfig;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
_export_star(require("./action-base.entity"), exports);
|
|
26
25
|
const _actionentity = _export_star(require("./action.entity"), exports);
|
|
27
26
|
_export_star(require("./permission-base.entity"), exports);
|
|
28
|
-
const _permissionwithcompanyentity = _export_star(require("./permission-with-company.entity"), exports);
|
|
29
27
|
_export_star(require("./role-base.entity"), exports);
|
|
28
|
+
const _permissionwithcompanyentity = _export_star(require("./permission-with-company.entity"), exports);
|
|
30
29
|
const _rolewithcompanyentity = _export_star(require("./role-with-company.entity"), exports);
|
|
31
30
|
const _roleentity = _export_star(require("./role.entity"), exports);
|
|
32
31
|
const _useriampermissionentity = _export_star(require("./user-iam-permission.entity"), exports);
|
|
@@ -2,20 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get IamEntityType () {
|
|
13
|
-
return IamEntityType;
|
|
14
|
-
},
|
|
15
|
-
get IamPermissionType () {
|
|
16
|
-
return IamPermissionType;
|
|
17
|
-
},
|
|
18
|
-
get PermissionBase () {
|
|
5
|
+
Object.defineProperty(exports, "PermissionBase", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
19
8
|
return PermissionBase;
|
|
20
9
|
}
|
|
21
10
|
});
|
|
@@ -43,20 +32,6 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
43
32
|
function _ts_metadata(k, v) {
|
|
44
33
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
45
34
|
}
|
|
46
|
-
var IamPermissionType = /*#__PURE__*/ function(IamPermissionType) {
|
|
47
|
-
IamPermissionType["USER_ROLE"] = "user_role";
|
|
48
|
-
IamPermissionType["ROLE_ACTION"] = "role_action";
|
|
49
|
-
IamPermissionType["USER_ACTION"] = "user_action";
|
|
50
|
-
IamPermissionType["COMPANY_ACTION"] = "company_action";
|
|
51
|
-
return IamPermissionType;
|
|
52
|
-
}({});
|
|
53
|
-
var IamEntityType = /*#__PURE__*/ function(IamEntityType) {
|
|
54
|
-
IamEntityType["USER"] = "user";
|
|
55
|
-
IamEntityType["ROLE"] = "role";
|
|
56
|
-
IamEntityType["ACTION"] = "action";
|
|
57
|
-
IamEntityType["COMPANY"] = "company";
|
|
58
|
-
return IamEntityType;
|
|
59
|
-
}({});
|
|
60
35
|
let PermissionBase = class PermissionBase extends _nestjsshared.Identity {
|
|
61
36
|
isValid(now = new Date()) {
|
|
62
37
|
if (this.validFrom && now < this.validFrom) return false;
|
|
@@ -85,7 +60,7 @@ _ts_decorate([
|
|
|
85
60
|
], PermissionBase.prototype, "sourceType", void 0);
|
|
86
61
|
_ts_decorate([
|
|
87
62
|
(0, _typeorm.Column)({
|
|
88
|
-
type: '
|
|
63
|
+
type: 'varchar',
|
|
89
64
|
length: 150,
|
|
90
65
|
name: 'source_id'
|
|
91
66
|
}),
|
|
@@ -101,7 +76,7 @@ _ts_decorate([
|
|
|
101
76
|
], PermissionBase.prototype, "targetType", void 0);
|
|
102
77
|
_ts_decorate([
|
|
103
78
|
(0, _typeorm.Column)({
|
|
104
|
-
type: '
|
|
79
|
+
type: 'varchar',
|
|
105
80
|
length: 150,
|
|
106
81
|
name: 'target_id'
|
|
107
82
|
}),
|
|
@@ -109,7 +84,7 @@ _ts_decorate([
|
|
|
109
84
|
], PermissionBase.prototype, "targetId", void 0);
|
|
110
85
|
_ts_decorate([
|
|
111
86
|
(0, _typeorm.Column)({
|
|
112
|
-
type: '
|
|
87
|
+
type: 'varchar',
|
|
113
88
|
length: 150,
|
|
114
89
|
nullable: true,
|
|
115
90
|
name: 'user_id'
|
|
@@ -47,7 +47,7 @@ let UserIamPermissionWithCompany = class UserIamPermissionWithCompany extends _p
|
|
|
47
47
|
};
|
|
48
48
|
_ts_decorate([
|
|
49
49
|
(0, _typeorm.Column)({
|
|
50
|
-
type: '
|
|
50
|
+
type: 'varchar',
|
|
51
51
|
length: 150,
|
|
52
52
|
nullable: true,
|
|
53
53
|
name: 'company_id'
|
|
@@ -56,7 +56,7 @@ _ts_decorate([
|
|
|
56
56
|
], UserIamPermissionWithCompany.prototype, "companyId", void 0);
|
|
57
57
|
_ts_decorate([
|
|
58
58
|
(0, _typeorm.Column)({
|
|
59
|
-
type: '
|
|
59
|
+
type: 'varchar',
|
|
60
60
|
length: 150,
|
|
61
61
|
nullable: true,
|
|
62
62
|
name: 'branch_id'
|
|
@@ -2,20 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get IamEntityType () {
|
|
13
|
-
return _permissionbaseentity.IamEntityType;
|
|
14
|
-
},
|
|
15
|
-
get IamPermissionType () {
|
|
16
|
-
return _permissionbaseentity.IamPermissionType;
|
|
17
|
-
},
|
|
18
|
-
get UserIamPermission () {
|
|
5
|
+
Object.defineProperty(exports, "UserIamPermission", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
19
8
|
return UserIamPermission;
|
|
20
9
|
}
|
|
21
10
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "IamEntityType", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return IamEntityType;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var IamEntityType = /*#__PURE__*/ function(IamEntityType) {
|
|
12
|
+
IamEntityType["USER"] = "user";
|
|
13
|
+
IamEntityType["ROLE"] = "role";
|
|
14
|
+
IamEntityType["ACTION"] = "action";
|
|
15
|
+
IamEntityType["COMPANY"] = "company";
|
|
16
|
+
return IamEntityType;
|
|
17
|
+
}({});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "IamPermissionType", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return IamPermissionType;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var IamPermissionType = /*#__PURE__*/ function(IamPermissionType) {
|
|
12
|
+
IamPermissionType["USER_ROLE"] = "user_role";
|
|
13
|
+
IamPermissionType["ROLE_ACTION"] = "role_action";
|
|
14
|
+
IamPermissionType["USER_ACTION"] = "user_action";
|
|
15
|
+
IamPermissionType["COMPANY_ACTION"] = "company_action";
|
|
16
|
+
return IamPermissionType;
|
|
17
|
+
}({});
|
package/cjs/enums/index.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
_export_star(require("./action-type.enum"), exports);
|
|
6
|
+
_export_star(require("./iam-entity-type.enum"), exports);
|
|
7
|
+
_export_star(require("./iam-permission-type.enum"), exports);
|
|
6
8
|
_export_star(require("./permission-type.enum"), exports);
|
|
7
9
|
function _export_star(from, to) {
|
|
8
10
|
Object.keys(from).forEach(function(k) {
|
|
@@ -18,6 +18,8 @@ const _permissionwithcompanyentity = require("../entities/permission-with-compan
|
|
|
18
18
|
const _rolewithcompanyentity = require("../entities/role-with-company.entity");
|
|
19
19
|
const _roleentity = require("../entities/role.entity");
|
|
20
20
|
const _useriampermissionentity = require("../entities/user-iam-permission.entity");
|
|
21
|
+
const _iamentitytypeenum = require("../enums/iam-entity-type.enum");
|
|
22
|
+
const _iampermissiontypeenum = require("../enums/iam-permission-type.enum");
|
|
21
23
|
const _actiontypeenum = require("../enums/action-type.enum");
|
|
22
24
|
const _permissiontypeenum = require("../enums/permission-type.enum");
|
|
23
25
|
const _iamconfigservice = require("./iam-config.service");
|
|
@@ -83,10 +85,10 @@ let PermissionService = class PermissionService {
|
|
|
83
85
|
if (itemsToAdd.length > 0) {
|
|
84
86
|
const actionIdsToAdd = itemsToAdd.map((item)=>item.id);
|
|
85
87
|
const whereFind = {
|
|
86
|
-
permissionType:
|
|
87
|
-
sourceType:
|
|
88
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ACTION,
|
|
89
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
88
90
|
sourceId: dto.userId,
|
|
89
|
-
targetType:
|
|
91
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
90
92
|
targetId: (0, _typeorm.In)(actionIdsToAdd)
|
|
91
93
|
};
|
|
92
94
|
if (enableCompanyFeature) {
|
|
@@ -101,10 +103,10 @@ let PermissionService = class PermissionService {
|
|
|
101
103
|
});
|
|
102
104
|
const existingActionIds = new Set(existingPermissions.map((p)=>p.targetId));
|
|
103
105
|
const newPermissions = itemsToAdd.filter((item)=>!existingActionIds.has(item.id)).map((item)=>({
|
|
104
|
-
permissionType:
|
|
105
|
-
sourceType:
|
|
106
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ACTION,
|
|
107
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
106
108
|
sourceId: dto.userId,
|
|
107
|
-
targetType:
|
|
109
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
108
110
|
targetId: item.id,
|
|
109
111
|
userId: dto.userId,
|
|
110
112
|
companyId: enableCompanyFeature ? companyId : null,
|
|
@@ -128,10 +130,10 @@ let PermissionService = class PermissionService {
|
|
|
128
130
|
if (itemsToRemove.length > 0) {
|
|
129
131
|
const actionIdsToRemove = itemsToRemove.map((item)=>item.id);
|
|
130
132
|
const whereDelete = {
|
|
131
|
-
permissionType:
|
|
132
|
-
sourceType:
|
|
133
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ACTION,
|
|
134
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
133
135
|
sourceId: dto.userId,
|
|
134
|
-
targetType:
|
|
136
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
135
137
|
targetId: (0, _typeorm.In)(actionIdsToRemove)
|
|
136
138
|
};
|
|
137
139
|
if (enableCompanyFeature) {
|
|
@@ -149,8 +151,8 @@ let PermissionService = class PermissionService {
|
|
|
149
151
|
const actionRepo = await this.getActionRepository();
|
|
150
152
|
const enableCompanyFeature = this.iamConfigService.isCompanyFeatureEnabled();
|
|
151
153
|
const where = {
|
|
152
|
-
permissionType:
|
|
153
|
-
sourceType:
|
|
154
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ACTION,
|
|
155
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
154
156
|
sourceId: userId
|
|
155
157
|
};
|
|
156
158
|
if (enableCompanyFeature) {
|
|
@@ -218,10 +220,10 @@ let PermissionService = class PermissionService {
|
|
|
218
220
|
const actionIdsToAdd = itemsToAdd.map((item)=>item.id);
|
|
219
221
|
const existingPermissions = await permissionRepo.find({
|
|
220
222
|
where: {
|
|
221
|
-
permissionType:
|
|
222
|
-
sourceType:
|
|
223
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.ROLE_ACTION,
|
|
224
|
+
sourceType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
223
225
|
sourceId: dto.roleId,
|
|
224
|
-
targetType:
|
|
226
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
225
227
|
targetId: (0, _typeorm.In)(actionIdsToAdd)
|
|
226
228
|
},
|
|
227
229
|
select: [
|
|
@@ -230,10 +232,10 @@ let PermissionService = class PermissionService {
|
|
|
230
232
|
});
|
|
231
233
|
const existingActionIds = new Set(existingPermissions.map((p)=>p.targetId));
|
|
232
234
|
const newPermissions = itemsToAdd.filter((item)=>!existingActionIds.has(item.id)).map((item)=>({
|
|
233
|
-
permissionType:
|
|
234
|
-
sourceType:
|
|
235
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.ROLE_ACTION,
|
|
236
|
+
sourceType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
235
237
|
sourceId: dto.roleId,
|
|
236
|
-
targetType:
|
|
238
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
237
239
|
targetId: item.id,
|
|
238
240
|
userId: null,
|
|
239
241
|
companyId: enableCompanyFeature ? roleCompanyId : null,
|
|
@@ -257,10 +259,10 @@ let PermissionService = class PermissionService {
|
|
|
257
259
|
if (itemsToRemove.length > 0) {
|
|
258
260
|
const actionIdsToRemove = itemsToRemove.map((item)=>item.id);
|
|
259
261
|
const result = await permissionRepo.delete({
|
|
260
|
-
permissionType:
|
|
261
|
-
sourceType:
|
|
262
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.ROLE_ACTION,
|
|
263
|
+
sourceType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
262
264
|
sourceId: dto.roleId,
|
|
263
|
-
targetType:
|
|
265
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
264
266
|
targetId: (0, _typeorm.In)(actionIdsToRemove)
|
|
265
267
|
});
|
|
266
268
|
removed = result.affected || 0;
|
|
@@ -273,8 +275,8 @@ let PermissionService = class PermissionService {
|
|
|
273
275
|
const actionRepo = await this.getActionRepository();
|
|
274
276
|
const permissions = await permissionRepo.find({
|
|
275
277
|
where: {
|
|
276
|
-
permissionType:
|
|
277
|
-
sourceType:
|
|
278
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.ROLE_ACTION,
|
|
279
|
+
sourceType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
278
280
|
sourceId: roleId
|
|
279
281
|
}
|
|
280
282
|
});
|
|
@@ -328,10 +330,10 @@ let PermissionService = class PermissionService {
|
|
|
328
330
|
async addCompanyActions(permissionRepo, companyId, actionIds) {
|
|
329
331
|
const existingPermissions = await permissionRepo.find({
|
|
330
332
|
where: {
|
|
331
|
-
permissionType:
|
|
332
|
-
sourceType:
|
|
333
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.COMPANY_ACTION,
|
|
334
|
+
sourceType: _iamentitytypeenum.IamEntityType.COMPANY,
|
|
333
335
|
sourceId: companyId,
|
|
334
|
-
targetType:
|
|
336
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
335
337
|
targetId: (0, _typeorm.In)(actionIds)
|
|
336
338
|
},
|
|
337
339
|
select: [
|
|
@@ -344,10 +346,10 @@ let PermissionService = class PermissionService {
|
|
|
344
346
|
return 0;
|
|
345
347
|
}
|
|
346
348
|
const newPermissions = newActionIds.map((actionId)=>permissionRepo.create({
|
|
347
|
-
permissionType:
|
|
348
|
-
sourceType:
|
|
349
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.COMPANY_ACTION,
|
|
350
|
+
sourceType: _iamentitytypeenum.IamEntityType.COMPANY,
|
|
349
351
|
sourceId: companyId,
|
|
350
|
-
targetType:
|
|
352
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
351
353
|
targetId: actionId,
|
|
352
354
|
userId: null
|
|
353
355
|
}));
|
|
@@ -358,10 +360,10 @@ let PermissionService = class PermissionService {
|
|
|
358
360
|
const permissionEntity = this.iamConfigService.isCompanyFeatureEnabled() ? _permissionwithcompanyentity.UserIamPermissionWithCompany : _useriampermissionentity.UserIamPermission;
|
|
359
361
|
const permissionRepo = manager.getRepository(permissionEntity);
|
|
360
362
|
const companyResult = await permissionRepo.delete({
|
|
361
|
-
permissionType:
|
|
362
|
-
sourceType:
|
|
363
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.COMPANY_ACTION,
|
|
364
|
+
sourceType: _iamentitytypeenum.IamEntityType.COMPANY,
|
|
363
365
|
sourceId: companyId,
|
|
364
|
-
targetType:
|
|
366
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
365
367
|
targetId: (0, _typeorm.In)(actionIds)
|
|
366
368
|
});
|
|
367
369
|
const roleEntity = this.iamConfigService.isCompanyFeatureEnabled() ? _rolewithcompanyentity.RoleWithCompany : _roleentity.Role;
|
|
@@ -380,19 +382,19 @@ let PermissionService = class PermissionService {
|
|
|
380
382
|
if (companyRoles.length > 0) {
|
|
381
383
|
const roleIds = companyRoles.map((role)=>role.id);
|
|
382
384
|
const roleResult = await permissionRepo.delete({
|
|
383
|
-
permissionType:
|
|
384
|
-
sourceType:
|
|
385
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.ROLE_ACTION,
|
|
386
|
+
sourceType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
385
387
|
sourceId: (0, _typeorm.In)(roleIds),
|
|
386
|
-
targetType:
|
|
388
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
387
389
|
targetId: (0, _typeorm.In)(actionIds)
|
|
388
390
|
});
|
|
389
391
|
removedRoleActions = roleResult.affected || 0;
|
|
390
392
|
}
|
|
391
393
|
if (this.iamConfigService.isCompanyFeatureEnabled()) {
|
|
392
394
|
const userResult = await permissionRepo.delete({
|
|
393
|
-
permissionType:
|
|
395
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ACTION,
|
|
394
396
|
companyId,
|
|
395
|
-
targetType:
|
|
397
|
+
targetType: _iamentitytypeenum.IamEntityType.ACTION,
|
|
396
398
|
targetId: (0, _typeorm.In)(actionIds)
|
|
397
399
|
});
|
|
398
400
|
removedUserActions = userResult.affected || 0;
|
|
@@ -408,8 +410,8 @@ let PermissionService = class PermissionService {
|
|
|
408
410
|
const actionRepo = await this.getActionRepository();
|
|
409
411
|
const permissions = await permissionRepo.find({
|
|
410
412
|
where: {
|
|
411
|
-
permissionType:
|
|
412
|
-
sourceType:
|
|
413
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.COMPANY_ACTION,
|
|
414
|
+
sourceType: _iamentitytypeenum.IamEntityType.COMPANY,
|
|
413
415
|
sourceId: companyId
|
|
414
416
|
}
|
|
415
417
|
});
|
|
@@ -442,8 +444,8 @@ let PermissionService = class PermissionService {
|
|
|
442
444
|
const permissionRepo = await this.getPermissionRepository();
|
|
443
445
|
const permissions = await permissionRepo.find({
|
|
444
446
|
where: {
|
|
445
|
-
permissionType:
|
|
446
|
-
sourceType:
|
|
447
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.COMPANY_ACTION,
|
|
448
|
+
sourceType: _iamentitytypeenum.IamEntityType.COMPANY,
|
|
447
449
|
sourceId: companyId
|
|
448
450
|
},
|
|
449
451
|
select: [
|
|
@@ -470,10 +472,10 @@ let PermissionService = class PermissionService {
|
|
|
470
472
|
if (itemsToAdd.length > 0) {
|
|
471
473
|
const roleIdsToAdd = itemsToAdd.map((item)=>item.id);
|
|
472
474
|
const whereFind = {
|
|
473
|
-
permissionType:
|
|
474
|
-
sourceType:
|
|
475
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ROLE,
|
|
476
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
475
477
|
sourceId: dto.userId,
|
|
476
|
-
targetType:
|
|
478
|
+
targetType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
477
479
|
targetId: (0, _typeorm.In)(roleIdsToAdd)
|
|
478
480
|
};
|
|
479
481
|
if (enableCompanyFeature) {
|
|
@@ -488,10 +490,10 @@ let PermissionService = class PermissionService {
|
|
|
488
490
|
});
|
|
489
491
|
const existingRoleIds = new Set(existingPermissions.map((p)=>p.targetId));
|
|
490
492
|
const newPermissions = itemsToAdd.filter((item)=>!existingRoleIds.has(item.id)).map((item)=>({
|
|
491
|
-
permissionType:
|
|
492
|
-
sourceType:
|
|
493
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ROLE,
|
|
494
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
493
495
|
sourceId: dto.userId,
|
|
494
|
-
targetType:
|
|
496
|
+
targetType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
495
497
|
targetId: item.id,
|
|
496
498
|
userId: dto.userId,
|
|
497
499
|
companyId: enableCompanyFeature ? companyId : null,
|
|
@@ -515,10 +517,10 @@ let PermissionService = class PermissionService {
|
|
|
515
517
|
if (itemsToRemove.length > 0) {
|
|
516
518
|
const roleIdsToRemove = itemsToRemove.map((item)=>item.id);
|
|
517
519
|
const whereDelete = {
|
|
518
|
-
permissionType:
|
|
519
|
-
sourceType:
|
|
520
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ROLE,
|
|
521
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
520
522
|
sourceId: dto.userId,
|
|
521
|
-
targetType:
|
|
523
|
+
targetType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
522
524
|
targetId: (0, _typeorm.In)(roleIdsToRemove)
|
|
523
525
|
};
|
|
524
526
|
if (enableCompanyFeature) {
|
|
@@ -536,8 +538,8 @@ let PermissionService = class PermissionService {
|
|
|
536
538
|
const roleRepo = await this.getRoleRepository();
|
|
537
539
|
const enableCompanyFeature = this.iamConfigService.isCompanyFeatureEnabled();
|
|
538
540
|
const where = {
|
|
539
|
-
permissionType:
|
|
540
|
-
sourceType:
|
|
541
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ROLE,
|
|
542
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
541
543
|
sourceId: userId
|
|
542
544
|
};
|
|
543
545
|
if (enableCompanyFeature) {
|
|
@@ -740,8 +742,8 @@ let PermissionService = class PermissionService {
|
|
|
740
742
|
if (!enableCompanyFeature) {
|
|
741
743
|
const permissions = await permissionRepo.find({
|
|
742
744
|
where: {
|
|
743
|
-
permissionType:
|
|
744
|
-
sourceType:
|
|
745
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ROLE,
|
|
746
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
745
747
|
sourceId: userId
|
|
746
748
|
}
|
|
747
749
|
});
|
|
@@ -749,8 +751,8 @@ let PermissionService = class PermissionService {
|
|
|
749
751
|
}
|
|
750
752
|
const roleIds = new Set();
|
|
751
753
|
const baseWhere = {
|
|
752
|
-
permissionType:
|
|
753
|
-
sourceType:
|
|
754
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ROLE,
|
|
755
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
754
756
|
sourceId: userId,
|
|
755
757
|
companyId: companyId
|
|
756
758
|
};
|
|
@@ -783,8 +785,8 @@ let PermissionService = class PermissionService {
|
|
|
783
785
|
const permissionRepo = await this.getPermissionRepository();
|
|
784
786
|
const permissions = await permissionRepo.find({
|
|
785
787
|
where: {
|
|
786
|
-
permissionType:
|
|
787
|
-
sourceType:
|
|
788
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.ROLE_ACTION,
|
|
789
|
+
sourceType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
788
790
|
sourceId: (0, _typeorm.In)(roleIds)
|
|
789
791
|
}
|
|
790
792
|
});
|
|
@@ -796,8 +798,8 @@ let PermissionService = class PermissionService {
|
|
|
796
798
|
if (!enableCompanyFeature) {
|
|
797
799
|
const permissions = await permissionRepo.find({
|
|
798
800
|
where: {
|
|
799
|
-
permissionType:
|
|
800
|
-
sourceType:
|
|
801
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ACTION,
|
|
802
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
801
803
|
sourceId: userId
|
|
802
804
|
}
|
|
803
805
|
});
|
|
@@ -805,8 +807,8 @@ let PermissionService = class PermissionService {
|
|
|
805
807
|
}
|
|
806
808
|
const actionIds = new Set();
|
|
807
809
|
const baseWhere = {
|
|
808
|
-
permissionType:
|
|
809
|
-
sourceType:
|
|
810
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ACTION,
|
|
811
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
810
812
|
sourceId: userId
|
|
811
813
|
};
|
|
812
814
|
if (companyId) {
|
|
@@ -851,9 +853,9 @@ let PermissionService = class PermissionService {
|
|
|
851
853
|
const enableCompanyFeature = this.iamConfigService.isCompanyFeatureEnabled();
|
|
852
854
|
const userRoles = await permissionRepo.find({
|
|
853
855
|
where: {
|
|
854
|
-
permissionType:
|
|
855
|
-
sourceType:
|
|
856
|
-
targetType:
|
|
856
|
+
permissionType: _iampermissiontypeenum.IamPermissionType.USER_ROLE,
|
|
857
|
+
sourceType: _iamentitytypeenum.IamEntityType.USER,
|
|
858
|
+
targetType: _iamentitytypeenum.IamEntityType.ROLE,
|
|
857
859
|
targetId: roleId
|
|
858
860
|
}
|
|
859
861
|
});
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Identity } from '@flusys/nestjs-shared';
|
|
2
|
+
import { ActionType } from '../enums';
|
|
3
|
+
import { LogicNode } from '../types';
|
|
4
|
+
export declare class Action extends Identity {
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string | null;
|
|
8
|
+
code: string | null;
|
|
9
|
+
actionType: ActionType;
|
|
10
|
+
permissionLogic: LogicNode | null;
|
|
11
|
+
serial: number | null;
|
|
12
|
+
isActive: boolean;
|
|
13
|
+
parent: Action | null;
|
|
14
|
+
parentId: string | null;
|
|
15
|
+
children: Action[];
|
|
3
16
|
}
|
package/entities/index.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
export * from './action-base.entity';
|
|
2
1
|
export * from './action.entity';
|
|
3
2
|
export * from './permission-base.entity';
|
|
4
|
-
export * from './permission-with-company.entity';
|
|
5
3
|
export * from './role-base.entity';
|
|
4
|
+
export * from './permission-with-company.entity';
|
|
6
5
|
export * from './role-with-company.entity';
|
|
7
6
|
export * from './role.entity';
|
|
8
7
|
export * from './user-iam-permission.entity';
|
|
9
|
-
import {
|
|
8
|
+
import { UserIamPermissionWithCompany } from './permission-with-company.entity';
|
|
10
9
|
import { RoleWithCompany } from './role-with-company.entity';
|
|
10
|
+
import { Role } from './role.entity';
|
|
11
11
|
import { UserIamPermission } from './user-iam-permission.entity';
|
|
12
|
-
import { UserIamPermissionWithCompany } from './permission-with-company.entity';
|
|
13
12
|
export declare const IAMCoreEntities: (typeof Role | typeof UserIamPermission)[];
|
|
14
13
|
export declare const IAMCompanyEntities: (typeof UserIamPermissionWithCompany | typeof RoleWithCompany)[];
|
|
15
14
|
export declare const IAMAllEntities: (typeof Role | typeof UserIamPermission)[];
|