feature/833 Add customized logout url for taskana web application.

This commit is contained in:
Martin Rojas Miguel Angel 2019-03-27 13:45:48 +01:00 committed by Holger Hagen
parent 47bcdfa259
commit 66b7bf4b04
8 changed files with 123 additions and 50 deletions

View File

@ -1,3 +1,4 @@
{
"taskanaRestUrl": ""
"taskanaRestUrl": "",
"taskanaLogoutUrl": ""
}

View File

@ -91,7 +91,7 @@ export class NavBarComponent implements OnInit, OnDestroy {
logout() {
this.taskanaEngineService.logout().subscribe(() => {
})
this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/logout';
this.window.nativeWindow.location.href = environment.taskanaLogoutUrl;
}
showDomainSelector(): boolean {

View File

@ -0,0 +1,62 @@
import {TestBed, inject, getTestBed} from '@angular/core/testing';
import {StartupService} from './startup.service'
import {HttpClient, HttpClientModule} from '@angular/common/http';
import {CustomFieldsService} from '../custom-fields/custom-fields.service';
import {TaskanaEngineService} from '../taskana-engine/taskana-engine.service';
import {WindowRefService} from '../window/window.service';
import {environment} from '../../../environments/environment';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
fdescribe('StartupService', () => {
const environmentFile = '/environments/data-sources/environment-information.json';
const someRestUrl = 'someRestUrl';
const someLogoutUrl = 'someLogoutUrl';
const dummyEnvironmentInformation = {
'taskanaRestUrl': someRestUrl,
'taskanaLogoutUrl': someLogoutUrl
}
let httpMock, service;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
HttpClientTestingModule
],
providers: [
StartupService,
HttpClient,
CustomFieldsService,
TaskanaEngineService,
WindowRefService
]
});
});
beforeEach(() => {
const injector = getTestBed();
httpMock = injector.get(HttpTestingController);
// UserService provided to the TestBed
service = TestBed.get(StartupService);
})
it('should be created', inject([StartupService], () => {
expect(service).toBeTruthy();
}));
it('should initialize rest and logout url from external file', (done) => {
environment.taskanaRestUrl = '';
environment.taskanaLogoutUrl = '';
service.getEnvironmentFilePromise().then((res) => {
expect(environment.taskanaRestUrl).toBe(someRestUrl);
expect(environment.taskanaLogoutUrl).toBe(someLogoutUrl);
done();
})
const req = httpMock.expectOne(environmentFile);
expect(req.request.method).toBe('GET');
req.flush(dummyEnvironmentInformation);
httpMock.verify();
});
});

View File

@ -10,52 +10,59 @@ import { WindowRefService } from 'app/services/window/window.service';
@Injectable()
export class StartupService {
constructor(
private httpClient: HttpClient,
private customFieldsService: CustomFieldsService,
private taskanaEngineService: TaskanaEngineService,
private injector: Injector,
private window: WindowRefService) { }
constructor(
private httpClient: HttpClient,
private customFieldsService: CustomFieldsService,
private taskanaEngineService: TaskanaEngineService,
private injector: Injector,
private window: WindowRefService) {
}
load(): Promise<any> {
return this.loadEnvironment();
}
load(): Promise<any> {
return this.loadEnvironment();
}
private loadEnvironment() {
return this.getEnvironmentFilePromise().then(
() => this.geCustomizedFieldsFilePromise()
).then(
() => this.taskanaEngineService.getUserInformation()
).catch(error => {
this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/login';
});
}
private loadEnvironment() {
return this.getEnvironmentFilePromise().then(
() => this.geCustomizedFieldsFilePromise()
).then(
() => this.taskanaEngineService.getUserInformation()
).catch(error => {
this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/login';
});
}
getEnvironmentFilePromise() {
return this.httpClient.get<any>('environments/data-sources/environment-information.json').pipe(map(jsonFile => {
if (jsonFile && environment.taskanaRestUrl === '') {
environment.taskanaRestUrl = jsonFile.taskanaRestUrl === '' ?
window.location.protocol + '//' + window.location.host : jsonFile.taskanaRestUrl;
this.customFieldsService.initCustomFields('EN', jsonFile);
}
})).toPromise()
.catch(() => {
return of(true)
});
}
getEnvironmentFilePromise() {
return this.httpClient.get<any>('/environments/data-sources/environment-information.json').pipe(map(jsonFile => {
if (jsonFile && environment.taskanaRestUrl === '') {
environment.taskanaRestUrl = jsonFile.taskanaRestUrl === '' ?
window.location.protocol + '//' + window.location.host : jsonFile.taskanaRestUrl;
}
geCustomizedFieldsFilePromise() {
return this.httpClient.get<any>('environments/data-sources/taskana-customization.json').pipe(map(jsonFile => {
if (jsonFile) {
this.customFieldsService.initCustomFields('EN', jsonFile);
}
})).toPromise()
.catch(() => {
return of(true)
});
}
if (jsonFile && environment.taskanaLogoutUrl === '') {
environment.taskanaLogoutUrl = jsonFile.taskanaLogoutUrl === '' ?
environment.taskanaRestUrl + '/logout' : jsonFile.taskanaLogoutUrl;
public get router(): Router {
return this.injector.get(Router);
}
}
this.customFieldsService.initCustomFields('EN', jsonFile);
})).toPromise()
.catch(() => {
return of(true)
});
}
geCustomizedFieldsFilePromise() {
return this.httpClient.get<any>('environments/data-sources/taskana-customization.json').pipe(map(jsonFile => {
if (jsonFile) {
this.customFieldsService.initCustomFields('EN', jsonFile);
}
})).toPromise()
.catch(() => {
return of(true)
});
}
public get router(): Router {
return this.injector.get(Router);
}
}

View File

@ -40,7 +40,7 @@ export class TaskanaEngineService {
logout(): Observable<string> {
return this.httpClient
.post<string>(`${environment.taskanaRestUrl}/logout`, '');
.post<string>(`${environment.taskanaLogoutUrl}`, '');
}

View File

@ -1,3 +1,4 @@
{
"taskanaRestUrl": ""
}
"taskanaRestUrl": "",
"taskanaLogoutUrl": ""
}

View File

@ -1,4 +1,5 @@
export const environment = {
production: true,
taskanaRestUrl: ''
taskanaRestUrl: '',
taskanaLogoutUrl: ''
};

View File

@ -5,5 +5,6 @@
export const environment = {
production: false,
taskanaRestUrl: 'http://localhost:8080'
taskanaRestUrl: 'http://localhost:8080',
taskanaLogoutUrl: 'http://localhost:8080/logout'
};