Skip to content

Commit

Permalink
TCVP-2687 modified the lookup functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Sai Krishna Metpalli authored and Sai Krishna Metpalli committed Jun 7, 2024
1 parent d74f712 commit edca13d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/frontend/staff-portal/src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class AuthService {

private site: string = "staff-api";
private roles = [
{ name: UserGroup.JUDICIAL_JUSTICE, redirectUrl: AppRoutes.JJ },
{ name: UserGroup.VTC_STAFF, redirectUrl: AppRoutes.STAFF },
{ name: [UserGroup.JUDICIAL_JUSTICE, UserGroup.ADMIN_JUDICIAL_JUSTICE, UserGroup.SUPPORT_STAFF], redirectUrl: AppRoutes.JJ },
{ name: [UserGroup.VTC_STAFF, UserGroup.SUPPORT_STAFF], redirectUrl: AppRoutes.STAFF },
]

constructor(
Expand All @@ -35,8 +35,8 @@ export class AuthService {
private toastService: ToastService,
private logger: LoggerService,
private configService: ConfigService,
private lookupsService: LookupsService, // to be moved
private store: Store<AppState>, // to be moved
private lookupsService: LookupsService,
private store: Store<AppState>,
) {
this.keycloak.keycloakEvents$.subscribe({
next(event) {
Expand All @@ -56,24 +56,11 @@ export class AuthService {
.pipe(
map((response: boolean) => {
if (response) {
this.loadUserProfile().subscribe(() => { // to be moved
this.loadUserProfile().subscribe(() => {
this._isLoggedIn.next(response);
if (this.isLoggedIn && this.isInit) {
this.userProfile$.pipe(first()).subscribe(() => {
this.isInit = false;
let observables = [
this.loadUsersLists(),
this.lookupsService.init()
];

forkJoin(observables).subscribe({
next: results => {
this.store.dispatch(JJDisputeStore.Actions.Get());
},
error: err => {
this.logger.error("Landing Page Init: Initial data loading failed");
}
});
this.isInit = false;
})
}
return response;
Expand All @@ -86,6 +73,22 @@ export class AuthService {
);
}

loadLookupData(){
let observables = [
this.loadUsersLists(),
this.lookupsService.init()
];

forkJoin(observables).subscribe({
next: results => {
this.store.dispatch(JJDisputeStore.Actions.Get());
},
error: err => {
this.logger.error("Landing Page Init: Initial data loading failed");
}
});
}

get token(): string {
return this.keycloak.getKeycloakInstance().token;
}
Expand Down Expand Up @@ -176,10 +179,12 @@ export class AuthService {
getRedirectUrl(): string {
var result;
this.roles.forEach(r => {
if (this.keycloak.isUserInRole(r.name, this.site)) {
result = r.redirectUrl;
}
})
r.name.forEach(n => {
if (this.keycloak.isUserInRole(n, this.site)) {
result = r.redirectUrl;
}
});
});
if (!result) {
result = AppRoutes.UNAUTHORIZED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { NavigationEnd, Router, Scroll } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { AppRoutes } from 'app/app.routes';
import { AppConfigService } from 'app/services/app-config.service';
import { AuthService, KeycloakProfile } from 'app/services/auth.service';
import { filter } from 'rxjs';
Expand Down Expand Up @@ -54,6 +55,9 @@ export class HeaderComponent implements OnInit {
this.authService.isLoggedIn$.subscribe(isLoggedIn => {
this.isLoggedIn = isLoggedIn;
this.fullName = this.authService.userProfile?.fullName;
if(this.router.url.indexOf(AppRoutes.UNAUTHORIZED) === -1){
this.authService.loadLookupData();
}
})
})
}
Expand Down

0 comments on commit edca13d

Please sign in to comment.