From f7733648053d18758c033996020be4af81756ae9 Mon Sep 17 00:00:00 2001
From: lpapadopoulos <lpapadopoulos@ubitech.eu>
Date: Tue, 28 May 2024 23:16:26 +0300
Subject: [PATCH] redirection logic

---
 .../edit-individuals.component.ts             |  2 --
 .../components/redirect/redirect.component.ts | 24 +------------
 src/app/shared/services/auth.service.ts       | 34 ++++++-------------
 3 files changed, 12 insertions(+), 48 deletions(-)

diff --git a/src/app/shared/components/partyManagement/edit-individuals/edit-individuals.component.ts b/src/app/shared/components/partyManagement/edit-individuals/edit-individuals.component.ts
index ca79f47..337b3f9 100644
--- a/src/app/shared/components/partyManagement/edit-individuals/edit-individuals.component.ts
+++ b/src/app/shared/components/partyManagement/edit-individuals/edit-individuals.component.ts
@@ -214,7 +214,6 @@ export class EditIndividualsComponent implements OnInit {
         }
       )
     }
-    // this.updateGeographicSite();
   }
 
   refreshIndividual(updatedIndividual: Individual) {
@@ -223,7 +222,6 @@ export class EditIndividualsComponent implements OnInit {
     if(this.testbedProvider) {
       this.retrieveGeographicSite()
       }
-    console.log("TODO-Retrieve Geographic Site info as well")//TODO
   }
 
   retrieveGeographicSite(){
diff --git a/src/app/shared/components/redirect/redirect.component.ts b/src/app/shared/components/redirect/redirect.component.ts
index fcd8950..aabf208 100644
--- a/src/app/shared/components/redirect/redirect.component.ts
+++ b/src/app/shared/components/redirect/redirect.component.ts
@@ -17,46 +17,24 @@ export class RedirectComponent implements OnInit {
   ) { }
 
   ngOnInit() {
-    // this.authService.fetchIndividualInfo();
-    let isTestbedProvider = false;
-    if(this.authService != null && this.authService.portalUserJWT !=null) {
-    for(var val of this.authService.portalUserJWT.realm_access.roles){
-      if (val ==='TESTBED_PROVIDER') {
-        isTestbedProvider=true
-        }
-    }}
-    //TODO insert redirection logic
+
     const activePortal = localStorage.getItem('active_portal')
 
     if (activePortal === 'services') {
-        if (isTestbedProvider){
-        this.router.navigate(['services', 'individual_update'])
-        }
-        else {
-      // this.router.navigate(['services', 'services_marketplace'])
       this.router.navigate(['services', 'individual_update'])
 
-      }
     }
     else if (activePortal === 'resources') {
       this.router.navigate(['resources', 'resource_catalogs'])
     }
     else if (activePortal === 'testing') {
 
-    if (isTestbedProvider){
       this.router.navigate(['testing', 'individual_update'])
-      } else {
-      this.router.navigate(['testing', 'service_test_specs'])
-      }
     }
 
     else if (activePortal === 'products') {
 
-    if (isTestbedProvider){
           this.router.navigate(['products', 'individual_update'])
-          } else {
-          this.router.navigate(['products', 'marketplace'])
-          }
     }
 
     else {
diff --git a/src/app/shared/services/auth.service.ts b/src/app/shared/services/auth.service.ts
index d2227e4..b233d46 100644
--- a/src/app/shared/services/auth.service.ts
+++ b/src/app/shared/services/auth.service.ts
@@ -37,12 +37,12 @@ export class AuthService {
   public portalUser: Individual
   public portalUserJWT: userFromJWT
 
-   constructor(    
+   constructor(
     private oauthService: OAuthService,
     private router: Router,
     private bootstrapService: BootstrapService,
     private individualService: IndividualService
-    ) 
+    )
   {
     window.addEventListener('storage', (event) => {
       // The `key` is `null` if the event was caused by `.clear()`
@@ -77,7 +77,7 @@ export class AuthService {
 
   public runInitialLoginSequence() {
     this.authConfigFile = this.bootstrapService.getConfig().OAUTH_CONFIG
-    
+
     this.oauthService.configure(this.authConfigFile);
     this.oauthService.setStorage(localStorage);
 
@@ -88,15 +88,15 @@ export class AuthService {
     this.oauthService.tryLoginCodeFlow()
     .catch(error => console.error(error))
     .then(
-      () => {       
+      () => {
         // console.warn('AccessTokenExpiration : ', new Date(this.oauthService.getAccessTokenExpiration()).toUTCString());
 
         if (this.oauthService.hasValidAccessToken()) {
           // console.warn('this.oauthService.hasValidAccessToken() === true')
           this.isAuthenticatedSubject$.next(this.oauthService.hasValidAccessToken());
           return Promise.resolve();
-        } 
-        
+        }
+
         //If Silent LOGIN isn't implemented
         else {
           // console.warn('this.oauthService.hasValidAccessToken() === false')
@@ -108,12 +108,12 @@ export class AuthService {
       this.isDoneLoadingSubject$.next(true)
     }
     )
-    .catch( error => { 
+    .catch( error => {
       this.isDoneLoadingSubject$.next(true)
     })
 
   }
-  
+
   public fetchUserInfo() {
     this.portalUserJWT = decode(this.getAccessToken())
     this.individualService.retrieveIndividual({id:'myuser'}).subscribe(
@@ -126,23 +126,11 @@ export class AuthService {
     )
   }
 
-  public fetchIndividualInfo() {
-    // this.portalUserJWT = decode(this.getAccessToken())
-    this.individualService.retrieveIndividual({id:'myuser'}).subscribe(
-      data => { this.portalUser = data },
-      error => {
-        console.error(error)
-        // this.toast.error('An error occurred fetching user information')
-        // this.logout()
-      }
-    )
-  }
-
   public login() {
     this.oauthService.initCodeFlow()
   }
 
-  public logout() { 
+  public logout() {
     // this.http.delete(authConfig.tokenEndpoint).subscribe(
     //   data => console.log(data)
     // )
@@ -150,7 +138,7 @@ export class AuthService {
     localStorage.clear()
 
     // this.http.delete(this.authConfigFile.tokenEndpoint).subscribe(
-    //   data => { 
+    //   data => {
     //     console.warn(data)
     //     this.oauthService.logOut()
     //     this.router.navigate([this.router.routerState.snapshot.url])
@@ -158,7 +146,7 @@ export class AuthService {
     //   error => {
     //     console.error(error)
     //     this.oauthService.logOut()
-    //     this.router.navigate([this.router.routerState.snapshot.url])        
+    //     this.router.navigate([this.router.routerState.snapshot.url])
     //   }
     // )
   }
-- 
GitLab