check workflow

This commit is contained in:
kittapath 2024-10-22 08:21:07 +07:00
parent e0f37dda4a
commit aa5e69776e
6 changed files with 69 additions and 49 deletions

View file

@ -53,18 +53,7 @@ class CheckAuth {
return await new CallAPI()
.GetData(req, `/org/permission/org/${system}/${action}`)
.then(async (x) => {
console.log(x);
let privilege = x.privilege;
// if (action.trim().toLocaleUpperCase() == "CREATE")
// privilege = await this.PermissionCreate(req, system);
// if (action.trim().toLocaleUpperCase() == "DELETE")
// privilege = await this.PermissionDelete(req, system);
// if (action.trim().toLocaleUpperCase() == "GET")
// privilege = await this.PermissionGet(req, system);
// if (action.trim().toLocaleUpperCase() == "LIST")
// privilege = await this.PermissionList(req, system);
// if (action.trim().toLocaleUpperCase() == "UPDATE")
// privilege = await this.PermissionUpdate(req, system);
let data: any = {
root: [null],
@ -72,6 +61,7 @@ class CheckAuth {
child2: [null],
child3: [null],
child4: [null],
privilege: [null],
};
let node = 4;
if (x.orgChild1Id == null) {
@ -83,13 +73,23 @@ class CheckAuth {
} else if (x.orgChild4Id == null) {
node = 3;
}
if (privilege == "ROOT") {
if (privilege == "OWNER") {
data = {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
privilege: "OWNER",
};
} else if (privilege == "ROOT") {
data = {
root: [x.orgRootId],
child1: null,
child2: null,
child3: null,
child4: null,
privilege: "ROOT",
};
} else if (privilege == "CHILD") {
data = {
@ -98,6 +98,7 @@ class CheckAuth {
child2: node >= 2 ? [x.orgChild2Id] : null,
child3: node >= 3 ? [x.orgChild3Id] : null,
child4: node >= 4 ? [x.orgChild4Id] : null,
privilege: "CHILD",
};
} else if (privilege == "NORMAL") {
data = {
@ -106,16 +107,9 @@ class CheckAuth {
child2: [x.orgChild2Id],
child3: [x.orgChild3Id],
child4: [x.orgChild4Id],
privilege: "NORMAL",
};
} else if (privilege == "SPECIFIC") {
} else if (privilege == "OWNER") {
data = {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
};
}
return data;
@ -145,16 +139,6 @@ class CheckAuth {
.GetData(req, `/org/permission/user/${system}/${action}/${profileId}`)
.then(async (x) => {
let org = x.org;
// if (action.trim().toLocaleUpperCase() == "CREATE")
// org = await this.PermissionOrgCreate(req, system);
// if (action.trim().toLocaleUpperCase() == "DELETE")
// org = await this.PermissionOrgDelete(req, system);
// if (action.trim().toLocaleUpperCase() == "GET")
// org = await this.PermissionOrgGet(req, system);
// if (action.trim().toLocaleUpperCase() == "LIST")
// org = await this.PermissionOrgList(req, system);
// if (action.trim().toLocaleUpperCase() == "UPDATE")
// org = await this.PermissionOrgUpdate(req, system);
if (org.root != null) if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
if (org.child1 != null)
@ -176,6 +160,26 @@ class CheckAuth {
}
});
}
public async Workflow(req: RequestWithUser, id: string, sysName: string) {
if (
req.headers.hasOwnProperty("api_key") &&
req.headers["api_key"] &&
req.headers["api_key"] == process.env.API_KEY
) {
return null;
}
return await new CallAPI()
.PostData(req, "/org/workflow/keycloak/isofficer", {
refId: id,
sysName: sysName,
})
.then((x) => {
return true;
})
.catch((x) => {
return false;
});
}
public async PermissionCreate(req: RequestWithUser, system: string) {
return await this.Permission(req, system, "CREATE");
}