From 3456ce677cdbc5d756731888f981e9e3328e0d77 Mon Sep 17 00:00:00 2001
From: illfixit <66363651+illfixit@users.noreply.github.com>
Date: Fri, 18 Oct 2024 19:09:11 +0200
Subject: [PATCH] feat: fake logout support
---
.../src/app/app.component.html | 2 +-
.../core/api/fake-backend/impl/fake-users.ts | 16 ++++++---
.../unauthenticated-page.component.html | 36 +++++++++++++------
.../unauthenticated-page.component.ts | 15 ++++++--
.../logout-button.component.html | 3 +-
.../logout-button/logout-button.component.ts | 9 +++++
.../control-center.component.html | 2 +-
.../control-center.component.ts | 14 +++++++-
8 files changed, 76 insertions(+), 21 deletions(-)
diff --git a/authority-portal-frontend/src/app/app.component.html b/authority-portal-frontend/src/app/app.component.html
index e16a9366f..43d05a5a2 100644
--- a/authority-portal-frontend/src/app/app.component.html
+++ b/authority-portal-frontend/src/app/app.component.html
@@ -3,7 +3,7 @@
*ngIf="appConfig.useFakeBackend"
class="absolute t-[5px] w-full flex flex-row justify-end"
style="z-index: 9999">
-
+
diff --git a/authority-portal-frontend/src/app/core/api/fake-backend/impl/fake-users.ts b/authority-portal-frontend/src/app/core/api/fake-backend/impl/fake-users.ts
index d2ddfb405..c03f56a8a 100644
--- a/authority-portal-frontend/src/app/core/api/fake-backend/impl/fake-users.ts
+++ b/authority-portal-frontend/src/app/core/api/fake-backend/impl/fake-users.ts
@@ -310,10 +310,18 @@ export const updateLoggedInUser = (patcher: Patcher) => {
currentlyLoggedInUser = patchObj(currentlyLoggedInUser, patcher);
};
-export const fakeLogin = () => {
- currentlyLoggedInUser = buildUserInfo(
- ALL_USERS['00000000-0000-0000-0000-000000000001'],
- );
+export const fakeLogin = (userId?: string) => {
+ if (userId && Object.keys(ALL_USERS).includes(userId)) {
+ currentlyLoggedInUser = buildUserInfo(ALL_USERS[userId]);
+ } else {
+ currentlyLoggedInUser = buildUserInfo(
+ ALL_USERS['00000000-0000-0000-0000-000000000001'],
+ );
+ }
+};
+
+export const fakeLogout = () => {
+ currentlyLoggedInUser = buildUnauthenticatedUserInfo();
};
/**
diff --git a/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.html b/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.html
index becc4a4d7..86ad78ebd 100644
--- a/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.html
+++ b/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.html
@@ -12,20 +12,36 @@
-
-
-
+
+
+
diff --git a/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.ts b/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.ts
index 9f0f54bab..3e11b04fe 100644
--- a/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.ts
+++ b/authority-portal-frontend/src/app/pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component.ts
@@ -12,7 +12,12 @@
*/
import {Component, Inject} from '@angular/core';
import {Title} from '@angular/platform-browser';
-import {fakeLogin} from 'src/app/core/api/fake-backend/impl/fake-users';
+import {Store} from '@ngxs/store';
+import {
+ ALL_USERS,
+ fakeLogin,
+} from 'src/app/core/api/fake-backend/impl/fake-users';
+import {RefreshUserInfo} from 'src/app/core/global-state/global-state-actions';
import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
@Component({
@@ -20,8 +25,12 @@ import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
templateUrl: './unauthenticated-page.component.html',
})
export class UnauthenticatedPageComponent {
+ fakeBackendUserIds = Object.keys(ALL_USERS);
+ fakeBackendUsers = ALL_USERS;
+
constructor(
@Inject(APP_CONFIG) public appConfig: AppConfig,
+ public store: Store,
private titleService: Title,
) {
this.titleService.setTitle('Unauthenticated');
@@ -33,9 +42,9 @@ export class UnauthenticatedPageComponent {
return url.toString();
}
- login() {
+ login(event: any): void {
if (this.appConfig.useFakeBackend) {
- fakeLogin();
+ fakeLogin(event.target.value);
} else {
location.href = this.loginUrl;
}
diff --git a/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.html b/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.html
index 3dc2dcfc3..0958d7d43 100644
--- a/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.html
+++ b/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.html
@@ -1,5 +1,6 @@
+ (click)="logout()">
logoutLog Out
diff --git a/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.ts b/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.ts
index ef94a4f7e..31d5cc84f 100644
--- a/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.ts
+++ b/authority-portal-frontend/src/app/shared/common/logout-button/logout-button.component.ts
@@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, Inject} from '@angular/core';
+import {fakeLogout} from 'src/app/core/api/fake-backend/impl/fake-users';
import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
@Component({
@@ -19,4 +20,12 @@ import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
})
export class LogoutButtonComponent {
constructor(@Inject(APP_CONFIG) public appConfig: AppConfig) {}
+
+ logout() {
+ if (this.appConfig.useFakeBackend) {
+ fakeLogout();
+ } else {
+ location.href = this.appConfig.logoutUrl;
+ }
+ }
}
diff --git a/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.html b/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.html
index ee371ee19..73ab02e6d 100644
--- a/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.html
+++ b/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.html
@@ -55,7 +55,7 @@
+ (click)="logout()">
Logout
diff --git a/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.ts b/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.ts
index 356866997..770cbe699 100644
--- a/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.ts
+++ b/authority-portal-frontend/src/app/shared/common/portal-layout/control-center/control-center.component.ts
@@ -10,7 +10,9 @@
* Contributors:
* sovity GmbH - initial implementation
*/
-import {Component, Input, OnChanges} from '@angular/core';
+import {Component, Inject, Input, OnChanges} from '@angular/core';
+import {fakeLogout} from 'src/app/core/api/fake-backend/impl/fake-users';
+import {APP_CONFIG, AppConfig} from 'src/app/core/services/config/app-config';
import {AvatarConfig} from '../avatar/avatar.component';
import {ControlCenterModel} from './control-center.model';
@@ -25,10 +27,20 @@ export class ControlCenterComponent implements OnChanges {
userAvatar!: AvatarConfig;
userMenuOpen = false;
+ constructor(@Inject(APP_CONFIG) public appConfig: AppConfig) {}
+
ngOnChanges(): void {
this.userAvatar = {
firstName: this.userData.firstName,
lastName: this.userData.lastName,
};
}
+
+ logout(): void {
+ if (this.appConfig.useFakeBackend) {
+ fakeLogout();
+ } else {
+ location.href = this.logoutUrl;
+ }
+ }
}