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.
- package/dist/BaseChyz.d.ts +74 -0
- package/dist/BaseChyz.d.ts.map +1 -0
- package/dist/BaseChyz.js +586 -0
- package/dist/base/ActionFilter.d.ts +32 -0
- package/dist/base/ActionFilter.d.ts.map +1 -0
- package/dist/base/ActionFilter.js +90 -0
- package/dist/base/BadRequestHttpException.d.ts +6 -0
- package/dist/base/BadRequestHttpException.d.ts.map +1 -0
- package/dist/base/BadRequestHttpException.js +17 -0
- package/dist/base/BaseError.d.ts +44 -0
- package/dist/base/BaseError.d.ts.map +1 -0
- package/{base/BaseError.ts → dist/base/BaseError.js} +18 -26
- package/dist/base/Behavior.d.ts +4 -0
- package/dist/base/Behavior.d.ts.map +1 -0
- package/dist/base/Behavior.js +7 -0
- package/dist/base/CBaseObject.d.ts +5 -0
- package/dist/base/CBaseObject.d.ts.map +1 -0
- package/dist/base/CBaseObject.js +16 -0
- package/dist/base/CEvents.d.ts +13 -0
- package/dist/base/CEvents.d.ts.map +1 -0
- package/dist/base/CEvents.js +24 -0
- package/dist/base/CRequest.d.ts +2 -0
- package/dist/base/CRequest.d.ts.map +1 -0
- package/{base/CRequest.ts → dist/base/CRequest.js} +2 -6
- package/dist/base/CWebController.d.ts +44 -0
- package/dist/base/CWebController.d.ts.map +1 -0
- package/dist/base/CWebController.js +81 -0
- package/dist/base/Component.d.ts +21 -0
- package/dist/base/Component.d.ts.map +1 -0
- package/dist/base/Component.js +57 -0
- package/dist/base/Configurable.d.ts +3 -0
- package/dist/base/Configurable.d.ts.map +1 -0
- package/{requiments/Glob.ts → dist/base/Configurable.js} +2 -3
- package/dist/base/DataErrorDbException.d.ts +6 -0
- package/dist/base/DataErrorDbException.d.ts.map +1 -0
- package/dist/base/DataErrorDbException.js +17 -0
- package/dist/base/DbConnection.d.ts +13 -0
- package/dist/base/DbConnection.d.ts.map +1 -0
- package/dist/base/DbConnection.js +53 -0
- package/dist/base/ForbiddenHttpException.d.ts +5 -0
- package/dist/base/ForbiddenHttpException.d.ts.map +1 -0
- package/dist/base/ForbiddenHttpException.js +16 -0
- package/dist/base/InvalidArgumentException.d.ts +6 -0
- package/dist/base/InvalidArgumentException.d.ts.map +1 -0
- package/dist/base/InvalidArgumentException.js +17 -0
- package/dist/base/InvalidConfigException.d.ts +6 -0
- package/dist/base/InvalidConfigException.d.ts.map +1 -0
- package/dist/base/InvalidConfigException.js +17 -0
- package/dist/base/Logs.d.ts +22 -0
- package/dist/base/Logs.d.ts.map +1 -0
- package/{base/Logs.ts → dist/base/Logs.js} +24 -41
- package/dist/base/Model.d.ts +302 -0
- package/dist/base/Model.d.ts.map +1 -0
- package/{base/Model.ts → dist/base/Model.js} +158 -225
- package/dist/base/ModelManager.d.ts +2 -0
- package/dist/base/ModelManager.d.ts.map +1 -0
- package/{base/ModelManager.ts → dist/base/ModelManager.js} +7 -7
- package/dist/base/NotFoundHttpException.d.ts +6 -0
- package/dist/base/NotFoundHttpException.d.ts.map +1 -0
- package/dist/base/NotFoundHttpException.js +17 -0
- package/dist/base/RestClient.d.ts +7 -0
- package/dist/base/RestClient.d.ts.map +1 -0
- package/dist/base/RestClient.js +25 -0
- package/dist/base/UnauthorizedHttpException.d.ts +6 -0
- package/dist/base/UnauthorizedHttpException.d.ts.map +1 -0
- package/dist/base/UnauthorizedHttpException.js +17 -0
- package/dist/base/ValidationHttpException.d.ts +6 -0
- package/dist/base/ValidationHttpException.d.ts.map +1 -0
- package/dist/base/ValidationHttpException.js +17 -0
- package/dist/base/db/Exception.d.ts +7 -0
- package/dist/base/db/Exception.d.ts.map +1 -0
- package/dist/base/db/Exception.js +15 -0
- package/dist/base/index.d.ts +20 -0
- package/dist/base/index.d.ts.map +1 -0
- package/dist/base/index.js +41 -0
- package/dist/decorator/Middleware.d.ts +4 -0
- package/dist/decorator/Middleware.d.ts.map +1 -0
- package/dist/decorator/Middleware.js +10 -0
- package/dist/decorator/controller.d.ts +3 -0
- package/dist/decorator/controller.d.ts.map +1 -0
- package/{decorator/controller.ts → dist/decorator/controller.js} +9 -7
- package/dist/decorator/delete.d.ts +3 -0
- package/dist/decorator/delete.d.ts.map +1 -0
- package/{decorator/delete.ts → dist/decorator/delete.js} +9 -9
- package/dist/decorator/enums/ControllerDecoratorParams.d.ts +6 -0
- package/dist/decorator/enums/ControllerDecoratorParams.d.ts.map +1 -0
- package/dist/decorator/enums/ControllerDecoratorParams.js +9 -0
- package/dist/decorator/get.d.ts +3 -0
- package/dist/decorator/get.d.ts.map +1 -0
- package/{decorator/get.ts → dist/decorator/get.js} +10 -11
- package/dist/decorator/index.d.ts +6 -0
- package/dist/decorator/index.d.ts.map +1 -0
- package/dist/decorator/index.js +13 -0
- package/dist/decorator/post.d.ts +3 -0
- package/dist/decorator/post.d.ts.map +1 -0
- package/{decorator/post.ts → dist/decorator/post.js} +10 -10
- package/dist/decorator/put.d.ts +3 -0
- package/dist/decorator/put.d.ts.map +1 -0
- package/{decorator/put.ts → dist/decorator/put.js} +9 -9
- package/dist/filters/AccessControl.d.ts +12 -0
- package/dist/filters/AccessControl.d.ts.map +1 -0
- package/dist/filters/AccessControl.js +83 -0
- package/dist/filters/AccessRule.d.ts +83 -0
- package/dist/filters/AccessRule.d.ts.map +1 -0
- package/dist/filters/AccessRule.js +136 -0
- package/{filters/auth/AuthInterface.ts → dist/filters/auth/AuthInterface.d.ts} +7 -15
- package/dist/filters/auth/AuthInterface.d.ts.map +1 -0
- package/dist/filters/auth/AuthInterface.js +2 -0
- package/dist/filters/auth/AuthMethod.d.ts +38 -0
- package/dist/filters/auth/AuthMethod.d.ts.map +1 -0
- package/dist/filters/auth/AuthMethod.js +82 -0
- package/dist/filters/auth/HttpBasicAuth.d.ts +24 -0
- package/dist/filters/auth/HttpBasicAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpBasicAuth.js +79 -0
- package/dist/filters/auth/HttpBearerAuth.d.ts +18 -0
- package/dist/filters/auth/HttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpBearerAuth.js +33 -0
- package/dist/filters/auth/HttpHeaderAuth.d.ts +19 -0
- package/dist/filters/auth/HttpHeaderAuth.d.ts.map +1 -0
- package/dist/filters/auth/HttpHeaderAuth.js +64 -0
- package/dist/filters/auth/JwtHttpBearerAuth.d.ts +21 -0
- package/dist/filters/auth/JwtHttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/JwtHttpBearerAuth.js +88 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts +23 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.d.ts.map +1 -0
- package/dist/filters/auth/KeyCloakHttpBearerAuth.js +116 -0
- package/dist/filters/auth/index.d.ts +5 -0
- package/dist/filters/auth/index.d.ts.map +1 -0
- package/dist/filters/auth/index.js +11 -0
- package/dist/filters/index.d.ts +3 -0
- package/dist/filters/index.d.ts.map +1 -0
- package/dist/filters/index.js +7 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/log/log/config/log4js.json +55 -0
- package/dist/model/RouteDefinition.d.ts +7 -0
- package/dist/model/RouteDefinition.d.ts.map +1 -0
- package/{base/Configurable.ts → dist/model/RouteDefinition.js} +2 -4
- package/dist/package.json +63 -0
- package/dist/rbac/AuthAssignment.d.ts +19 -0
- package/dist/rbac/AuthAssignment.d.ts.map +1 -0
- package/dist/rbac/AuthAssignment.js +44 -0
- package/dist/rbac/AuthItem.d.ts +27 -0
- package/dist/rbac/AuthItem.d.ts.map +1 -0
- package/{rbac/AuthItem.ts → dist/rbac/AuthItem.js} +16 -22
- package/dist/rbac/AuthItemChild.d.ts +19 -0
- package/dist/rbac/AuthItemChild.d.ts.map +1 -0
- package/{rbac/AuthItemChild.ts → dist/rbac/AuthItemChild.js} +14 -21
- package/dist/rbac/AuthManager.d.ts +112 -0
- package/dist/rbac/AuthManager.d.ts.map +1 -0
- package/dist/rbac/AuthManager.js +356 -0
- package/dist/rbac/index.d.ts +5 -0
- package/dist/rbac/index.d.ts.map +1 -0
- package/dist/rbac/index.js +28 -0
- package/dist/requiments/Glob.d.ts +3 -0
- package/dist/requiments/Glob.d.ts.map +1 -0
- package/dist/requiments/Glob.js +10 -0
- package/dist/requiments/ReflectUtil.d.ts +1 -0
- package/dist/requiments/ReflectUtil.d.ts.map +1 -0
- package/{requiments/ReflectUtil.ts → dist/requiments/ReflectUtil.js} +4 -6
- package/dist/requiments/Utils.d.ts +2 -0
- package/dist/requiments/Utils.d.ts.map +1 -0
- package/{requiments/Utils.ts → dist/requiments/Utils.js} +34 -40
- package/dist/validators/BooleanValidator.d.ts +1 -0
- package/dist/validators/BooleanValidator.d.ts.map +1 -0
- package/dist/validators/BooleanValidator.js +1 -0
- package/dist/validators/CompareValidator.d.ts +1 -0
- package/dist/validators/CompareValidator.d.ts.map +1 -0
- package/dist/validators/CompareValidator.js +1 -0
- package/dist/validators/DateValidator.d.ts +1 -0
- package/dist/validators/DateValidator.d.ts.map +1 -0
- package/dist/validators/DateValidator.js +1 -0
- package/dist/validators/EmailValidator.d.ts +1 -0
- package/dist/validators/EmailValidator.d.ts.map +1 -0
- package/dist/validators/EmailValidator.js +1 -0
- package/dist/validators/Validator.d.ts +18 -0
- package/dist/validators/Validator.d.ts.map +1 -0
- package/dist/validators/Validator.js +27 -0
- package/{web/IdentityInterface.ts → dist/web/IdentityInterface.d.ts} +2 -15
- package/dist/web/IdentityInterface.d.ts.map +1 -0
- package/dist/web/IdentityInterface.js +8 -0
- package/dist/web/WebUser.d.ts +72 -0
- package/dist/web/WebUser.d.ts.map +1 -0
- package/dist/web/WebUser.js +165 -0
- package/package.json +16 -56
- package/BaseChyz.ts +0 -623
- package/base/ActionFilter.ts +0 -88
- package/base/BadRequestHttpException.ts +0 -14
- package/base/Behavior.ts +0 -6
- package/base/CBaseObject.ts +0 -17
- package/base/CEvents.ts +0 -24
- package/base/CWebController.ts +0 -90
- package/base/Component.ts +0 -66
- package/base/DataErrorDbException.ts +0 -16
- package/base/DbConnection.ts +0 -55
- package/base/ForbiddenHttpException.ts +0 -15
- package/base/InvalidArgumentException.ts +0 -16
- package/base/InvalidConfigException.ts +0 -16
- package/base/NotFoundHttpException.ts +0 -14
- package/base/RestClient.ts +0 -26
- package/base/UnauthorizedHttpException.ts +0 -17
- package/base/ValidationHttpException.ts +0 -14
- package/base/db/Exception.ts +0 -14
- package/base/index.ts +0 -19
- package/decorator/Middleware.ts +0 -9
- package/decorator/enums/ControllerDecoratorParams.ts +0 -5
- package/decorator/index.ts +0 -5
- package/filters/AccessControl.ts +0 -74
- package/filters/AccessRule.ts +0 -182
- package/filters/auth/AuthMethod.ts +0 -100
- package/filters/auth/HttpBasicAuth.ts +0 -79
- package/filters/auth/HttpBearerAuth.ts +0 -34
- package/filters/auth/HttpHeaderAuth.ts +0 -61
- package/filters/auth/JwtHttpBearerAuth.ts +0 -83
- package/filters/auth/KeyCloakHttpBearerAuth.ts +0 -114
- package/filters/auth/index.ts +0 -4
- package/filters/index.ts +0 -2
- package/index.ts +0 -80
- package/model/RouteDefinition.ts +0 -18
- package/rbac/AuthAssignment.ts +0 -50
- package/rbac/AuthManager.ts +0 -399
- package/rbac/index.ts +0 -12
- package/validators/BooleanValidator.ts +0 -0
- package/validators/CompareValidator.ts +0 -0
- package/validators/DateValidator.ts +0 -0
- package/validators/EmailValidator.ts +0 -0
- package/validators/Validator.ts +0 -27
- package/web/WebUser.ts +0 -187
- /package/{README.md → dist/README.md} +0 -0
- /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
|
-
|
package/model/RouteDefinition.ts
DELETED
|
@@ -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
|
-
|
package/rbac/AuthAssignment.ts
DELETED
|
@@ -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/AuthManager.ts
DELETED
|
@@ -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
|
package/validators/Validator.ts
DELETED
|
@@ -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
|
-
}
|