]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Modal dialogs are still open when UI is redirected to the login screen 23328/head
authorVolker Theile <vtheile@suse.com>
Mon, 30 Jul 2018 15:22:41 +0000 (17:22 +0200)
committerVolker Theile <vtheile@suse.com>
Wed, 1 Aug 2018 07:43:02 +0000 (09:43 +0200)
Fixes https://tracker.ceph.com/issues/24570

Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts

index f2df1e8646d7d2699ae806dbff626031f76f88fa..e03aaf866b761b7a6846a6f416d4eff55210cd12 100644 (file)
@@ -1,11 +1,9 @@
 import { HttpClientTestingModule } from '@angular/common/http/testing';
 import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { FormsModule } from '@angular/forms';
 import { RouterTestingModule } from '@angular/router/testing';
 
 import { configureTestBed } from '../../../../testing/unit-test-helper';
-import { AuthService } from '../../../shared/api/auth.service';
-import { AuthStorageService } from '../../../shared/services/auth-storage.service';
+import { AuthModule } from '../auth.module';
 import { LoginComponent } from './login.component';
 
 describe('LoginComponent', () => {
@@ -13,9 +11,7 @@ describe('LoginComponent', () => {
   let fixture: ComponentFixture<LoginComponent>;
 
   configureTestBed({
-    imports: [FormsModule, RouterTestingModule, HttpClientTestingModule],
-    declarations: [LoginComponent],
-    providers: [AuthService, AuthStorageService]
+    imports: [RouterTestingModule, HttpClientTestingModule, AuthModule]
   });
 
   beforeEach(() => {
@@ -27,4 +23,10 @@ describe('LoginComponent', () => {
   it('should create', () => {
     expect(component).toBeTruthy();
   });
+
+  it('should ensure no modal dialogs are opened', () => {
+    component.bsModalService.modalsCount = 2;
+    component.ngOnInit();
+    expect(component.bsModalService.getModalsCount()).toBe(0);
+  });
 });
index a1ff473e80c7c2ea5a3cbec4d5fbdcd26511acfe..1fc8b92058ba430b595bf1400ed9a0f6e3164f9a 100644 (file)
@@ -1,6 +1,8 @@
 import { Component, OnInit } from '@angular/core';
 import { Router } from '@angular/router';
 
+import { BsModalService } from 'ngx-bootstrap';
+
 import { AuthService } from '../../../shared/api/auth.service';
 import { Credentials } from '../../../shared/models/credentials';
 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
@@ -16,12 +18,21 @@ export class LoginComponent implements OnInit {
   constructor(
     private authService: AuthService,
     private authStorageService: AuthStorageService,
+    private bsModalService: BsModalService,
     private router: Router
   ) {}
 
   ngOnInit() {
     if (this.authStorageService.isLoggedIn()) {
       this.router.navigate(['']);
+    } else {
+      // Make sure all open modal dialogs are closed. This might be
+      // necessary when the logged in user is redirected to the login
+      // page after a 401.
+      const modalsCount = this.bsModalService.getModalsCount();
+      for (let i = 1; i <= modalsCount; i++) {
+        this.bsModalService.hide(i);
+      }
     }
   }