[ADF-3191] Fix userprefrence oauth2 (#3488)

* remove user preference setting save

* fix host setting test

* remove userPreferences test

* fix title service test

* remove unused imports

* restore input align

* fix service import in test tag rating
This commit is contained in:
Eugenio Romano
2018-06-15 08:32:16 +01:00
committed by GitHub
parent af2cde0791
commit 8966e22487
43 changed files with 417 additions and 528 deletions

View File

@@ -17,20 +17,20 @@
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot, CanActivate,
CanActivateChild, RouterStateSnapshot, Router
ActivatedRouteSnapshot, CanActivate,
CanActivateChild, RouterStateSnapshot, Router
} from '@angular/router';
import { AuthenticationService } from './authentication.service';
import { Observable } from 'rxjs/Observable';
import { AppConfigService } from '../app-config/app-config.service';
import { UserPreferencesService } from './user-preferences.service';
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
import { OauthConfigModel } from '../models/oauth-config.model';
@Injectable()
export class AuthGuard implements CanActivate, CanActivateChild {
constructor(private authService: AuthenticationService,
private router: Router,
private userPreference: UserPreferencesService,
private appConfig: AppConfigService) {}
private appConfig: AppConfigService) {
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | Observable<boolean> {
const redirectUrl = state.url;
@@ -45,8 +45,8 @@ export class AuthGuard implements CanActivate, CanActivateChild {
if (this.authService.isLoggedIn()) {
return true;
}
if (!this.authService.isOauth() || this.isOAuthWithoutSilentLogin() ) {
this.authService.setRedirect({ provider: 'ALL', url: redirectUrl } );
if (!this.authService.isOauth() || this.isOAuthWithoutSilentLogin()) {
this.authService.setRedirect({ provider: 'ALL', url: redirectUrl });
const pathToLogin = this.getRouteDestinationForLogin();
this.router.navigate(['/' + pathToLogin]);
@@ -56,12 +56,13 @@ export class AuthGuard implements CanActivate, CanActivateChild {
}
isOAuthWithoutSilentLogin() {
return this.authService.isOauth() && this.userPreference.oauthConfig.silentLogin === false;
let oauth: OauthConfigModel = this.appConfig.get<OauthConfigModel>(AppConfigValues.OAUTHCONFIG, null);
return this.authService.isOauth() && oauth.silentLogin === false;
}
public getRouteDestinationForLogin(): string {
return this.appConfig &&
this.appConfig.get<string>('loginRoute') ?
this.appConfig.get<string>('loginRoute') : 'login';
this.appConfig.get<string>(AppConfigValues.LOGIN_ROUTE) ?
this.appConfig.get<string>(AppConfigValues.LOGIN_ROUTE) : 'login';
}
}