chyz 2.0.1-rc.36 → 2.0.1-rc.37

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.
Files changed (231) hide show
  1. package/dist/BaseChyz.d.ts +74 -0
  2. package/dist/BaseChyz.d.ts.map +1 -0
  3. package/dist/BaseChyz.js +586 -0
  4. package/dist/base/ActionFilter.d.ts +32 -0
  5. package/dist/base/ActionFilter.d.ts.map +1 -0
  6. package/dist/base/ActionFilter.js +90 -0
  7. package/dist/base/BadRequestHttpException.d.ts +6 -0
  8. package/dist/base/BadRequestHttpException.d.ts.map +1 -0
  9. package/dist/base/BadRequestHttpException.js +17 -0
  10. package/dist/base/BaseError.d.ts +44 -0
  11. package/dist/base/BaseError.d.ts.map +1 -0
  12. package/{base/BaseError.ts → dist/base/BaseError.js} +18 -26
  13. package/dist/base/Behavior.d.ts +4 -0
  14. package/dist/base/Behavior.d.ts.map +1 -0
  15. package/dist/base/Behavior.js +7 -0
  16. package/dist/base/CBaseObject.d.ts +5 -0
  17. package/dist/base/CBaseObject.d.ts.map +1 -0
  18. package/dist/base/CBaseObject.js +16 -0
  19. package/dist/base/CEvents.d.ts +13 -0
  20. package/dist/base/CEvents.d.ts.map +1 -0
  21. package/dist/base/CEvents.js +24 -0
  22. package/dist/base/CRequest.d.ts +2 -0
  23. package/dist/base/CRequest.d.ts.map +1 -0
  24. package/{base/CRequest.ts → dist/base/CRequest.js} +2 -6
  25. package/dist/base/CWebController.d.ts +44 -0
  26. package/dist/base/CWebController.d.ts.map +1 -0
  27. package/dist/base/CWebController.js +81 -0
  28. package/dist/base/Component.d.ts +21 -0
  29. package/dist/base/Component.d.ts.map +1 -0
  30. package/dist/base/Component.js +57 -0
  31. package/dist/base/Configurable.d.ts +3 -0
  32. package/dist/base/Configurable.d.ts.map +1 -0
  33. package/{requiments/Glob.ts → dist/base/Configurable.js} +2 -3
  34. package/dist/base/DataErrorDbException.d.ts +6 -0
  35. package/dist/base/DataErrorDbException.d.ts.map +1 -0
  36. package/dist/base/DataErrorDbException.js +17 -0
  37. package/dist/base/DbConnection.d.ts +13 -0
  38. package/dist/base/DbConnection.d.ts.map +1 -0
  39. package/dist/base/DbConnection.js +53 -0
  40. package/dist/base/ForbiddenHttpException.d.ts +5 -0
  41. package/dist/base/ForbiddenHttpException.d.ts.map +1 -0
  42. package/dist/base/ForbiddenHttpException.js +16 -0
  43. package/dist/base/InvalidArgumentException.d.ts +6 -0
  44. package/dist/base/InvalidArgumentException.d.ts.map +1 -0
  45. package/dist/base/InvalidArgumentException.js +17 -0
  46. package/dist/base/InvalidConfigException.d.ts +6 -0
  47. package/dist/base/InvalidConfigException.d.ts.map +1 -0
  48. package/dist/base/InvalidConfigException.js +17 -0
  49. package/dist/base/Logs.d.ts +22 -0
  50. package/dist/base/Logs.d.ts.map +1 -0
  51. package/{base/Logs.ts → dist/base/Logs.js} +24 -41
  52. package/dist/base/Model.d.ts +302 -0
  53. package/dist/base/Model.d.ts.map +1 -0
  54. package/{base/Model.ts → dist/base/Model.js} +158 -225
  55. package/dist/base/ModelManager.d.ts +2 -0
  56. package/dist/base/ModelManager.d.ts.map +1 -0
  57. package/{base/ModelManager.ts → dist/base/ModelManager.js} +7 -7
  58. package/dist/base/NotFoundHttpException.d.ts +6 -0
  59. package/dist/base/NotFoundHttpException.d.ts.map +1 -0
  60. package/dist/base/NotFoundHttpException.js +17 -0
  61. package/dist/base/RestClient.d.ts +7 -0
  62. package/dist/base/RestClient.d.ts.map +1 -0
  63. package/dist/base/RestClient.js +25 -0
  64. package/dist/base/UnauthorizedHttpException.d.ts +6 -0
  65. package/dist/base/UnauthorizedHttpException.d.ts.map +1 -0
  66. package/dist/base/UnauthorizedHttpException.js +17 -0
  67. package/dist/base/ValidationHttpException.d.ts +6 -0
  68. package/dist/base/ValidationHttpException.d.ts.map +1 -0
  69. package/dist/base/ValidationHttpException.js +17 -0
  70. package/dist/base/db/Exception.d.ts +7 -0
  71. package/dist/base/db/Exception.d.ts.map +1 -0
  72. package/dist/base/db/Exception.js +15 -0
  73. package/dist/base/index.d.ts +20 -0
  74. package/dist/base/index.d.ts.map +1 -0
  75. package/dist/base/index.js +41 -0
  76. package/dist/decorator/Middleware.d.ts +4 -0
  77. package/dist/decorator/Middleware.d.ts.map +1 -0
  78. package/dist/decorator/Middleware.js +10 -0
  79. package/dist/decorator/controller.d.ts +3 -0
  80. package/dist/decorator/controller.d.ts.map +1 -0
  81. package/{decorator/controller.ts → dist/decorator/controller.js} +9 -7
  82. package/dist/decorator/delete.d.ts +3 -0
  83. package/dist/decorator/delete.d.ts.map +1 -0
  84. package/{decorator/delete.ts → dist/decorator/delete.js} +9 -9
  85. package/dist/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
  86. package/dist/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
  87. package/dist/decorator/enums/ControllerDecoratorParams.js +9 -0
  88. package/dist/decorator/get.d.ts +3 -0
  89. package/dist/decorator/get.d.ts.map +1 -0
  90. package/{decorator/get.ts → dist/decorator/get.js} +10 -11
  91. package/dist/decorator/index.d.ts +6 -0
  92. package/dist/decorator/index.d.ts.map +1 -0
  93. package/dist/decorator/index.js +13 -0
  94. package/dist/decorator/post.d.ts +3 -0
  95. package/dist/decorator/post.d.ts.map +1 -0
  96. package/{decorator/post.ts → dist/decorator/post.js} +10 -10
  97. package/dist/decorator/put.d.ts +3 -0
  98. package/dist/decorator/put.d.ts.map +1 -0
  99. package/{decorator/put.ts → dist/decorator/put.js} +9 -9
  100. package/dist/filters/AccessControl.d.ts +12 -0
  101. package/dist/filters/AccessControl.d.ts.map +1 -0
  102. package/dist/filters/AccessControl.js +83 -0
  103. package/dist/filters/AccessRule.d.ts +83 -0
  104. package/dist/filters/AccessRule.d.ts.map +1 -0
  105. package/dist/filters/AccessRule.js +136 -0
  106. package/{filters/auth/AuthInterface.ts → dist/filters/auth/AuthInterface.d.ts} +7 -15
  107. package/dist/filters/auth/AuthInterface.d.ts.map +1 -0
  108. package/dist/filters/auth/AuthInterface.js +2 -0
  109. package/dist/filters/auth/AuthMethod.d.ts +38 -0
  110. package/dist/filters/auth/AuthMethod.d.ts.map +1 -0
  111. package/dist/filters/auth/AuthMethod.js +82 -0
  112. package/dist/filters/auth/HttpBasicAuth.d.ts +24 -0
  113. package/dist/filters/auth/HttpBasicAuth.d.ts.map +1 -0
  114. package/dist/filters/auth/HttpBasicAuth.js +79 -0
  115. package/dist/filters/auth/HttpBearerAuth.d.ts +18 -0
  116. package/dist/filters/auth/HttpBearerAuth.d.ts.map +1 -0
  117. package/dist/filters/auth/HttpBearerAuth.js +33 -0
  118. package/dist/filters/auth/HttpHeaderAuth.d.ts +19 -0
  119. package/dist/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
  120. package/dist/filters/auth/HttpHeaderAuth.js +64 -0
  121. package/dist/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
  122. package/dist/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
  123. package/dist/filters/auth/JwtHttpBearerAuth.js +88 -0
  124. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
  125. package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
  126. package/dist/filters/auth/KeyCloakHttpBearerAuth.js +116 -0
  127. package/dist/filters/auth/index.d.ts +5 -0
  128. package/dist/filters/auth/index.d.ts.map +1 -0
  129. package/dist/filters/auth/index.js +11 -0
  130. package/dist/filters/index.d.ts +3 -0
  131. package/dist/filters/index.d.ts.map +1 -0
  132. package/dist/filters/index.js +7 -0
  133. package/dist/index.d.ts +26 -0
  134. package/dist/index.d.ts.map +1 -0
  135. package/dist/index.js +73 -0
  136. package/dist/log/log/config/log4js.json +55 -0
  137. package/dist/model/RouteDefinition.d.ts +7 -0
  138. package/dist/model/RouteDefinition.d.ts.map +1 -0
  139. package/{base/Configurable.ts → dist/model/RouteDefinition.js} +2 -4
  140. package/dist/package.json +63 -0
  141. package/dist/rbac/AuthAssignment.d.ts +19 -0
  142. package/dist/rbac/AuthAssignment.d.ts.map +1 -0
  143. package/dist/rbac/AuthAssignment.js +44 -0
  144. package/dist/rbac/AuthItem.d.ts +27 -0
  145. package/dist/rbac/AuthItem.d.ts.map +1 -0
  146. package/{rbac/AuthItem.ts → dist/rbac/AuthItem.js} +16 -22
  147. package/dist/rbac/AuthItemChild.d.ts +19 -0
  148. package/dist/rbac/AuthItemChild.d.ts.map +1 -0
  149. package/{rbac/AuthItemChild.ts → dist/rbac/AuthItemChild.js} +14 -21
  150. package/dist/rbac/AuthManager.d.ts +112 -0
  151. package/dist/rbac/AuthManager.d.ts.map +1 -0
  152. package/dist/rbac/AuthManager.js +356 -0
  153. package/dist/rbac/index.d.ts +5 -0
  154. package/dist/rbac/index.d.ts.map +1 -0
  155. package/dist/rbac/index.js +28 -0
  156. package/dist/requiments/Glob.d.ts +3 -0
  157. package/dist/requiments/Glob.d.ts.map +1 -0
  158. package/dist/requiments/Glob.js +10 -0
  159. package/dist/requiments/ReflectUtil.d.ts +1 -0
  160. package/dist/requiments/ReflectUtil.d.ts.map +1 -0
  161. package/{requiments/ReflectUtil.ts → dist/requiments/ReflectUtil.js} +4 -6
  162. package/dist/requiments/Utils.d.ts +2 -0
  163. package/dist/requiments/Utils.d.ts.map +1 -0
  164. package/{requiments/Utils.ts → dist/requiments/Utils.js} +34 -40
  165. package/dist/validators/BooleanValidator.d.ts +1 -0
  166. package/dist/validators/BooleanValidator.d.ts.map +1 -0
  167. package/dist/validators/BooleanValidator.js +1 -0
  168. package/dist/validators/CompareValidator.d.ts +1 -0
  169. package/dist/validators/CompareValidator.d.ts.map +1 -0
  170. package/dist/validators/CompareValidator.js +1 -0
  171. package/dist/validators/DateValidator.d.ts +1 -0
  172. package/dist/validators/DateValidator.d.ts.map +1 -0
  173. package/dist/validators/DateValidator.js +1 -0
  174. package/dist/validators/EmailValidator.d.ts +1 -0
  175. package/dist/validators/EmailValidator.d.ts.map +1 -0
  176. package/dist/validators/EmailValidator.js +1 -0
  177. package/dist/validators/Validator.d.ts +18 -0
  178. package/dist/validators/Validator.d.ts.map +1 -0
  179. package/dist/validators/Validator.js +27 -0
  180. package/{web/IdentityInterface.ts → dist/web/IdentityInterface.d.ts} +2 -15
  181. package/dist/web/IdentityInterface.d.ts.map +1 -0
  182. package/dist/web/IdentityInterface.js +8 -0
  183. package/dist/web/WebUser.d.ts +72 -0
  184. package/dist/web/WebUser.d.ts.map +1 -0
  185. package/dist/web/WebUser.js +165 -0
  186. package/package.json +16 -56
  187. package/BaseChyz.ts +0 -623
  188. package/base/ActionFilter.ts +0 -88
  189. package/base/BadRequestHttpException.ts +0 -14
  190. package/base/Behavior.ts +0 -6
  191. package/base/CBaseObject.ts +0 -17
  192. package/base/CEvents.ts +0 -24
  193. package/base/CWebController.ts +0 -90
  194. package/base/Component.ts +0 -66
  195. package/base/DataErrorDbException.ts +0 -16
  196. package/base/DbConnection.ts +0 -55
  197. package/base/ForbiddenHttpException.ts +0 -15
  198. package/base/InvalidArgumentException.ts +0 -16
  199. package/base/InvalidConfigException.ts +0 -16
  200. package/base/NotFoundHttpException.ts +0 -14
  201. package/base/RestClient.ts +0 -26
  202. package/base/UnauthorizedHttpException.ts +0 -17
  203. package/base/ValidationHttpException.ts +0 -14
  204. package/base/db/Exception.ts +0 -14
  205. package/base/index.ts +0 -19
  206. package/decorator/Middleware.ts +0 -9
  207. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  208. package/decorator/index.ts +0 -5
  209. package/filters/AccessControl.ts +0 -74
  210. package/filters/AccessRule.ts +0 -182
  211. package/filters/auth/AuthMethod.ts +0 -100
  212. package/filters/auth/HttpBasicAuth.ts +0 -79
  213. package/filters/auth/HttpBearerAuth.ts +0 -34
  214. package/filters/auth/HttpHeaderAuth.ts +0 -61
  215. package/filters/auth/JwtHttpBearerAuth.ts +0 -83
  216. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -114
  217. package/filters/auth/index.ts +0 -4
  218. package/filters/index.ts +0 -2
  219. package/index.ts +0 -80
  220. package/model/RouteDefinition.ts +0 -18
  221. package/rbac/AuthAssignment.ts +0 -50
  222. package/rbac/AuthManager.ts +0 -399
  223. package/rbac/index.ts +0 -12
  224. package/validators/BooleanValidator.ts +0 -0
  225. package/validators/CompareValidator.ts +0 -0
  226. package/validators/DateValidator.ts +0 -0
  227. package/validators/EmailValidator.ts +0 -0
  228. package/validators/Validator.ts +0 -27
  229. package/web/WebUser.ts +0 -187
  230. /package/{README.md → dist/README.md} +0 -0
  231. /package/{log → dist/log}/config/log4js.json +0 -0
package/index.ts DELETED
@@ -1,80 +0,0 @@
1
- /*
2
- *
3
- * Copyright (c) 2022.. Chy Bilgisayar Bilisim
4
- * Author: Cihan Ozturk
5
- * E-mail: cihan@chy.com.tr
6
- * Github:https://github.com/cihan53/
7
- *
8
- */
9
-
10
- declare global {
11
- interface String {
12
- tokenReplace(obj: any): string;
13
- }
14
- }
15
-
16
- declare namespace Express {
17
- export interface Request {
18
- identity?: string
19
- }
20
- }
21
-
22
- import BaseChyz from "./BaseChyz";
23
- import {RestClient} from "./base";
24
-
25
-
26
- declare module "express-serve-static-core" {
27
- interface Request {
28
- identity: any;
29
- }
30
- }
31
-
32
- String.prototype.tokenReplace = function (obj) {
33
- let retStr: any = this;
34
- for (let x in obj) {
35
- // @ts-ignore
36
- retStr = retStr.replace(new RegExp("\\:" + x, 'g'), obj[x]).toString();
37
- }
38
- return retStr;
39
- };
40
-
41
-
42
- /**
43
- *
44
- */
45
- const Chyz = new BaseChyz();
46
- const pjson = require('./package.json');
47
- export const Chyz_Version = pjson.version;
48
- export {Request, Response, NextFunction} from "./base/CRequest";
49
- export {RouteDefinition} from "./model/RouteDefinition";
50
- export {WebUser} from "./web/WebUser";
51
- export {BaseChyz, RestClient}
52
- export {
53
- Logs,
54
- ActionFilter,
55
- BaseError,
56
- Behavior,
57
- Component,
58
- Configurable,
59
- CWebController,
60
- DbConnection,
61
- ForbiddenHttpException,
62
- InvalidConfigException,
63
- InvalidArgumentException,
64
- NotFoundHttpException,
65
- UnauthorizedHttpException,
66
- DataErrorDbException,
67
- ValidationHttpException,
68
- Model,
69
- ModelManager,
70
- CEvents
71
- } from "./base";
72
- export * from "./filters";
73
- export * from "./filters/auth";
74
- export * from "./rbac/";
75
-
76
- export * from "./decorator";
77
- export * from "./requiments/Utils";
78
-
79
- export default Chyz;
80
-
@@ -1,18 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
-
8
- export interface RouteDefinition {
9
- //id
10
- id:string;
11
- // Path to our route
12
- path: string;
13
- // HTTP Request method (get, post, ...)
14
- requestMethod: 'get' | 'post' | 'delete' | 'options' | 'put';
15
- // Method name within our class responsible for this route
16
- methodName: string;
17
- }
18
-
@@ -1,50 +0,0 @@
1
- /*
2
- * Copyright (c) 2021. Chy Bilgisayar Bilisim
3
- * Author: Cihan Ozturk
4
- * E-mail: cihan@chy.com.tr
5
- * Github:https://github.com/cihan53/
6
- */
7
-
8
- import {DataTypes, Model, ModelManager, Relation} from "../base";
9
-
10
- export class AuthAssignmentClass extends Model {
11
- [x: string]: any;
12
-
13
- tableName() {
14
- return 'auth_assignment';
15
- }
16
- attributes() {
17
- return {
18
-
19
- // Model attributes are defined here
20
- item_name: {
21
- type: DataTypes.STRING,
22
- primaryKey:true,
23
- allowNull: false
24
- },
25
- user_id : {
26
- type: DataTypes.STRING,
27
- allowNull: false
28
- }
29
-
30
- }
31
- }
32
-
33
- init(){
34
- super.init();
35
- this.model().removeAttribute('id')
36
- }
37
-
38
- relations(): Relation[] {
39
- return [
40
- {
41
- type: "hasMany",
42
- foreignKey: "name",
43
- sourceKey:'item_name',
44
- model: ModelManager.AuthItem.model()
45
- }
46
- ]
47
- }
48
-
49
- }
50
-
@@ -1,399 +0,0 @@
1
- import {Component, InvalidConfigException, ModelManager} from "../base";
2
- import {BaseChyz, InvalidArgumentException} from "../index";
3
- import {Utils} from "../requiments/Utils";
4
-
5
-
6
- interface Role {
7
- type: number;
8
- name: string;
9
- description: string;
10
- ruleName: string;
11
- data: string;
12
- params: string;
13
- }
14
-
15
- interface Permission {
16
- type: number;
17
- name: string;
18
- description: string;
19
- ruleName: string;
20
- data: string;
21
- params: string;
22
- }
23
-
24
-
25
- export class AuthManager extends Component {
26
- static readonly TYPE_ROLE = 1;
27
- static readonly TYPE_PERMISSION = 2;
28
-
29
- init() {
30
- BaseChyz.info("Auth Manager init....")
31
- }
32
-
33
- /**
34
- * @var Item[] all auth items (name => Item)
35
- */
36
- protected items: any;
37
- checkAccessAssignments: any = {}
38
- defaultRoles: any = {}
39
-
40
-
41
- /**
42
- *
43
- */
44
-
45
- public async checkAccess(userId: number, permissionName: string, params: any[] = []): Promise<boolean> {
46
- let assignments: any;
47
-
48
- if (!userId) return false;
49
-
50
- if (!this.checkAccessAssignments[userId.toString()]) {
51
- assignments = await this.getAssignments(userId);
52
- this.checkAccessAssignments[userId.toString()] = assignments;
53
- } else {
54
- assignments = this.checkAccessAssignments[userId.toString()]
55
- }
56
-
57
-
58
- // BaseChyz.info("assignments",assignments)
59
- if (this.hasNoAssignments(assignments)) {
60
- return false;
61
- }
62
-
63
-
64
- return await this.checkAccessRecursive(userId, permissionName, params, assignments);
65
- }
66
-
67
- async checkAccessFromCache() {
68
-
69
-
70
- }
71
-
72
- public async checkAccessRecursive(user: string | number, itemname: string, params: any[], assignments: any): Promise<boolean> {
73
- let item: any = await this.getItem(itemname);
74
- if (!item) return false;
75
-
76
- /**
77
- * @todo
78
- * Rule test edilmeli
79
- */
80
-
81
- if (assignments[itemname] || Utils.find(this.defaultRoles, itemname)) {
82
- return true;
83
- }
84
-
85
- /**
86
- * item child
87
- */
88
- let parents = await ModelManager.AuthItemChild.findAll({attributes: ["parent"], where: {child: itemname}});
89
- for (const parent of parents) {
90
- let r = await this.checkAccessRecursive(user, parent.parent, params, assignments);
91
- if (r) {
92
- return true;
93
- }
94
- }
95
-
96
- return false;
97
-
98
- }
99
-
100
- /**
101
- *
102
- * @param name
103
- */
104
- public async getItem(name: string) {
105
- if (!name) return null;
106
-
107
- return await ModelManager.AuthItem.findOne({where: {name: name}})
108
-
109
- }
110
-
111
- public async getItems(type: number) {
112
- let items: any = {};
113
- let _items = await ModelManager.AuthItem.findAll({where: {type: type}})
114
- if (_items)
115
- _items.forEach((item: any) => {
116
- items[item["name"]] = item.dataValues as Role;
117
- })
118
-
119
- return items
120
-
121
- }
122
-
123
- public async getRolesByUser(userId: number) {
124
- if (this.isEmptyUserId(userId.toString())) {
125
- return [];
126
- }
127
-
128
-
129
- let roles: any = {}
130
- let items = await ModelManager.AuthAssignment.findAll({
131
- where: {
132
- user_id: userId.toString(),
133
- '$AuthItemClasses.type$': AuthManager.TYPE_ROLE
134
- },
135
- include: [{
136
- model: ModelManager.AuthItem.model()
137
- }]
138
- })
139
- for (const item of items) {
140
- for (const i of item.AuthItemClasses)
141
- roles[i["name"]] = i.dataValues as Role;
142
- }
143
-
144
- return roles;
145
-
146
- }
147
-
148
- /**
149
- *
150
- * @param roleName
151
- */
152
- public async getChildRoles(roleName: string) {
153
- let role = await this.getRole(roleName);
154
- if (role === null) {
155
- throw new InvalidArgumentException(`Role "${roleName}" not found.`);
156
- }
157
- const result: any = {result: {}};
158
- await this.getChildrenRecursive(roleName, await this.getChildrenList(), result);
159
- let roles: any = {};
160
- roles[roleName] = role;
161
- let _roles = await this.getRoles();
162
- let _r: any = {};
163
- Utils.forEach(_roles, (item: Role) => {
164
- if (result.result[item.name])
165
- _r[item.name] = item;
166
- })
167
-
168
-
169
- return Utils.merge(roles, _r);
170
- }
171
-
172
- /**
173
- *
174
- * @param roleName
175
- */
176
- public async getPermissionsByRole(roleName: string) {
177
- let childrenList = this.getChildrenList();
178
- const result = {result: {}}
179
- let permissions: any = {}
180
- await this.getChildrenRecursive(roleName, childrenList, result);
181
- if (Utils.isEmpty(result.result)) {
182
- return {};
183
- }
184
-
185
- let itemResult = await ModelManager.AuthItem.findAll({
186
- where: {
187
- type: AuthManager.TYPE_PERMISSION,
188
- name: Object.keys(result.result)
189
- }
190
- });
191
- for (const itemElement of itemResult) {
192
- permissions[itemElement["name"]] = itemElement.dataValues as Permission
193
- }
194
-
195
- return permissions;
196
-
197
- }
198
-
199
- /**
200
- *
201
- * @param userId
202
- */
203
- public async getPermissionsByUser(userId: number) {
204
-
205
- if (this.isEmptyUserId(userId.toString())) {
206
- return {};
207
- }
208
-
209
- let directPermission = await this.getDirectPermissionsByUser(userId);
210
- let inheritedPermission = await this.getInheritedPermissionsByUser(userId);
211
-
212
- return Utils.merge(directPermission, inheritedPermission);
213
- }
214
-
215
- /**
216
- * Returns all permissions that are directly assigned to user.
217
- * @return Permission[] all direct permissions that the user has. The array is indexed by the permission names.
218
- */
219
- protected async getDirectPermissionsByUser(userId: number) {
220
- let permissions: any = {}
221
- let result = await ModelManager.AuthAssignment.findAll({
222
- where: {
223
- user_id: userId.toString(),
224
- '$AuthItemClasses.type$': AuthManager.TYPE_PERMISSION
225
- },
226
- include: [
227
- {
228
- model: ModelManager.AuthItem.model()
229
- }
230
- ]
231
- })
232
-
233
- for (const resultElement of result) {
234
- for (const i of resultElement.AuthItemClasses)
235
- permissions[i["name"]] = i.dataValues as Permission;
236
- }
237
-
238
-
239
- return permissions;
240
- }
241
-
242
- protected async getInheritedPermissionsByUser(userId: number) {
243
- let userAssignment = await ModelManager.AuthAssignment.findAll({where: {user_id: userId.toString()}, attributes: ["item_name"]});
244
- let childrenList = await this.getChildrenList();
245
- const result: any = {result: {}}
246
- let permissions: any = {}
247
-
248
- for (const userAssignmentElement of userAssignment) {
249
- this.getChildrenRecursive(userAssignmentElement.item_name, childrenList, result);
250
- }
251
-
252
- if (Utils.isEmpty(result.result)) {
253
- return {};
254
- }
255
-
256
- let itemResult = await ModelManager.AuthItem.findAll({
257
- where: {
258
- type: AuthManager.TYPE_PERMISSION,
259
- name: Object.keys(result.result)
260
- }
261
- });
262
- for (const itemElement of itemResult) {
263
- permissions[itemElement["name"]] = itemElement.dataValues as Permission
264
- }
265
-
266
- return permissions;
267
- }
268
-
269
-
270
- /**
271
- *
272
- * @param userId
273
- */
274
- public async getItemsByUser(userId: number) {
275
- return await ModelManager.AuthAssignment.findAll({
276
- where: {
277
- user_id: userId.toString()
278
- },
279
- include: [{
280
- model: ModelManager.AuthItem.model()
281
- }]
282
- });
283
- }
284
-
285
-
286
- /**
287
- * Returns all role assignment information for the specified role.
288
- * @param $roleName
289
- */
290
- public async getUserIdsByRole(roleName: number) {
291
- if (!roleName) return [];
292
-
293
- return await ModelManager.AuthAssignment.findAll({where: {"item_name": roleName}, attributes: ["user_id"]});
294
- }
295
-
296
-
297
- /**
298
- * {@inheritdoc}
299
- */
300
- public async getRole(name: string) {
301
- let item: Role = await this.getItem(name);
302
- return item && item.type == AuthManager.TYPE_ROLE ? item : null;
303
- }
304
-
305
-
306
- /**
307
- * {@inheritdoc}
308
- */
309
- public getRoles() {
310
- return this.getItems(AuthManager.TYPE_ROLE);
311
- }
312
-
313
- /**
314
- * Recursively finds all children and grand children of the specified item.
315
- * @param string $name the name of the item whose children are to be looked for.
316
- * @param array $childrenList the child list built via [[getChildrenList()]]
317
- * @param array $result the children and grand children (in array keys)
318
- */
319
- protected getChildrenRecursive(name: string, childrenList: any, model: any) {
320
- if (childrenList[name]) {
321
- for (const child of childrenList[name]) {
322
- model.result[child] = true;
323
- this.getChildrenRecursive(child, childrenList, model);
324
- }
325
- }
326
-
327
- }
328
-
329
-
330
- /**
331
- *
332
- * @param roleName
333
- * @param userId
334
- */
335
- public getAssignment(roleName: string, userId: string) {
336
- if (this.isEmptyUserId(userId)) {
337
- return [];
338
- }
339
- return ModelManager.AuthAssignment.findAll({where: {user_id: userId, items_name: roleName}});
340
-
341
- }
342
-
343
- /**
344
- *
345
- */
346
- public async getAssignments(userId: number) {
347
- if (this.isEmptyUserId(userId.toString())) {
348
- return {};
349
- }
350
-
351
- let assignments: any = {};
352
- try {
353
-
354
- let as = await ModelManager.AuthAssignment.findAll({where: {user_id: userId.toString()}});
355
- for (const a of as) {
356
- assignments[a["item_name"]] = a;
357
- }
358
- } catch (e) {
359
- throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
360
- }
361
- return assignments;
362
- }
363
-
364
- /**
365
- * Returns the children for every parent.
366
- * @return array the children list. Each array key is a parent item name,
367
- * and the corresponding array value is a list of child item names.
368
- */
369
- protected async getChildrenList() {
370
- let items = await ModelManager.AuthItemChild.findAll();
371
- let parents: any = {};
372
- for (const item of items) {
373
- parents[item["parent"]] = Utils.concat(parents[item["parent"]] || [], [item["child"]]);
374
- }
375
-
376
- return parents
377
- }
378
-
379
- /**
380
- * Check whether $userId is empty.
381
- * @param mixed $userId
382
- * @return bool
383
- * @since 2.0.26
384
- */
385
- protected isEmptyUserId(userId: string) {
386
- return !userId || userId === '';
387
- }
388
-
389
- /**
390
- * Checks whether array of $assignments is empty and [[defaultRoles]] property is empty as well.
391
- *
392
- * @param Assignment[] $assignments array of user's assignments
393
- * @return bool whether array of $assignments is empty and [[defaultRoles]] property is empty as well
394
- * @since 2.0.11
395
- */
396
- protected hasNoAssignments(assignments: any) {
397
- return Utils.isEmpty(assignments) && Utils.isEmpty(this.defaultRoles)
398
- }
399
- }
package/rbac/index.ts DELETED
@@ -1,12 +0,0 @@
1
- /*
2
- *
3
- * Copyright (c) 2023.. Chy Bilgisayar Bilisim
4
- * Author: Cihan Ozturk
5
- * E-mail: cihan@chy.com.tr
6
- * Github:https://github.com/cihan53/
7
- *
8
- */
9
- export * from "./AuthManager";
10
- export * from "./AuthItem";
11
- export * from "./AuthAssignment";
12
- export * from "./AuthItemChild";
File without changes
File without changes
File without changes
File without changes
@@ -1,27 +0,0 @@
1
- import {Component} from "../base";
2
-
3
- export class Validator extends Component {
4
- public static builtInValidators = {
5
- 'boolean': '',
6
- 'email': '',
7
- }
8
-
9
-
10
- /**
11
- * @var array|string attributes to be validated by this validator. For multiple attributes,
12
- * please specify them as an array; for single attribute, you may use either a string or an array.
13
- */
14
- public attributes = [];
15
- public message: string = "";
16
-
17
- public except = [];
18
- public isEmpty = [];
19
-
20
- public init() {
21
- super.init();
22
- }
23
-
24
- public static createValidator(type: any, model: any, attributes: any, params = []) {
25
-
26
- }
27
- }