Merge branch 'develop-Bright' into develop
This commit is contained in:
commit
ef3ff21ffd
2 changed files with 40 additions and 2 deletions
|
|
@ -28,6 +28,7 @@ import {
|
||||||
removeUserGroup,
|
removeUserGroup,
|
||||||
removeUserRoles,
|
removeUserRoles,
|
||||||
getRoleMappings,
|
getRoleMappings,
|
||||||
|
getUserCount
|
||||||
} from "../keycloak";
|
} from "../keycloak";
|
||||||
// import * as io from "../lib/websocket";
|
// import * as io from "../lib/websocket";
|
||||||
// import elasticsearch from "../elasticsearch";
|
// import elasticsearch from "../elasticsearch";
|
||||||
|
|
@ -199,10 +200,28 @@ export class KeycloakController extends Controller {
|
||||||
|
|
||||||
@Get("user")
|
@Get("user")
|
||||||
async getUserList(@Query() first = "", @Query() max = "" ,@Query() search = "") {
|
async getUserList(@Query() first = "", @Query() max = "" ,@Query() search = "") {
|
||||||
|
const total = await getUserCount();
|
||||||
const result = await getUserList(first, max, search);
|
const result = await getUserList(first, max, search);
|
||||||
|
|
||||||
if (Array.isArray(result)) {
|
if (Array.isArray(result)) {
|
||||||
return result;
|
const mappedData = await Promise.all(result.map(async (x) => {
|
||||||
|
const roles = await getRoleMappings(x.id);
|
||||||
|
return {
|
||||||
|
id: x.id,
|
||||||
|
username: x.username,
|
||||||
|
firstname: x.firstName,
|
||||||
|
lastname: x.lastName,
|
||||||
|
email: x.email,
|
||||||
|
roles: roles
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
|
||||||
|
const _mapData = {
|
||||||
|
data: mappedData,
|
||||||
|
total: total
|
||||||
|
};
|
||||||
|
|
||||||
|
return _mapData;
|
||||||
}
|
}
|
||||||
throw new Error("Failed. Cannot get user list.");
|
throw new Error("Failed. Cannot get user list.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ export async function getUserList(first = "", max = "", search = "") {
|
||||||
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((await res.json()) as any[]).slice(0, 5000).map((v: Record<string, string>) => ({
|
return ((await res.json()) as any[]).map((v: Record<string, string>) => ({
|
||||||
id: v.id,
|
id: v.id,
|
||||||
username: v.username,
|
username: v.username,
|
||||||
firstName: v.firstName,
|
firstName: v.firstName,
|
||||||
|
|
@ -150,6 +150,25 @@ export async function getUserList(first = "", max = "", search = "") {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getUserCount() {
|
||||||
|
const res = await fetch(
|
||||||
|
`${KC_URL}/admin/realms/${KC_REALM}/users/count`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"authorization": `Bearer ${await getToken()}`,
|
||||||
|
"content-type": `application/json`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
).catch((e) => console.log("Keycloak Error: ", e));
|
||||||
|
|
||||||
|
if (!res) return false;
|
||||||
|
if (!res.ok) {
|
||||||
|
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return await res.json();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update keycloak user by uuid
|
* Update keycloak user by uuid
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue