เช็ค update role keycloak #802
This commit is contained in:
parent
71d5ad0ab9
commit
102f1f6646
1 changed files with 58 additions and 36 deletions
|
|
@ -2172,26 +2172,30 @@ export class CommandController extends Controller {
|
||||||
if (clearProfile) {
|
if (clearProfile) {
|
||||||
if (profile.keycloak != null) {
|
if (profile.keycloak != null) {
|
||||||
const delUserKeycloak = await deleteUser(profile.keycloak);
|
const delUserKeycloak = await deleteUser(profile.keycloak);
|
||||||
if (delUserKeycloak) profile.keycloak = _null;
|
if (delUserKeycloak) {
|
||||||
profile.roleKeycloaks = [];
|
profile.keycloak = _null;
|
||||||
|
profile.roleKeycloaks = [];
|
||||||
|
profile.isActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
profile.position = _null;
|
profile.position = _null;
|
||||||
profile.posTypeId = _null;
|
profile.posTypeId = _null;
|
||||||
profile.posLevelId = _null;
|
profile.posLevelId = _null;
|
||||||
}
|
}
|
||||||
const returnWork = await checkReturnCommandType(String(item.commandId));
|
const returnWork = await checkReturnCommandType(String(item.commandId));
|
||||||
|
//คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user
|
||||||
if (returnWork && item.isGovernment) {
|
if (returnWork && item.isGovernment) {
|
||||||
if (profile.keycloak != null) {
|
/*if (profile.keycloak != null) {
|
||||||
const enableActive = await enableStatus(profile.keycloak, true);
|
const enableActive = await enableStatus(profile.keycloak, true);
|
||||||
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
|
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
|
||||||
} else {
|
} else {*/
|
||||||
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
||||||
firstName: profile.firstName,
|
firstName: profile.firstName,
|
||||||
lastName: profile.lastName,
|
lastName: profile.lastName,
|
||||||
});
|
});
|
||||||
if (typeof userKeycloakId !== "string") {
|
// if (typeof userKeycloakId !== "string") {
|
||||||
throw new Error(userKeycloakId.errorMessage);
|
// throw new Error(userKeycloakId.errorMessage);
|
||||||
}
|
// }
|
||||||
const list = await getRoles();
|
const list = await getRoles();
|
||||||
if (!Array.isArray(list))
|
if (!Array.isArray(list))
|
||||||
throw new Error("Failed. Cannot get role(s) data from the server.");
|
throw new Error("Failed. Cannot get role(s) data from the server.");
|
||||||
|
|
@ -2204,11 +2208,11 @@ export class CommandController extends Controller {
|
||||||
name: x.name,
|
name: x.name,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
if (!result) throw new Error("Failed. Cannot set user's role.");
|
// if (!result) throw new Error("Failed. Cannot set user's role.");
|
||||||
profile.keycloak = userKeycloakId;
|
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||||
}
|
/*}*/
|
||||||
profile.isActive = true;
|
profile.isActive = true;
|
||||||
profile.roleKeycloaks = profile.roleKeycloaks ?? [roleKeycloak];
|
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||||
}
|
}
|
||||||
await this.profileRepository.save(profile);
|
await this.profileRepository.save(profile);
|
||||||
}),
|
}),
|
||||||
|
|
@ -2297,9 +2301,11 @@ export class CommandController extends Controller {
|
||||||
if (clearProfile) {
|
if (clearProfile) {
|
||||||
if (profile.keycloak != null) {
|
if (profile.keycloak != null) {
|
||||||
const delUserKeycloak = await deleteUser(profile.keycloak);
|
const delUserKeycloak = await deleteUser(profile.keycloak);
|
||||||
if (delUserKeycloak) profile.keycloak = _null;
|
if (delUserKeycloak) {
|
||||||
profile.roleKeycloaks = [];
|
profile.keycloak = _null;
|
||||||
profile.isActive = false;
|
profile.roleKeycloaks = [];
|
||||||
|
profile.isActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
profile.position = _null;
|
profile.position = _null;
|
||||||
profile.posTypeId = _null;
|
profile.posTypeId = _null;
|
||||||
|
|
@ -2373,8 +2379,11 @@ export class CommandController extends Controller {
|
||||||
if (clearProfile) {
|
if (clearProfile) {
|
||||||
if (profile.keycloak != null) {
|
if (profile.keycloak != null) {
|
||||||
const delUserKeycloak = await deleteUser(profile.keycloak);
|
const delUserKeycloak = await deleteUser(profile.keycloak);
|
||||||
if (delUserKeycloak) profile.keycloak = _null;
|
if (delUserKeycloak) {
|
||||||
profile.roleKeycloaks = [];
|
profile.keycloak = _null;
|
||||||
|
profile.roleKeycloaks = [];
|
||||||
|
profile.isActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
profile.position = _null;
|
profile.position = _null;
|
||||||
profile.posTypeId = _null;
|
profile.posTypeId = _null;
|
||||||
|
|
@ -2615,17 +2624,27 @@ export class CommandController extends Controller {
|
||||||
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
const exceptClear = await checkExceptCommandType(String(item.commandId));
|
||||||
if (item.isLeave == true && !exceptClear) {
|
if (item.isLeave == true && !exceptClear) {
|
||||||
await removeProfileInOrganize(_profile.id, "OFFICER");
|
await removeProfileInOrganize(_profile.id, "OFFICER");
|
||||||
} else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
}
|
||||||
const enableActive = await enableStatus(_profile.keycloak, false);
|
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
|
||||||
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
|
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
|
||||||
_profile.isActive = false;
|
// const enableActive = await enableStatus(_profile.keycloak, false);
|
||||||
|
// if (!enableActive) throw new Error("Failed. Cannot change enable status.");
|
||||||
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
|
if (delUserKeycloak) {
|
||||||
|
_profile.keycloak = _null;
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
_profile.isActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const clearProfile = await checkCommandType(String(item.commandId));
|
const clearProfile = await checkCommandType(String(item.commandId));
|
||||||
if (clearProfile) {
|
if (clearProfile) {
|
||||||
if (_profile.keycloak != null) {
|
if (_profile.keycloak != null) {
|
||||||
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
if (delUserKeycloak) _profile.keycloak = _null;
|
if (delUserKeycloak) {
|
||||||
_profile.roleKeycloaks = [];
|
_profile.keycloak = _null;
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
_profile.isActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_profile.position = _null;
|
_profile.position = _null;
|
||||||
_profile.posTypeId = _null;
|
_profile.posTypeId = _null;
|
||||||
|
|
@ -2903,8 +2922,11 @@ export class CommandController extends Controller {
|
||||||
if (clearProfile) {
|
if (clearProfile) {
|
||||||
if (_profile.keycloak != null) {
|
if (_profile.keycloak != null) {
|
||||||
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
const delUserKeycloak = await deleteUser(_profile.keycloak);
|
||||||
if (delUserKeycloak) _profile.keycloak = _null;
|
if (delUserKeycloak) {
|
||||||
_profile.roleKeycloaks = [];
|
_profile.keycloak = _null;
|
||||||
|
_profile.roleKeycloaks = [];
|
||||||
|
_profile.isActive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_profile.position = _null;
|
_profile.position = _null;
|
||||||
_profile.posTypeId = _null;
|
_profile.posTypeId = _null;
|
||||||
|
|
@ -2989,9 +3011,9 @@ export class CommandController extends Controller {
|
||||||
firstName: profile.firstName,
|
firstName: profile.firstName,
|
||||||
lastName: profile.lastName,
|
lastName: profile.lastName,
|
||||||
});
|
});
|
||||||
if (typeof userKeycloakId !== "string") {
|
// if (typeof userKeycloakId !== "string") {
|
||||||
throw new Error(userKeycloakId.errorMessage);
|
// throw new Error(userKeycloakId.errorMessage);
|
||||||
}
|
// }
|
||||||
const list = await getRoles();
|
const list = await getRoles();
|
||||||
if (!Array.isArray(list))
|
if (!Array.isArray(list))
|
||||||
throw new Error("Failed. Cannot get role(s) data from the server.");
|
throw new Error("Failed. Cannot get role(s) data from the server.");
|
||||||
|
|
@ -3004,9 +3026,9 @@ export class CommandController extends Controller {
|
||||||
name: x.name,
|
name: x.name,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
if (!result) throw new Error("Failed. Cannot set user's role.");
|
// if (!result) throw new Error("Failed. Cannot set user's role.");
|
||||||
profile.keycloak = userKeycloakId;
|
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
|
||||||
profile.roleKeycloaks = roleKeycloak ? [roleKeycloak] : [];
|
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||||
profile.email = item.bodyProfile.email;
|
profile.email = item.bodyProfile.email;
|
||||||
profile.dateStart = item.bodyProfile.dateStart;
|
profile.dateStart = item.bodyProfile.dateStart;
|
||||||
await this.profileRepository.save(profile);
|
await this.profileRepository.save(profile);
|
||||||
|
|
@ -3322,9 +3344,9 @@ export class CommandController extends Controller {
|
||||||
lastName: profile.lastName,
|
lastName: profile.lastName,
|
||||||
// email: profile.email,
|
// email: profile.email,
|
||||||
});
|
});
|
||||||
if (typeof userKeycloakId !== "string") {
|
// if (typeof userKeycloakId !== "string") {
|
||||||
throw new Error(userKeycloakId.errorMessage);
|
// throw new Error(userKeycloakId.errorMessage);
|
||||||
}
|
// }
|
||||||
const list = await getRoles();
|
const list = await getRoles();
|
||||||
if (!Array.isArray(list))
|
if (!Array.isArray(list))
|
||||||
throw new Error("Failed. Cannot get role(s) data from the server.");
|
throw new Error("Failed. Cannot get role(s) data from the server.");
|
||||||
|
|
@ -3337,9 +3359,9 @@ export class CommandController extends Controller {
|
||||||
name: x.name,
|
name: x.name,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
if (!result) throw new Error("Failed. Cannot set user's role.");
|
// if (!result) throw new Error("Failed. Cannot set user's role.");
|
||||||
profile.keycloak = userKeycloakId;
|
profile.keycloak = typeof userKeycloakId == "string" ? userKeycloakId : "";
|
||||||
profile.roleKeycloaks = roleKeycloak ? [roleKeycloak] : [];
|
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
|
||||||
// End Create Keycloak
|
// End Create Keycloak
|
||||||
|
|
||||||
positionNew.positionIsSelected = true;
|
positionNew.positionIsSelected = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue