This is an automated email from the ASF dual-hosted git repository.

ababiichuk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new b674486  [AMBARI-23748] - [Logsearch UI] Logout button does not 
navigate user to login/logged out page
b674486 is described below

commit b674486ef961243530bccc549ec16a8329a6c3f5
Author: Istvan Tobias <tobias.ist...@gmail.com>
AuthorDate: Fri May 4 00:38:16 2018 +0200

    [AMBARI-23748] - [Logsearch UI] Logout button does not navigate user to 
login/logged out page
---
 .../ambari-logsearch-web/src/app/app-routing.module.ts        |  4 +++-
 ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts   |  4 +++-
 .../src/app/services/auth-guard.service.ts                    |  2 +-
 .../src/app/services/auth.service.spec.ts                     | 11 ++++++++++-
 .../ambari-logsearch-web/src/app/services/auth.service.ts     |  9 +++++++--
 .../{auth-guard.service.ts => login-screen-guard.service.ts}  | 11 +++++------
 6 files changed, 29 insertions(+), 12 deletions(-)

diff --git 
a/ambari-logsearch/ambari-logsearch-web/src/app/app-routing.module.ts 
b/ambari-logsearch/ambari-logsearch-web/src/app/app-routing.module.ts
index 5fb281b..9a51050 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/app-routing.module.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/app-routing.module.ts
@@ -23,13 +23,15 @@ import {LoginFormComponent} from 
'@app/components/login-form/login-form.componen
 import {AuthGuardService} from '@app/services/auth-guard.service';
 import {TabGuard} from '@app/services/tab.guard';
 import {LogsBreadcrumbsResolverService} from 
'@app/services/logs-breadcrumbs-resolver.service';
+import {LoginScreenGuardService} from 
'@app/services/login-screen-guard.service';
 
 const appRoutes: Routes = [{
     path: 'login',
     component: LoginFormComponent,
     data: {
       breadcrumbs: 'login.title'
-    }
+    },
+    canActivate: [LoginScreenGuardService]
   }, {
     path: 'logs/:activeTab',
     component: LogsContainerComponent,
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts 
b/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts
index 8db8dea..b1121d5 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts
@@ -114,6 +114,7 @@ import {TabGuard} from '@app/services/tab.guard';
 import {LogsBreadcrumbsResolverService} from 
'@app/services/logs-breadcrumbs-resolver.service';
 import {LogsFilteringUtilsService} from 
'@app/services/logs-filtering-utils.service';
 import {LogsStateService} from '@app/services/storage/logs-state.service';
+import {LoginScreenGuardService} from 
'@app/services/login-screen-guard.service';
 
 export function getXHRBackend(
   injector: Injector, browser: BrowserXhr, xsrf: XSRFStrategy, options: 
ResponseOptions
@@ -239,7 +240,8 @@ export function getXHRBackend(
     HistoryManagerService,
     ClusterSelectionService,
     LogsFilteringUtilsService,
-    LogsStateService
+    LogsStateService,
+    LoginScreenGuardService
   ],
   bootstrap: [AppComponent],
   entryComponents: [
diff --git 
a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth-guard.service.ts 
b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth-guard.service.ts
index c940ce6..8b56239 100644
--- 
a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth-guard.service.ts
+++ 
b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth-guard.service.ts
@@ -23,7 +23,7 @@ import {Observable} from 'rxjs/Observable';
 import {AuthService} from '@app/services/auth.service';
 
 /**
- * This service meant to be a single place where the authorization should 
happen.
+ * This guard goal is to prevent to display screens where authorization needs.
  */
 @Injectable()
 export class AuthGuardService implements CanActivate {
diff --git 
a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts 
b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts
index c033052..74a7125 100644
--- 
a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts
+++ 
b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts
@@ -27,6 +27,8 @@ import {AppStateService, appState} from 
'@app/services/storage/app-state.service
 import {AuthService} from '@app/services/auth.service';
 import {HttpClientService} from '@app/services/http-client.service';
 import {RouterTestingModule} from '@angular/router/testing';
+import {Routes} from '@angular/router';
+import {Component} from '@angular/core';
 
 describe('AuthService', () => {
 
@@ -61,13 +63,20 @@ describe('AuthService', () => {
   };
 
   beforeEach(() => {
+    const testRoutes: Routes = [{
+      path: 'login',
+      component: Component,
+      data: {
+        breadcrumbs: 'login.title'
+      }
+    }];
     TestBed.configureTestingModule({
       imports: [
         HttpModule,
         StoreModule.provideStore({
           appState
         }),
-        RouterTestingModule
+        RouterTestingModule.withRoutes(testRoutes)
       ],
       providers: [
         AuthService,
diff --git 
a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts 
b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts
index f5fb4dc..1a26fe4 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts
@@ -55,9 +55,14 @@ export class AuthService {
   }
 
   onAppStateIsAuthorizedChanged = (isAuthorized): void => {
-    if (isAuthorized && this.redirectUrl) {
-      this.router.navigate(Array.isArray(this.redirectUrl) ? this.redirectUrl 
: [this.redirectUrl]);
+    if (isAuthorized) {
+      const redirectTo = this.redirectUrl || 
(this.router.routerState.snapshot.url === '/login' ? '/' : null);
+      if (redirectTo) {
+        this.router.navigate(Array.isArray(redirectTo) ? redirectTo : 
[redirectTo]);
+      }
       this.redirectUrl = '';
+    } else if (!isAuthorized) {
+      this.router.navigate(['/login']);
     }
   }
   /**
diff --git 
a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth-guard.service.ts 
b/ambari-logsearch/ambari-logsearch-web/src/app/services/login-screen-guard.service.ts
similarity index 82%
copy from 
ambari-logsearch/ambari-logsearch-web/src/app/services/auth-guard.service.ts
copy to 
ambari-logsearch/ambari-logsearch-web/src/app/services/login-screen-guard.service.ts
index c940ce6..8dbe1d7 100644
--- 
a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth-guard.service.ts
+++ 
b/ambari-logsearch/ambari-logsearch-web/src/app/services/login-screen-guard.service.ts
@@ -23,20 +23,19 @@ import {Observable} from 'rxjs/Observable';
 import {AuthService} from '@app/services/auth.service';
 
 /**
- * This service meant to be a single place where the authorization should 
happen.
+ * The goal of this guard service is to prevent to display the login screen 
when the user is logged in.
  */
 @Injectable()
-export class AuthGuardService implements CanActivate {
+export class LoginScreenGuardService implements CanActivate {
 
   constructor(private authService: AuthService, private router: Router) {}
 
   canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): 
Observable<boolean> {
     return this.authService.isAuthorized().map((isAuthorized: boolean) => {
-      this.authService.redirectUrl = state.url;
-      if (!isAuthorized) {
-        this.router.navigate(['/login']);
+      if (isAuthorized && state.url === '/login') {
+        this.router.navigate(['/']);
       }
-      return isAuthorized;
+      return !isAuthorized;
     });
   }
 

-- 
To stop receiving notification emails like this one, please contact
ababiic...@apache.org.

Reply via email to