Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Changed getAllUsers to getDevPortalUsers #13

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ describe('CreateDeveloperComponent', () => {
}
}];

const adminService = jasmine.createSpyObj('adminService', ['getKeycloakUsers', 'getAllClients']);
adminService.getKeycloakUsers.and.returnValue(from(
const adminService = jasmine.createSpyObj('adminService', ['getDevPortalUsers', 'getAllClients']);
adminService.getDevPortalUsers.and.returnValue(from(
keycloakUsers
));
adminService.getAllClients.and.returnValue(from(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CreateDeveloperComponent implements OnInit, OnDestroy {
* On init life circle
*/
ngOnInit(): void {
const getKeycloakUserTask = this.adminService.getKeycloakUsers().pipe(map(keycloakUsers => {
const getKeycloakUserTask = this.adminService.getDevPortalUsers().pipe(map(keycloakUsers => {
this.keycloakUsers = keycloakUsers;
this.filteredKeycloakUsers = keycloakUsers.filter((user => this.checkDeveloperNotExists(user.username)));
}));
Expand Down
8 changes: 4 additions & 4 deletions src/app/components/admin/services/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import {Inject, Injectable} from '@angular/core';
import {Observable, of} from 'rxjs';
import {catchError, map, mergeMap} from 'rxjs/operators';
import {from, Observable, of} from 'rxjs';
import {mergeMap} from 'rxjs/operators';
import {ClientSearchResult, Developer} from '../../../services/api-data.service';
import {HttpClient} from '@angular/common/http';
import {KeycloakInteractionService} from './keycloak-interaction.service';
Expand Down Expand Up @@ -57,8 +57,8 @@ export class AdminService {
/**
* Get all keycloak users
*/
public getKeycloakUsers() {
return this.keycloak.getAllUsers();
public getDevPortalUsers() {
return from(this.keycloak.getDevPortalUsers());
}

/**
Expand Down
21 changes: 16 additions & 5 deletions src/app/components/admin/services/keycloak-interaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import {Inject, Injectable} from '@angular/core';
import {KeycloakService} from 'keycloak-angular';
import KcAdminClient from 'keycloak-admin';
import {from} from 'rxjs';
import {map, mergeMap} from 'rxjs/operators';
import {TokenService} from '../../../services/token.service';
import UserRepresentation from 'keycloak-admin/lib/defs/userRepresentation';
import GroupRepresentation from 'keycloak-admin/lib/defs/groupRepresentation';

@Injectable({
providedIn: 'root'
Expand All @@ -28,6 +28,7 @@ export class KeycloakInteractionService {

private kcAdminClient: KcAdminClient;


/**
* Constructor of Keycloak Interaction Service
* @param keycloak the keycloak service
Expand Down Expand Up @@ -55,9 +56,19 @@ export class KeycloakInteractionService {

/**
* Get all keycloak users
* Max value: https://www.keycloak.org/docs-api/9.0/rest-api/index.html#_users_resource
* id, max value: https://www.keycloak.org/docs-api/12.0/rest-api/index.html#_groups_resource
*/
public getAllUsers() {
return from(this.kcAdminClient.users.find({max: (Math.pow(2, 31) - 1)}));
public async getDevPortalUsers(): Promise<UserRepresentation[]> {
const keycloakGroups: GroupRepresentation[] = [];
const devPortalGroups: GroupRepresentation[] = [];
const devPortalUsers: UserRepresentation[] = [];
keycloakGroups.push(...(await this.kcAdminClient.groups.find()));
devPortalGroups.push(...(keycloakGroups.filter(group => {
return group.name === 'API-Management-Developer-Portal-Users' || group.name === 'API-Management-Administrators';
})));
for (const group of devPortalGroups){
devPortalUsers.push(...(await this.kcAdminClient.groups.listMembers({id: group.id, max: (Math.pow(2, 31) - 1)})));
}
return devPortalUsers;
}
}