chyz 1.2.1-rc.2 → 1.2.4-rc.2

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 (201) hide show
  1. package/{dist/BaseChyz.js → BaseChyz.js} +0 -0
  2. package/{dist/BaseChyz.js.map → BaseChyz.js.map} +0 -0
  3. package/{dist/Chyz.js → Chyz.js} +0 -0
  4. package/{dist/Chyz.js.map → Chyz.js.map} +0 -0
  5. package/{dist/base → base}/ActionFilter.js +0 -0
  6. package/{dist/base → base}/ActionFilter.js.map +0 -0
  7. package/{dist/base → base}/BaseError.js +0 -0
  8. package/{dist/base → base}/BaseError.js.map +0 -0
  9. package/{dist/base → base}/BaseObject.js +0 -0
  10. package/{dist/base → base}/BaseObject.js.map +0 -0
  11. package/{dist/base → base}/Behavior.js +0 -0
  12. package/{dist/base → base}/Behavior.js.map +0 -0
  13. package/{dist/base → base}/CWebController.js +0 -0
  14. package/{dist/base → base}/CWebController.js.map +0 -0
  15. package/{dist/base → base}/Component.js +0 -0
  16. package/{dist/base → base}/Component.js.map +0 -0
  17. package/{dist/base → base}/Configurable.js +0 -0
  18. package/{dist/base → base}/Configurable.js.map +0 -0
  19. package/{dist/base → base}/DataErrorDbException.js +0 -0
  20. package/{dist/base → base}/DataErrorDbException.js.map +0 -0
  21. package/{dist/base → base}/DbConnection.js +0 -0
  22. package/{dist/base → base}/DbConnection.js.map +0 -0
  23. package/{dist/base → base}/ForbiddenHttpException.js +0 -0
  24. package/{dist/base → base}/ForbiddenHttpException.js.map +0 -0
  25. package/{dist/base → base}/InvalidArgumentException.js +0 -0
  26. package/{dist/base → base}/InvalidArgumentException.js.map +0 -0
  27. package/{dist/base → base}/InvalidConfigException.js +0 -0
  28. package/{dist/base → base}/InvalidConfigException.js.map +0 -0
  29. package/{dist/base → base}/Model.js +0 -0
  30. package/{dist/base → base}/Model.js.map +0 -0
  31. package/{dist/base → base}/ModelManager.js +0 -0
  32. package/{dist/base → base}/ModelManager.js.map +0 -0
  33. package/{dist/base → base}/NotFoundHttpException.js +0 -0
  34. package/{dist/base → base}/NotFoundHttpException.js.map +0 -0
  35. package/{dist/base → base}/RestClient.js +0 -0
  36. package/{dist/base → base}/RestClient.js.map +0 -0
  37. package/{dist/base → base}/UnauthorizedHttpException.js +0 -0
  38. package/{dist/base → base}/UnauthorizedHttpException.js.map +0 -0
  39. package/{dist/base → base}/ValidationHttpException.js +0 -0
  40. package/{dist/base → base}/ValidationHttpException.js.map +0 -0
  41. package/{dist/base → base}/db/Exception.js +0 -0
  42. package/{dist/base → base}/db/Exception.js.map +0 -0
  43. package/{dist/base → base}/index.js +0 -0
  44. package/{dist/base → base}/index.js.map +0 -0
  45. package/{dist/decorator → decorator}/Middleware.js +0 -0
  46. package/{dist/decorator → decorator}/Middleware.js.map +0 -0
  47. package/{dist/decorator → decorator}/controller.js +0 -0
  48. package/{dist/decorator → decorator}/controller.js.map +0 -0
  49. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js +0 -0
  50. package/{dist/decorator → decorator}/enums/ControllerDecoratorParams.js.map +0 -0
  51. package/{dist/decorator → decorator}/get.js +0 -0
  52. package/{dist/decorator → decorator}/get.js.map +0 -0
  53. package/{dist/decorator → decorator}/index.js +0 -0
  54. package/{dist/decorator → decorator}/index.js.map +0 -0
  55. package/{dist/decorator → decorator}/post.js +0 -0
  56. package/{dist/decorator → decorator}/post.js.map +0 -0
  57. package/{dist/filters → filters}/AccessControl.js +0 -1
  58. package/filters/AccessControl.js.map +1 -0
  59. package/{dist/filters → filters}/AccessRule.js +0 -0
  60. package/{dist/filters → filters}/AccessRule.js.map +0 -0
  61. package/{dist/filters → filters}/auth/AuthInterface.js +0 -0
  62. package/{dist/filters → filters}/auth/AuthInterface.js.map +0 -0
  63. package/{dist/filters → filters}/auth/AuthMethod.js +0 -0
  64. package/{dist/filters → filters}/auth/AuthMethod.js.map +1 -1
  65. package/{dist/filters → filters}/auth/HttpBasicAuth.js +0 -0
  66. package/{dist/filters → filters}/auth/HttpBasicAuth.js.map +0 -0
  67. package/{dist/filters → filters}/auth/HttpBearerAuth.js +0 -0
  68. package/{dist/filters → filters}/auth/HttpBearerAuth.js.map +0 -0
  69. package/{dist/filters → filters}/auth/HttpHeaderAuth.js +0 -0
  70. package/{dist/filters → filters}/auth/HttpHeaderAuth.js.map +0 -0
  71. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js +2 -3
  72. package/{dist/filters → filters}/auth/JwtHttpBearerAuth.js.map +1 -1
  73. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js +0 -0
  74. package/{dist/filters → filters}/auth/KeyCloakHttpBearerAuth.js.map +0 -0
  75. package/{dist/filters → filters}/auth/index.js +0 -0
  76. package/{dist/filters → filters}/auth/index.js.map +0 -0
  77. package/{dist/filters → filters}/index.js +0 -0
  78. package/{dist/filters → filters}/index.js.map +0 -0
  79. package/{dist/index.js → index.js} +3 -0
  80. package/{dist/index.js.map → index.js.map} +1 -1
  81. package/log/config/log4js.json +1 -1
  82. package/{dist/model → model}/RouteDefinition.js +0 -0
  83. package/{dist/model → model}/RouteDefinition.js.map +0 -0
  84. package/package.json +2 -2
  85. package/{dist/rbac → rbac}/AuthAssignment.js +0 -0
  86. package/{dist/rbac → rbac}/AuthAssignment.js.map +0 -0
  87. package/{dist/rbac → rbac}/AuthItem.js +0 -0
  88. package/{dist/rbac → rbac}/AuthItem.js.map +0 -0
  89. package/{dist/rbac → rbac}/AuthItemChild.js +0 -0
  90. package/{dist/rbac → rbac}/AuthItemChild.js.map +0 -0
  91. package/{dist/rbac → rbac}/AuthManager.js +0 -0
  92. package/{dist/rbac → rbac}/AuthManager.js.map +0 -0
  93. package/{dist/requiments → requiments}/Glob.js +0 -0
  94. package/{dist/requiments → requiments}/Glob.js.map +0 -0
  95. package/{dist/requiments → requiments}/ReflectUtil.js +0 -0
  96. package/{dist/requiments → requiments}/ReflectUtil.js.map +0 -0
  97. package/{dist/requiments → requiments}/Utils.js +0 -0
  98. package/{dist/requiments → requiments}/Utils.js.map +0 -0
  99. package/{dist/validators → validators}/BooleanValidator.js +0 -0
  100. package/{dist/validators → validators}/BooleanValidator.js.map +0 -0
  101. package/{dist/validators → validators}/CompareValidator.js +0 -0
  102. package/{dist/validators → validators}/CompareValidator.js.map +0 -0
  103. package/{dist/validators → validators}/DateValidator.js +0 -0
  104. package/{dist/validators → validators}/DateValidator.js.map +0 -0
  105. package/{dist/validators → validators}/EmailValidator.js +0 -0
  106. package/{dist/validators → validators}/EmailValidator.js.map +0 -0
  107. package/{dist/validators → validators}/Validator.js +0 -0
  108. package/{dist/validators → validators}/Validator.js.map +0 -0
  109. package/{dist/web → web}/IdentityInterface.js +0 -0
  110. package/{dist/web → web}/IdentityInterface.js.map +0 -0
  111. package/{dist/web → web}/WebUser.js +0 -0
  112. package/{dist/web → web}/WebUser.js.map +0 -0
  113. package/BaseChyz.ts +0 -454
  114. package/Chyz.ts +0 -11
  115. package/Doc/Moel kullanma.md +0 -13
  116. package/Examples/Controllers/ApiController.ts +0 -140
  117. package/Examples/Controllers/BasicApiController.ts +0 -121
  118. package/Examples/Controllers/KeyCloakController.ts +0 -100
  119. package/Examples/Controllers/PublicController.ts +0 -42
  120. package/Examples/Controllers/SiteController.ts +0 -149
  121. package/Examples/Models/AuthAssignment.ts +0 -50
  122. package/Examples/Models/AuthItem.ts +0 -59
  123. package/Examples/Models/AuthItemChild.ts +0 -49
  124. package/Examples/Models/Categories.ts +0 -51
  125. package/Examples/Models/Customer.ts +0 -115
  126. package/Examples/Models/KeycloakUser.ts +0 -70
  127. package/Examples/Models/Order.ts +0 -64
  128. package/Examples/Models/OrderItem.ts +0 -27
  129. package/Examples/Models/ProductModels.ts +0 -49
  130. package/Examples/Models/ProductToCategories.ts +0 -46
  131. package/Examples/Models/Products.ts +0 -50
  132. package/Examples/Models/Stocks.ts +0 -60
  133. package/Examples/Models/User.ts +0 -128
  134. package/Examples/Models/UserPermission.ts +0 -37
  135. package/Examples/Models/index.ts +0 -19
  136. package/Examples/index-keycloack.ts +0 -78
  137. package/Examples/index.ts +0 -60
  138. package/Examples/keycloak.json +0 -7
  139. package/Examples/log/access.log +0 -0
  140. package/Examples/log/app.log +0 -20601
  141. package/Examples/log/errors.log +0 -2120
  142. package/Examples/package.json +0 -49
  143. package/Examples/tsconfig.json +0 -21
  144. package/base/ActionFilter.ts +0 -71
  145. package/base/BaseError.ts +0 -28
  146. package/base/BaseObject.ts +0 -19
  147. package/base/Behavior.ts +0 -6
  148. package/base/CWebController.ts +0 -84
  149. package/base/Component.ts +0 -66
  150. package/base/Configurable.ts +0 -10
  151. package/base/DataErrorDbException.ts +0 -16
  152. package/base/DbConnection.ts +0 -55
  153. package/base/ForbiddenHttpException.ts +0 -15
  154. package/base/InvalidArgumentException.ts +0 -16
  155. package/base/InvalidConfigException.ts +0 -16
  156. package/base/Model.ts +0 -555
  157. package/base/ModelManager.ts +0 -19
  158. package/base/NotFoundHttpException.ts +0 -14
  159. package/base/RestClient.ts +0 -28
  160. package/base/UnauthorizedHttpException.ts +0 -17
  161. package/base/ValidationHttpException.ts +0 -14
  162. package/base/db/Exception.ts +0 -14
  163. package/base/index.ts +0 -18
  164. package/decorator/Middleware.ts +0 -9
  165. package/decorator/controller.ts +0 -22
  166. package/decorator/enums/ControllerDecoratorParams.ts +0 -5
  167. package/decorator/get.ts +0 -37
  168. package/decorator/index.ts +0 -3
  169. package/decorator/post.ts +0 -36
  170. package/dist/filters/AccessControl.js.map +0 -1
  171. package/dist/log/config/log4js.json +0 -55
  172. package/dist/package.json +0 -59
  173. package/filters/AccessControl.ts +0 -77
  174. package/filters/AccessRule.ts +0 -182
  175. package/filters/auth/AuthInterface.ts +0 -34
  176. package/filters/auth/AuthMethod.ts +0 -88
  177. package/filters/auth/HttpBasicAuth.ts +0 -75
  178. package/filters/auth/HttpBearerAuth.ts +0 -31
  179. package/filters/auth/HttpHeaderAuth.ts +0 -53
  180. package/filters/auth/JwtHttpBearerAuth.ts +0 -80
  181. package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -115
  182. package/filters/auth/index.ts +0 -4
  183. package/filters/index.ts +0 -2
  184. package/index.ts +0 -16
  185. package/model/RouteDefinition.ts +0 -18
  186. package/package-lock.json +0 -5259
  187. package/rbac/AuthAssignment.ts +0 -50
  188. package/rbac/AuthItem.ts +0 -57
  189. package/rbac/AuthItemChild.ts +0 -50
  190. package/rbac/AuthManager.ts +0 -398
  191. package/requiments/Glob.ts +0 -9
  192. package/requiments/ReflectUtil.ts +0 -26
  193. package/requiments/Utils.ts +0 -63
  194. package/tsconfig.json +0 -18
  195. package/validators/BooleanValidator.ts +0 -0
  196. package/validators/CompareValidator.ts +0 -0
  197. package/validators/DateValidator.ts +0 -0
  198. package/validators/EmailValidator.ts +0 -0
  199. package/validators/Validator.ts +0 -27
  200. package/web/IdentityInterface.ts +0 -68
  201. package/web/WebUser.ts +0 -187
@@ -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
-
package/rbac/AuthItem.ts DELETED
@@ -1,57 +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 AuthItemClass extends Model {
11
- [x: string]: any;
12
-
13
- tableName() {
14
- return 'auth_item';
15
- }
16
-
17
- attributes() {
18
- return {
19
- // Model attributes are defined here
20
- name: {
21
- type: DataTypes.STRING,
22
- primaryKey:true,
23
- allowNull: false
24
- },
25
- type: {
26
- type: DataTypes.INTEGER,
27
- allowNull: false
28
- },
29
- description: {
30
- type: DataTypes.STRING,
31
- allowNull: false
32
- },
33
- rule_name: {
34
- type: DataTypes.STRING,
35
- allowNull: false
36
- }
37
-
38
- }
39
- }
40
-
41
- init() {
42
- super.init();
43
- this.model().removeAttribute('id')
44
- }
45
-
46
- relations(): Relation[] {
47
- return [
48
- {
49
- type: "hasOne",
50
- foreignKey: "item_name",
51
- model: ModelManager.AuthAssignment.model()
52
- }
53
- ]
54
- }
55
-
56
- }
57
-
@@ -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
-
9
-
10
- import {DataTypes, Model, ModelManager, Relation} from "../base";
11
-
12
- export class AuthItemChildClass extends Model {
13
- [x: string]: any;
14
-
15
- tableName() {
16
- return 'auth_item_child';
17
- }
18
-
19
- attributes() {
20
- return {
21
- // Model attributes are defined here
22
- parent: {
23
- type: DataTypes.STRING,
24
- primaryKey:true,
25
- allowNull: false
26
- },
27
- child: {
28
- type: DataTypes.STRING,
29
- allowNull: false
30
- }
31
- }
32
- }
33
-
34
- init() {
35
- super.init();
36
- this.model().removeAttribute('id')
37
- }
38
-
39
- relations(): Relation[] {
40
- return [
41
- {
42
- type: "hasOne",
43
- foreignKey: "item_name",
44
- model: ModelManager.AuthAssignment.model()
45
- }
46
- ]
47
- }
48
-
49
- }
50
-
@@ -1,398 +0,0 @@
1
- import {Component, DataErrorDbException, InvalidConfigException, ModelManager, UnauthorizedHttpException} 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
- if (!this.checkAccessAssignments[userId.toString()]) {
48
- assignments = await this.getAssignments(userId);
49
- this.checkAccessAssignments[userId.toString()] = assignments;
50
- } else {
51
- assignments = this.checkAccessAssignments[userId.toString()]
52
- }
53
-
54
-
55
- // BaseChyz.info("assignments",assignments)
56
- if (this.hasNoAssignments(assignments)) {
57
- return false;
58
- }
59
-
60
-
61
- return await this.checkAccessRecursive(userId, permissionName, params, assignments);
62
- }
63
-
64
- async checkAccessFromCache() {
65
-
66
-
67
- }
68
-
69
- public async checkAccessRecursive(user: string | number, itemname: string, params: any[], assignments: any): Promise<boolean> {
70
- let item: any = await this.getItem(itemname);
71
- if (!item) return false;
72
-
73
- /**
74
- * @todo
75
- * Rule test edilmeli
76
- */
77
-
78
- if (assignments[itemname] || Utils.find(this.defaultRoles, itemname)) {
79
- return true;
80
- }
81
-
82
- /**
83
- * item child
84
- */
85
- let parents = await ModelManager.AuthItemChild.findAll({attributes:["parent"], where: {child: itemname}});
86
- for (const parent of parents) {
87
- let r = await this.checkAccessRecursive(user, parent.parent, params, assignments);
88
- if (r) {
89
- return true;
90
- }
91
- }
92
-
93
- return false;
94
-
95
- }
96
-
97
- /**
98
- *
99
- * @param name
100
- */
101
- public async getItem(name: string) {
102
- if (!name) return null;
103
-
104
- return await ModelManager.AuthItem.findOne({where: {name: name}})
105
-
106
- }
107
-
108
- public async getItems(type: number) {
109
- let items: any = {};
110
- let _items = await ModelManager.AuthItem.findAll({where: {type: type}})
111
- if (_items)
112
- _items.forEach((item: any) => {
113
- items[item["name"]] = item.dataValues as Role;
114
- })
115
-
116
- return items
117
-
118
- }
119
-
120
- public async getRolesByUser(userId: number) {
121
- if (this.isEmptyUserId(userId.toString())) {
122
- return [];
123
- }
124
-
125
-
126
- let roles: any = {}
127
- let items = await ModelManager.AuthAssignment.findAll({
128
- where: {
129
- user_id: userId.toString(),
130
- '$AuthItemClasses.type$': AuthManager.TYPE_ROLE
131
- },
132
- include: [{
133
- model: ModelManager.AuthItem.model()
134
- }]
135
- })
136
- for (const item of items) {
137
- for (const i of item.AuthItemClasses)
138
- roles[i["name"]] = i.dataValues as Role;
139
- }
140
-
141
- return roles;
142
-
143
- }
144
-
145
- /**
146
- *
147
- * @param roleName
148
- */
149
- public async getChildRoles(roleName: string) {
150
- let role = await this.getRole(roleName);
151
- if (role === null) {
152
- throw new InvalidArgumentException(`Role "${roleName}" not found.`);
153
- }
154
- const result: any = {result: {}};
155
- await this.getChildrenRecursive(roleName, await this.getChildrenList(), result);
156
- let roles: any = {};
157
- roles[roleName] = role;
158
- let _roles = await this.getRoles();
159
- let _r: any = {};
160
- Utils.forEach(_roles, (item: Role) => {
161
- if (result.result[item.name])
162
- _r[item.name] = item;
163
- })
164
-
165
-
166
- return Utils.merge(roles, _r);
167
- }
168
-
169
- /**
170
- *
171
- * @param roleName
172
- */
173
- public async getPermissionsByRole(roleName: string) {
174
- let childrenList = this.getChildrenList();
175
- const result = {result: {}}
176
- let permissions: any = {}
177
- await this.getChildrenRecursive(roleName, childrenList, result);
178
- if (Utils.isEmpty(result.result)) {
179
- return {};
180
- }
181
-
182
- let itemResult = await ModelManager.AuthItem.findAll({
183
- where: {
184
- type: AuthManager.TYPE_PERMISSION,
185
- name: Object.keys(result.result)
186
- }
187
- });
188
- for (const itemElement of itemResult) {
189
- permissions[itemElement["name"]] = itemElement.dataValues as Permission
190
- }
191
-
192
- return permissions;
193
-
194
- }
195
-
196
- /**
197
- *
198
- * @param userId
199
- */
200
- public async getPermissionsByUser(userId: number) {
201
-
202
- if (this.isEmptyUserId(userId.toString())) {
203
- return {};
204
- }
205
-
206
- let directPermission = await this.getDirectPermissionsByUser(userId);
207
- let inheritedPermission = await this.getInheritedPermissionsByUser(userId);
208
-
209
- return Utils.merge(directPermission, inheritedPermission);
210
- }
211
-
212
- /**
213
- * Returns all permissions that are directly assigned to user.
214
- * @return Permission[] all direct permissions that the user has. The array is indexed by the permission names.
215
- */
216
- protected async getDirectPermissionsByUser(userId: number) {
217
- let permissions: any = {}
218
- let result = await ModelManager.AuthAssignment.findAll({
219
- where: {
220
- user_id: userId.toString(),
221
- '$AuthItemClasses.type$': AuthManager.TYPE_PERMISSION
222
- },
223
- include: [
224
- {
225
- model: ModelManager.AuthItem.model()
226
- }
227
- ]
228
- })
229
-
230
- for (const resultElement of result) {
231
- for (const i of resultElement.AuthItemClasses)
232
- permissions[i["name"]] = i.dataValues as Permission;
233
- }
234
-
235
-
236
- return permissions;
237
- }
238
-
239
- protected async getInheritedPermissionsByUser(userId: number) {
240
- let userAssignment = await ModelManager.AuthAssignment.findAll({where: {user_id: userId.toString()}, attributes: ["item_name"]});
241
- let childrenList = await this.getChildrenList();
242
- const result: any = {result: {}}
243
- let permissions: any = {}
244
-
245
- for (const userAssignmentElement of userAssignment) {
246
- this.getChildrenRecursive(userAssignmentElement.item_name, childrenList, result);
247
- }
248
-
249
- if (Utils.isEmpty(result.result)) {
250
- return {};
251
- }
252
-
253
- let itemResult = await ModelManager.AuthItem.findAll({
254
- where: {
255
- type: AuthManager.TYPE_PERMISSION,
256
- name: Object.keys(result.result)
257
- }
258
- });
259
- for (const itemElement of itemResult) {
260
- permissions[itemElement["name"]] = itemElement.dataValues as Permission
261
- }
262
-
263
- return permissions;
264
- }
265
-
266
-
267
- /**
268
- *
269
- * @param userId
270
- */
271
- public async getItemsByUser(userId: number) {
272
- let items = await ModelManager.AuthAssignment.findAll({
273
- where: {
274
- user_id: userId.toString()
275
- },
276
- include: [{
277
- model: ModelManager.AuthItem.model()
278
- }]
279
- })
280
-
281
- return items;
282
- }
283
-
284
-
285
- /**
286
- * Returns all role assignment information for the specified role.
287
- * @param $roleName
288
- */
289
- public async getUserIdsByRole(roleName: number) {
290
- if (!roleName) return [];
291
-
292
- return await ModelManager.AuthAssignment.findAll({where: {"item_name": roleName}, attributes: ["user_id"]});
293
- }
294
-
295
-
296
- /**
297
- * {@inheritdoc}
298
- */
299
- public async getRole(name: string) {
300
- let item: Role = await this.getItem(name);
301
- return item && item.type == AuthManager.TYPE_ROLE ? item : null;
302
- }
303
-
304
-
305
- /**
306
- * {@inheritdoc}
307
- */
308
- public getRoles() {
309
- return this.getItems(AuthManager.TYPE_ROLE);
310
- }
311
-
312
- /**
313
- * Recursively finds all children and grand children of the specified item.
314
- * @param string $name the name of the item whose children are to be looked for.
315
- * @param array $childrenList the child list built via [[getChildrenList()]]
316
- * @param array $result the children and grand children (in array keys)
317
- */
318
- protected getChildrenRecursive(name: string, childrenList: any, model: any) {
319
- if (childrenList[name]) {
320
- for (const child of childrenList[name]) {
321
- model.result[child] = true;
322
- this.getChildrenRecursive(child, childrenList, model);
323
- }
324
- }
325
-
326
- }
327
-
328
-
329
- /**
330
- *
331
- * @param roleName
332
- * @param userId
333
- */
334
- public getAssignment(roleName: string, userId: string) {
335
- if (this.isEmptyUserId(userId)) {
336
- return [];
337
- }
338
- return ModelManager.AuthAssignment.findAll({where: {user_id: userId, items_name: roleName}});
339
-
340
- }
341
-
342
- /**
343
- *
344
- */
345
- public async getAssignments(userId: number) {
346
- if (this.isEmptyUserId(userId.toString())) {
347
- return {};
348
- }
349
-
350
- let assignments: any = {};
351
- try {
352
-
353
- let as = await ModelManager.AuthAssignment.findAll({where: {user_id: userId.toString()}});
354
- for (const a of as) {
355
- assignments[a["item_name"]] = a;
356
- }
357
- } catch (e) {
358
- throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
359
- }
360
- return assignments;
361
- }
362
-
363
- /**
364
- * Returns the children for every parent.
365
- * @return array the children list. Each array key is a parent item name,
366
- * and the corresponding array value is a list of child item names.
367
- */
368
- protected async getChildrenList() {
369
- let items = await ModelManager.AuthItemChild.findAll();
370
- let parents: any = {};
371
- for (const item of items) {
372
- parents[item["parent"]] = Utils.concat(parents[item["parent"]] || [], [item["child"]]);
373
- }
374
-
375
- return parents
376
- }
377
-
378
- /**
379
- * Check whether $userId is empty.
380
- * @param mixed $userId
381
- * @return bool
382
- * @since 2.0.26
383
- */
384
- protected isEmptyUserId(userId: string) {
385
- return !userId || userId === '';
386
- }
387
-
388
- /**
389
- * Checks whether array of $assignments is empty and [[defaultRoles]] property is empty as well.
390
- *
391
- * @param Assignment[] $assignments array of user's assignments
392
- * @return bool whether array of $assignments is empty and [[defaultRoles]] property is empty as well
393
- * @since 2.0.11
394
- */
395
- protected hasNoAssignments(assignments: any) {
396
- return Utils.isEmpty(assignments) && Utils.isEmpty(this.defaultRoles)
397
- }
398
- }
@@ -1,9 +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
- const Glob = require("glob");
9
- export default Glob;
@@ -1,26 +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
- /**
9
- * @param strClass:
10
- * class name
11
- * @param optionals:
12
- * constructor arguments
13
- */
14
- // @ts-ignore
15
- Reflect.newInstance = function (strClass: string) {
16
- var args = Array.prototype.slice.call(arguments, 1);
17
- var clsClass = eval(strClass);
18
-
19
- const F = () => {
20
- return clsClass.apply(this, args);
21
- }
22
-
23
- F.prototype = clsClass.prototype;
24
- // @ts-ignore
25
- return new F();
26
- };
@@ -1,63 +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
- // import _ from "lodash";
8
- import {Utils} from "sequelize";
9
-
10
- const _ = require('lodash');
11
-
12
- const createObject = (object: any, params: any) => {
13
- let newParams: any = {}
14
- Object.keys(params).forEach((param) => {
15
- newParams[param] = {}
16
- Object.assign(newParams[param], {
17
- writable: true,
18
- configurable: true,
19
- value: params[param]
20
- });
21
- })
22
- return Object.create(object, newParams);
23
- }
24
-
25
- const findKeyValue = (object: any, findKey: string) => {
26
- let key = Object.keys(object).find(key => key.toLowerCase() === findKey.toLowerCase())
27
- if (key) {
28
- return object[key];
29
- }
30
-
31
- return null
32
- }
33
-
34
-
35
- const sleep = (seconds = 1) => {
36
- var waitTill = new Date(new Date().getTime() + seconds * 1000);
37
- while (waitTill > new Date()) {
38
- }
39
- }
40
-
41
-
42
- function wildTest(wildcard: string, str: string) {
43
- let w = wildcard.replace(/[.+^${}()|[\]\\]/g, '\\$&'); // regexp escape
44
- const re = new RegExp(`^${w.replace(/\*/g,'.*').replace(/\?/g,'.')}$`, 'i');
45
- return re.test(str); // remove last 'i' above to have case sensitive
46
- }
47
-
48
- const matchWildcard = (pattern: string, string: string, options: any = {}) => {
49
- return wildTest(pattern, string)
50
- }
51
-
52
- const t = function (text: string) {
53
- return text;
54
- }
55
-
56
- export default {
57
- t,
58
- createObject,
59
- findKeyValue,
60
- sleep,
61
- matchWildcard,
62
- ..._
63
- }
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es6",
5
- "sourceMap": true,
6
- "strict": true,
7
- "outDir": "dist",
8
- "resolveJsonModule": true,
9
- "emitDecoratorMetadata": true,
10
- "esModuleInterop": true,
11
- "experimentalDecorators": true,
12
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
13
- },
14
- "exclude": [
15
- "node_modules",
16
- "**/Examples/*"
17
- ]
18
- }
File without changes
File without changes
File without changes
File without changes