Skip to content

Commit 1007db2

Browse files
authored
Merge pull request #676 from BIX-Digital/feature/GH-675-handle-logout-in-spa
Handle logout in SPA
2 parents 37e7260 + bd9a243 commit 1007db2

File tree

21 files changed

+206
-166
lines changed

21 files changed

+206
-166
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66

7+
- Handle logout in SPA ([#675](https://github.com/opendevstack/ods-provisioning-app/issues/675))
78
- Handle form based auth in SPA ([#637](https://github.com/opendevstack/ods-provisioning-app/issues/637))
89
- Add default permissions to project groups on project creation ([#636](https://github.com/opendevstack/ods-provisioning-app/pull/636))
910
- Add support for odsbox for local development([#579](https://github.com/opendevstack/ods-provisioning-app/issues/579))

client/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="logo">
55
<h1>ODS Provisioning</h1>
66
</div>
7-
<div class="user-area" hidden>
7+
<div class="user-area" *ngIf="showLogoutButton">
88
<div class="user-area__logout">
99
<a
1010
mat-mini-fab

client/src/app/app.component.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { catchError } from 'rxjs/operators';
66
import { EMPTY } from 'rxjs';
77
import { EditModeFlag } from './modules/edit-mode/domain/edit-mode';
88
import { StorageService } from './modules/storage/services/storage.service';
9-
import { ActivatedRoute, NavigationStart, Router } from '@angular/router';
9+
import { NavigationStart, Router } from '@angular/router';
1010
import { ProjectService } from './modules/project/services/project.service';
1111
import { ProjectData, ProjectStorage } from './domain/project';
1212
import { AuthenticationService } from './modules/authentication/services/authentication.service';
@@ -21,13 +21,13 @@ export class AppComponent implements OnInit {
2121
isError: boolean;
2222
isNewProjectFormActive = false;
2323
hideSidebar = false;
24+
showLogoutButton = true;
2425

2526
projects: ProjectData[] = [];
2627

2728
constructor(
2829
public editMode: EditModeService,
2930
public router: Router,
30-
private activatedRoute: ActivatedRoute,
3131
private matIconRegistry: MatIconRegistry,
3232
private domSanitizer: DomSanitizer,
3333
private renderer: Renderer2,
@@ -40,35 +40,20 @@ export class AppComponent implements OnInit {
4040
}
4141

4242
ngOnInit() {
43-
this.activatedRoute.queryParams.subscribe(params => {
44-
if (params['sso']) {
45-
this.setSsoMode();
46-
}
47-
});
43+
this.authenticationService.checkAndSetSsoMode();
4844

4945
this.router.events.subscribe(event => {
5046
if (event instanceof NavigationStart) {
5147
if (event.url === '/') {
5248
this.loadAllProjects();
49+
} else if (event.url === '/login' || event.url === '/logout') {
50+
this.showLogoutButton = false;
51+
this.isLoading = false;
5352
}
54-
this.isLoading = false;
55-
}
56-
});
57-
}
58-
59-
private setSsoMode() {
60-
this.authenticationService.sso = true;
61-
this.router.navigate([], {
62-
queryParams: {
63-
sso: null
6453
}
6554
});
6655
}
6756

68-
private isSsoActive() {
69-
return this.authenticationService.sso;
70-
}
71-
7257
getEditModeStatus() {
7358
this.editMode.getEditModeFlag.subscribe((editMode: EditModeFlag) => {
7459
if (editMode.enabled) {
@@ -87,6 +72,8 @@ export class AppComponent implements OnInit {
8772
const projectKey = this.getProjectKeyFormStorage();
8873
if (projectKey) {
8974
this.router.navigateByUrl(`/project/${projectKey}`);
75+
} else {
76+
this.router.navigateByUrl('/project');
9077
}
9178
}
9279

@@ -100,6 +87,7 @@ export class AppComponent implements OnInit {
10087
.getAllProjects()
10188
.pipe(
10289
catchError(() => {
90+
// show generic error page
10391
this.isLoading = false;
10492
this.isError = true;
10593
return EMPTY;

client/src/app/modules/authentication/services/authentication.service.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Inject, Injectable } from '@angular/core';
22
import { HttpClient, HttpHeaders } from '@angular/common/http';
33
import { API_AUTH_URL, API_LOGOUT_URL } from '../../../tokens';
4+
import { ActivatedRoute, Router } from '@angular/router';
45

56
@Injectable({
67
providedIn: 'root'
@@ -10,18 +11,25 @@ export class AuthenticationService {
1011

1112
constructor(
1213
private httpClient: HttpClient,
14+
private activatedRoute: ActivatedRoute,
15+
private router: Router,
1316
@Inject(API_AUTH_URL) private apiAuthUrl: string,
1417
@Inject(API_LOGOUT_URL) private apiLogoutUrl: string
1518
) {}
1619

17-
set sso(enabled: boolean) {
18-
this._sso = enabled;
19-
}
20-
2120
get sso(): boolean {
2221
return this._sso;
2322
}
2423

24+
checkAndSetSsoMode() {
25+
this.activatedRoute.queryParams.subscribe(params => {
26+
if (params['sso']) {
27+
this._sso = true;
28+
this.removeSsoUrlParam();
29+
}
30+
});
31+
}
32+
2533
login(username: string, password: string): any {
2634
const formData: FormData = new FormData();
2735
formData.append('username', username);
@@ -34,6 +42,14 @@ export class AuthenticationService {
3442
}
3543

3644
logout(): any {
37-
return this.httpClient.post<any>(this.apiLogoutUrl, '');
45+
return this.httpClient.get<any>(this.apiLogoutUrl);
46+
}
47+
48+
private removeSsoUrlParam() {
49+
this.router.navigate([], {
50+
queryParams: {
51+
sso: null
52+
}
53+
});
3854
}
3955
}

client/src/app/modules/error-handler/http-request-interceptor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest } from '@angular/common/http';
3-
import { Observable, throwError } from 'rxjs';
3+
import { EMPTY, Observable, throwError } from 'rxjs';
44
import { catchError } from 'rxjs/operators';
55
import { Router } from '@angular/router';
66
import { AuthenticationService } from '../authentication/services/authentication.service';
@@ -42,6 +42,7 @@ export class HttpRequestInterceptor implements HttpInterceptor {
4242
catchError((error: HttpErrorResponse) => {
4343
if (error.status === 401) {
4444
this.router.navigateByUrl(this.authenticationService.sso ? '/' : '/login');
45+
return EMPTY;
4546
}
4647

4748
// TODO Improvement idea:

client/src/app/modules/general-error-page/components/general-error-page.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="empty-content">
22
<div class="infobox">
33
<div class="infobox__img">
4-
<img src="assets/icons/project-not-found.svg" alt="General error" />
4+
<img src="assets/icons/error.svg" alt="General error" />
55
</div>
66
<div class="infobox__headline">General error</div>
77
<div class="infobox__subline">There was a problem fetching initial data. Please try again soon.</div>

client/src/app/modules/logout/components/logout.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="empty-content" data-test-login *ngIf="!isLoading">
66
<div class="infobox">
77
<div class="infobox__img">
8-
<img src="assets/icons/quickstarter-not-found.svg" alt="Logged out" />
8+
<img src="assets/icons/quickstarters.svg" alt="Logged out" />
99
</div>
1010
<div class="infobox__headline">Logout successfully</div>
1111
<div class="infobox__subline">You might login again</div>

client/src/app/modules/new-project/components/new-project.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="empty-content">
88
<div class="infobox">
99
<div class="infobox__img">
10-
<img src="assets/icons/project-empty.svg" alt="Project template data could not be retrieved" />
10+
<img src="assets/icons/error.svg" alt="Project template data could not be retrieved" />
1111
</div>
1212
<div class="infobox__headline">Project template data could not be retrieved</div>
1313
<div class="infobox__subline">Please try again soon</div>

client/src/app/modules/project-page/components/project-page.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
<div class="empty-content">
88
<div class="infobox" *ngIf="errorType === 'NOT_FOUND'">
99
<div class="infobox__img">
10-
<img src="assets/icons/project-not-found.svg" alt="Project was not found" />
10+
<img src="assets/icons/error.svg" alt="Project was not found" />
1111
</div>
1212
<div class="infobox__headline">Project was not found</div>
1313
<div class="infobox__subline">Please check URL or select another project.</div>
1414
</div>
1515
<div class="infobox" *ngIf="errorType === 'NO_PROJECT_KEY'">
1616
<div class="infobox__img">
17-
<img src="assets/icons/project-empty.svg" alt="No project selected" />
17+
<img src="assets/icons/error.svg" alt="No project selected" />
1818
</div>
1919
<div class="infobox__headline">No project selected</div>
2020
<div class="infobox__subline">Select or create a project to see more detail.</div>
2121
</div>
2222
<div class="infobox" *ngIf="errorType === 'TECHNICAL_ERROR'">
2323
<div class="infobox__img">
24-
<img src="assets/icons/project-empty.svg" alt="Technical error" />
24+
<img src="assets/icons/error.svg" alt="Technical error" />
2525
</div>
2626
<div class="infobox__headline">Technical error</div>
2727
<div class="infobox__subline">There was a technical error retrieving the project. Please try again soon.</div>

client/src/app/modules/project-page/components/quickstarter-list.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<ng-container *ngIf="hasPlatformRuntime; else noPlatformRuntime">
7676
<div class="infobox" data-test-qs-list-platform-runtime-yes>
7777
<div class="infobox__img">
78-
<img src="assets/icons/quickstarter-not-found.svg" alt="No quickstarters applied yet" />
78+
<img src="assets/icons/quickstarters.svg" alt="No quickstarters applied yet" />
7979
</div>
8080
<div class="infobox__headline">No quickstarters applied yet</div>
8181
<div class="infobox__subline">Add new components to your project</div>
@@ -93,7 +93,7 @@
9393
<ng-template #noPlatformRuntime>
9494
<div class="infobox" data-test-qs-list-platform-runtime-no>
9595
<div class="infobox__img">
96-
<img src="assets/icons/quickstarter-not-found.svg" alt="No quickstarters possible" />
96+
<img src="assets/icons/quickstarters.svg" alt="No quickstarters possible" />
9797
</div>
9898
<div class="infobox__headline">No quickstarters possible in this project</div>
9999
<div class="infobox__subline">Quickstarters can only be applied in OpenShift projects</div>

0 commit comments

Comments
 (0)