This commit is contained in:
Adisak 2025-11-04 09:51:33 +07:00
parent d6383ec2c4
commit ca7d2f2a75
2 changed files with 29 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import {
Patch, Patch,
Path, Path,
Post, Post,
Query,
Request, Request,
Route, Route,
Security, Security,
@ -36,8 +37,21 @@ export class AuthRoleController extends Controller {
private redis = require("redis"); private redis = require("redis");
@Get("list") @Get("list")
public async listAuthRole() { public async listAuthRole(
const getList = await this.authRoleRepo.find(); @Request() req: RequestWithUser,
@Query("isAdminVisibled ") isAdminVisibled : string = "false",
) {
let condition: any = {};
if(isAdminVisibled.toLowerCase() === "true"){
condition = { isAdminVisibled: true };
}else{
condition = {};
}
const getList = await this.authRoleRepo.find(
{
where: condition,
}
);
// if (!getList || getList.length === 0) { // if (!getList || getList.length === 0) {
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// } // }
@ -161,6 +175,7 @@ export class AuthRoleController extends Controller {
body: { body: {
roleName: string; roleName: string;
roleDescription: string; roleDescription: string;
isAdminVisibled?: boolean;
authRoleAttrs: Array<{ authRoleAttrs: Array<{
// id: string; // id: string;
authSysId: string; authSysId: string;
@ -187,6 +202,7 @@ export class AuthRoleController extends Controller {
})); }));
Object.assign(record, { Object.assign(record, {
isAdminVisibled: body.isAdminVisibled?body.isAdminVisibled:false,
roleName: body.roleName, roleName: body.roleName,
roleDescription: body.roleDescription, roleDescription: body.roleDescription,
lastUpdateFullName: req.user.name, lastUpdateFullName: req.user.name,

View file

@ -758,11 +758,21 @@ export class KeycloakController extends Controller {
} }
@Get("user/role/{id}") @Get("user/role/{id}")
async getRoleUser(@Path("id") id: string) { async getRoleUser(@Request() req: RequestWithUser,@Path("id") id: string) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { keycloak: id }, where: { keycloak: id },
relations: ["roleKeycloaks"], relations: ["roleKeycloaks"],
}); });
if (
req.user.sub === id &&
req.user.role.some(x => x === 'ADMIN') &&
!req.user.role.some(x => x === 'SUPER_ADMIN')
) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่มีสิทธิ์เข้าถึงข้อมูลนี้");
}
if (!profile) { if (!profile) {
const profileEmp = await this.profileEmpRepo.findOne({ const profileEmp = await this.profileEmpRepo.findOne({
where: { keycloak: id, employeeClass: "PERM" }, where: { keycloak: id, employeeClass: "PERM" },