diff --git a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts index b5508d27f..3f533aa1d 100644 --- a/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/user-listing/user-listing-screen.component.ts @@ -59,7 +59,7 @@ export class UserListingScreenComponent extends BaseListingComponent imple .toPromise(); } - await this._loadData(true); + await this._loadData(); }); } @@ -83,7 +83,7 @@ export class UserListingScreenComponent extends BaseListingComponent imple this._loadingService.start(); user.roles = this.userService.isActive(user) ? [] : ['RED_USER']; await this._userControllerService.updateProfile(user, user.userId).toPromise(); - await this._loadData(true); + await this._loadData(); this._avatars.find(item => item.userId === user.userId).detectChanges(); } @@ -103,9 +103,9 @@ export class UserListingScreenComponent extends BaseListingComponent imple return this.userService.getName(user); } - private async _loadData(updateUserService = false) { + private async _loadData() { this.allEntities = await this._userControllerService.getAllUsers().toPromise(); - if (updateUserService) await this.userService.loadAllUsers(); + await this.userService.loadAllUsers(); this._executeSearchImmediately(); this._computeStats(); this._loadingService.stop(); diff --git a/apps/red-ui/src/app/services/user.service.ts b/apps/red-ui/src/app/services/user.service.ts index fb100e0b3..5aec1a941 100644 --- a/apps/red-ui/src/app/services/user.service.ts +++ b/apps/red-ui/src/app/services/user.service.ts @@ -89,10 +89,6 @@ export class UserService { return this._allRedUsers; } - get allUsers(): User[] { - return this._allUsers; - } - get userId(): string { return this._currentUser.id; } @@ -116,16 +112,19 @@ export class UserService { this._keycloakService.logout(window.location.origin + this._baseHref).then(); } - async loadAllUsersIfNecessary() { + async loadRedUsersIfNecessary() { if (!this._allRedUsers) { - await this.loadAllUsers(); + await this.loadRedUsers(); } } + async loadRedUsers() { + const allRedUsers = await this._userControllerService.getUsers().toPromise(); + this._allRedUsers = allRedUsers.filter(u => UserService._hasAnyRedRole(u)); + } + async loadAllUsers() { this._allUsers = await this._userControllerService.getAllUsers().toPromise(); - this._allRedUsers = this._allUsers.filter(u => UserService._hasAnyRedRole(u)); - return this._allUsers; } async loadCurrentUser() { @@ -144,11 +143,11 @@ export class UserService { } getUserById(id: string) { - return this._allUsers.find(u => u.userId === id); + return this._allUsers ? this._allUsers.find(u => u.userId === id) : this.getRedUserById(id); } getNameForId(userId: string) { - return this.getName(this.getRedUserById(userId) || this.getUserById(userId)); + return this.getName(this.getUserById(userId)); } getName(user?: User) { diff --git a/apps/red-ui/src/app/state/app-state.guard.ts b/apps/red-ui/src/app/state/app-state.guard.ts index 5ada1743f..4370d8944 100644 --- a/apps/red-ui/src/app/state/app-state.guard.ts +++ b/apps/red-ui/src/app/state/app-state.guard.ts @@ -15,11 +15,11 @@ export class AppStateGuard implements CanActivate { async canActivate(route: ActivatedRouteSnapshot): Promise { if (this._userService.user.isUserAdmin) { - await this._userService.loadAllUsersIfNecessary(); + await this._userService.loadRedUsersIfNecessary(); } if (this._userService.user.isUser || this._userService.user.isAdmin) { - await this._userService.loadAllUsersIfNecessary(); + await this._userService.loadRedUsersIfNecessary(); await this._appStateService.loadDossierTemplatesIfNecessary(); await this._appStateService.loadDictionaryDataIfNecessary(); }