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() { logout() {
this.taskanaEngineService.logout().subscribe(() => { this.taskanaEngineService.logout().subscribe(() => {
}) })
this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/logout'; this.window.nativeWindow.location.href = environment.taskanaLogoutUrl;
} }
showDomainSelector(): boolean { 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() @Injectable()
export class StartupService { export class StartupService {
constructor( constructor(
private httpClient: HttpClient, private httpClient: HttpClient,
private customFieldsService: CustomFieldsService, private customFieldsService: CustomFieldsService,
private taskanaEngineService: TaskanaEngineService, private taskanaEngineService: TaskanaEngineService,
private injector: Injector, private injector: Injector,
private window: WindowRefService) { } private window: WindowRefService) {
}
load(): Promise<any> { load(): Promise<any> {
return this.loadEnvironment(); return this.loadEnvironment();
} }
private loadEnvironment() { private loadEnvironment() {
return this.getEnvironmentFilePromise().then( return this.getEnvironmentFilePromise().then(
() => this.geCustomizedFieldsFilePromise() () => this.geCustomizedFieldsFilePromise()
).then( ).then(
() => this.taskanaEngineService.getUserInformation() () => this.taskanaEngineService.getUserInformation()
).catch(error => { ).catch(error => {
this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/login'; this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/login';
}); });
} }
getEnvironmentFilePromise() { getEnvironmentFilePromise() {
return this.httpClient.get<any>('environments/data-sources/environment-information.json').pipe(map(jsonFile => { return this.httpClient.get<any>('/environments/data-sources/environment-information.json').pipe(map(jsonFile => {
if (jsonFile && environment.taskanaRestUrl === '') { if (jsonFile && environment.taskanaRestUrl === '') {
environment.taskanaRestUrl = jsonFile.taskanaRestUrl === '' ? environment.taskanaRestUrl = jsonFile.taskanaRestUrl === '' ?
window.location.protocol + '//' + window.location.host : jsonFile.taskanaRestUrl; window.location.protocol + '//' + window.location.host : jsonFile.taskanaRestUrl;
this.customFieldsService.initCustomFields('EN', jsonFile); }
}
})).toPromise()
.catch(() => {
return of(true)
});
}
geCustomizedFieldsFilePromise() { if (jsonFile && environment.taskanaLogoutUrl === '') {
return this.httpClient.get<any>('environments/data-sources/taskana-customization.json').pipe(map(jsonFile => { environment.taskanaLogoutUrl = jsonFile.taskanaLogoutUrl === '' ?
if (jsonFile) { environment.taskanaRestUrl + '/logout' : jsonFile.taskanaLogoutUrl;
this.customFieldsService.initCustomFields('EN', jsonFile);
}
})).toPromise()
.catch(() => {
return of(true)
});
}
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> { logout(): Observable<string> {
return this.httpClient 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 = { export const environment = {
production: true, production: true,
taskanaRestUrl: '' taskanaRestUrl: '',
taskanaLogoutUrl: ''
}; };

View File

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