Skip to content

Commit

Permalink
feat(users): ✨ Include keycloak data if wanted
Browse files Browse the repository at this point in the history
  • Loading branch information
Nudelsuppe42 committed Jul 21, 2024
1 parent d6dc312 commit eb7d3d3
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class UserController {

if (!req.kauth.grant) ERROR_NO_PERMISSION(req, res);

const user = await this.core.getPrisma().user.findFirst({
let user;

const dbUser = await this.core.getPrisma().user.findFirst({
where: {
id: req.params.id,
},
Expand Down Expand Up @@ -186,6 +188,8 @@ class UserController {
},
},
});
user = dbUser;

const buildTeamManager = await this.core.getPrisma().buildTeam.findMany({
where: {
UserPermission: {
Expand All @@ -208,6 +212,20 @@ class UserController {
});
user.createdBuildTeams = user.createdBuildTeams.concat(buildTeamManager);

if (req.query.withKeycloak) {
const kcUser = await this.core
.getKeycloakAdmin()
.getKeycloakAdminClient()
.users.findOne({
id: user.ssoId,
});
user.email = kcUser?.email;
user.username = kcUser?.username;
user.enabled = kcUser?.enabled;
user.emailVerified = kcUser?.emailVerified;
user.createdTimestamp = kcUser?.createdTimestamp;
}

if (user.ssoId == req.kauth.grant.access_token.content.sub) {
res.send(user);
} else if (
Expand Down Expand Up @@ -575,4 +593,4 @@ async function userHasPermissionsInAnyTeam(
}
}
return false;
}
}

0 comments on commit eb7d3d3

Please sign in to comment.