no message
This commit is contained in:
parent
d897c8c041
commit
fa52b33786
4 changed files with 1007 additions and 13 deletions
|
|
@ -32,12 +32,12 @@ class CheckAuth {
|
|||
let permission = false;
|
||||
let role = x.roles.find((x: any) => x.authSysId == system);
|
||||
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
|
||||
if (role.attrOwnership == "OWNER") return "OWNER";
|
||||
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
|
||||
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
|
||||
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
|
||||
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
|
||||
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
|
||||
if (role.attrOwnership == "OWNER") permission = true;
|
||||
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
|
||||
return role.attrPrivilege;
|
||||
})
|
||||
|
|
@ -45,6 +45,87 @@ class CheckAuth {
|
|||
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||
});
|
||||
}
|
||||
public async PermissionOrg(req: RequestWithUser, system: string, action: 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()
|
||||
.GetData(req, "/org/permission/org")
|
||||
.then(async (x) => {
|
||||
let privilege = null;
|
||||
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],
|
||||
child1: [null],
|
||||
child2: [null],
|
||||
child3: [null],
|
||||
child4: [null],
|
||||
};
|
||||
let node = 4;
|
||||
if (x.orgChild1Id == null) {
|
||||
node = 0;
|
||||
} else if (x.orgChild2Id == null) {
|
||||
node = 1;
|
||||
} else if (x.orgChild3Id == null) {
|
||||
node = 2;
|
||||
} else if (x.orgChild4Id == null) {
|
||||
node = 3;
|
||||
}
|
||||
if (privilege == "ROOT") {
|
||||
data = {
|
||||
root: [x.orgRootId],
|
||||
child1: null,
|
||||
child2: null,
|
||||
child3: null,
|
||||
child4: null,
|
||||
};
|
||||
} else if (privilege == "CHILD") {
|
||||
data = {
|
||||
root: node >= 0 ? [x.orgRootId] : null,
|
||||
child1: node >= 1 ? [x.orgChild1Id] : null,
|
||||
child2: node >= 2 ? [x.orgChild2Id] : null,
|
||||
child3: node >= 3 ? [x.orgChild3Id] : null,
|
||||
child4: node >= 4 ? [x.orgChild4Id] : null,
|
||||
};
|
||||
} else if (privilege == "NORMAL") {
|
||||
data = {
|
||||
root: [x.orgRootId],
|
||||
child1: [x.orgChild1Id],
|
||||
child2: [x.orgChild2Id],
|
||||
child3: [x.orgChild3Id],
|
||||
child4: [x.orgChild4Id],
|
||||
};
|
||||
} else if (privilege == "SPECIFIC") {
|
||||
} else if (privilege == "OWNER") {
|
||||
data = {
|
||||
root: null,
|
||||
child1: null,
|
||||
child2: null,
|
||||
child3: null,
|
||||
child4: null,
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
})
|
||||
.catch((x) => {
|
||||
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||
});
|
||||
}
|
||||
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||
return await this.Permission(req, system, "CREATE");
|
||||
}
|
||||
|
|
@ -60,6 +141,22 @@ class CheckAuth {
|
|||
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
||||
return await this.Permission(req, system, "UPDATE");
|
||||
}
|
||||
|
||||
public async PermissionOrgCreate(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "CREATE");
|
||||
}
|
||||
public async PermissionOrgDelete(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "DELETE");
|
||||
}
|
||||
public async PermissionOrgGet(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "GET");
|
||||
}
|
||||
public async PermissionOrgList(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "LIST");
|
||||
}
|
||||
public async PermissionOrgUpdate(req: RequestWithUser, system: string) {
|
||||
return await this.PermissionOrg(req, system, "UPDATE");
|
||||
}
|
||||
}
|
||||
|
||||
export default CheckAuth;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue