From: Volker Theile Date: Mon, 30 Jul 2018 15:22:41 +0000 (+0200) Subject: mgr/dashboard: Modal dialogs are still open when UI is redirected to the login screen X-Git-Tag: v14.0.1~698^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=969645efeee9e2e79d05fa1433e8707d40723d94;p=ceph.git mgr/dashboard: Modal dialogs are still open when UI is redirected to the login screen Fixes https://tracker.ceph.com/issues/24570 Signed-off-by: Volker Theile --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts index f2df1e8646d7d..e03aaf866b761 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.spec.ts @@ -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; 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); + }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts index a1ff473e80c7c..1fc8b92058ba4 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts @@ -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); + } } }