Skip to content

Commit

Permalink
feat: update user creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ferruhcihan committed Oct 4, 2024
1 parent efcd26c commit 5575ba9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/operator/keycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,13 @@ async function addUserGroups(api: any, existingUser: any, teamGroups: string[])
}

async function createUpdateUser(api: any, user: any) {
const { email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams } = user
const { email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams, initialPassword } = user
const teamGroups = [
...(isPlatformAdmin ? ['platform-admin'] : []),
...(isTeamAdmin ? ['team-admin'] : []),
...(teams.length > 0 ? teams.map((team) => `team-${team}`) : []),
]
const userConf = createTeamUser(email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teamGroups)
const userConf = createTeamUser(email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teamGroups, initialPassword)
const existingUsersByUserEmail = (await doApiCall([], `Getting users`, () =>
api.users.realmUsersGet(keycloakRealm, false, `${email}`),
)) as UserRepresentation[]
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/keycloak/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const teamUserCfgTpl = (
isPlatformAdmin: boolean,
isTeamAdmin: boolean,
teamGroups: string[],
initialPassword: string,
): Record<string, unknown> => ({
username: email,
enabled: true,
Expand All @@ -89,7 +90,7 @@ export const teamUserCfgTpl = (
credentials: [
{
type: 'password',
value: `${email}`,
value: `${initialPassword}`,
temporary: true,
},
],
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/keycloak/realm-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ export function createTeamUser(
isPlatformAdmin: boolean,
isTeamAdmin: boolean,
teamGroups: string[],
initialPassword: string,
): UserRepresentation {
const userRepresentation = defaultsDeep(
new UserRepresentation(),
teamUserCfgTpl(email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teamGroups),
teamUserCfgTpl(email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teamGroups, initialPassword),
)
return userRepresentation
}
Expand Down

0 comments on commit 5575ba9

Please sign in to comment.