Fix Bug 2340: Invalid error message in UI for some role permission 38/14238/1
authorSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Wed, 6 Mar 2024 10:49:04 +0000 (16:19 +0530)
committerSANDHYA.JS <sandhya.j@tataelxsi.co.in>
Wed, 6 Mar 2024 10:49:04 +0000 (16:19 +0530)
- Added access denied lack of permission notification while setting vim accounts id get, ns_instances:opps:id:get and  ns_instances:id:get as false.

Change-Id: I220690baacb09231499f24ca2a8138c13f2d56d0
Signed-off-by: SANDHYA.JS <sandhya.j@tataelxsi.co.in>
src/app/vim-accounts/info-vim/InfoVimComponent.ts
src/services/RestService.ts

index b89a1b9..02aea69 100644 (file)
@@ -22,6 +22,8 @@ import { isNullOrUndefined } from 'util';
 import { Component, Injector, OnInit } from '@angular/core';
 import { ActivatedRoute, Router } from '@angular/router';
 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
+import { TranslateService } from '@ngx-translate/core';
+import { NotifierService } from 'angular-notifier';
 import { ERRORDATA } from 'CommonModel';
 import { DataService } from 'DataService';
 import { environment } from 'environment';
@@ -82,12 +84,20 @@ export class InfoVimComponent implements OnInit {
   /** Utilizes modal service for any modal operations @private */
   private modalService: NgbModal;
 
+  /** Handle translate @public */
+  private translateService: TranslateService;
+
+  /** Notifier service to popup notification @private */
+  private notifierService: NotifierService;
+
   constructor(injector: Injector) {
     this.injector = injector;
     this.restService = this.injector.get(RestService);
     this.dataService = this.injector.get(DataService);
     this.activatedRoute = this.injector.get(ActivatedRoute);
     this.modalService = this.injector.get(NgbModal);
+    this.translateService = this.injector.get(TranslateService);
+    this.notifierService = this.injector.get(NotifierService);
     this.router = this.injector.get(Router);
   }
 
@@ -141,10 +151,15 @@ export class InfoVimComponent implements OnInit {
         this.isLoadingResults = false;
       }, (error: ERRORDATA) => {
         this.isLoadingResults = false;
-        if (error.error.status === HttpStatus.NOT_FOUND || error.error.status === HttpStatus.UNAUTHORIZED) {
+        if (error.error.status === HttpStatus.NOT_FOUND) {
           this.router.navigateByUrl('404', { skipLocationChange: true }).catch((): void => {
             // Catch Navigation Error
           });
+        } else if (error.error.status === HttpStatus.UNAUTHORIZED) {
+          this.notifierService.notify('error', this.translateService.instant('HTTPERROR.401'));
+          this.router.navigate(['/vim/details']).catch((): void => {
+            // Catch Navigation Error
+          });
         } else {
           this.restService.handleError(error, 'get');
         }
index bea559a..d3d9ea0 100644 (file)
@@ -141,8 +141,11 @@ export class RestService {
                     this.notifierService.notify('error', err.error.detail !== undefined ?
                         err.error.detail : this.translateService.instant('HTTPERROR.401'));
                 }
-                this.activeModal.dismissAll();
+            } else {
+                this.notifierService.notify('error', err?.error?.detail !== undefined ?
+                    err?.error?.detail : this.translateService.instant('HTTPERROR.401'));
             }
+            this.activeModal.dismissAll();
         } else if (err.error.status === HttpStatus.BAD_REQUEST) {
             this.notifierService.notify('error', err.error.detail !== undefined ?
                 err.error.detail : this.translateService.instant('HTTPERROR.400'));
@@ -177,7 +180,7 @@ export class RestService {
         });
         return {
             url: apiURL,
-            httpOptions: {headers : apiHeaders}
+            httpOptions: { headers: apiHeaders }
         };
     }
 }