Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: redirect issues #353

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,10 @@ export const deleteOrganization = (organizationId: string) => {
(x) => x.id !== organizationId,
);
};

export const findOrganizationByUserId = (userId: string): string | null => {
const organization = TEST_ORGANIZATIONS.find((org) =>
org.memberList.some((member) => member.userId === userId),
);
return organization ? organization.id : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -291,30 +291,45 @@ export const TEST_USERS: UserInfo[] = [
buildUserInfo(ALL_USERS['00000000-0000-0000-0000-00000014']),
buildUserInfo(ALL_USERS['00000000-0000-0000-0000-000000000006']),
buildUserInfo(ALL_USERS['00000000-0000-0000-0000-00000011']),
{
authenticationStatus: 'UNAUTHENTICATED',
userId: 'unauthenticated',
roles: ['UNAUTHENTICATED'],
registrationStatus: undefined,
firstName: 'Unauthenticated',
lastName: 'User',
organizationName: 'No Organization',
organizationId: 'unauthenticated',
},
buildUnauthenticatedUserInfo(),
];

/**
* Currently "logged-in user" for local dev UI
*/
let currentlyLoggedInUser: UserInfo = buildUserInfo(
ALL_USERS['00000000-0000-0000-0000-000000000001'],
);
// let currentlyLoggedInUser: UserInfo = buildUserInfo(
// ALL_USERS['00000000-0000-0000-0000-000000000001'],
// );

let currentlyLoggedInUser = buildUnauthenticatedUserInfo();

/**
* Update currently logged-in User for local dev UI
*/
export const updateLoggedInUser = (patcher: Patcher<UserInfo>) => {
currentlyLoggedInUser = patchObj<UserInfo>(currentlyLoggedInUser, patcher);
localStorage.setItem(
'fakeUserId',
JSON.stringify(currentlyLoggedInUser.userId),
);
};

export const updateLoggedInUserById = (userId: string) => {
currentlyLoggedInUser = buildUserInfo(ALL_USERS[userId]);
localStorage.setItem('fakeUserId', JSON.stringify(userId));
};

export const fakeLogin = (userId?: string) => {
if (userId && Object.keys(ALL_USERS).includes(userId)) {
updateLoggedInUserById(userId);
} else {
updateLoggedInUserById('00000000-0000-0000-0000-000000000001');
}
};

export const fakeLogout = () => {
currentlyLoggedInUser = buildUnauthenticatedUserInfo();
localStorage.removeItem('fakeUserId');
};

/**
Expand Down Expand Up @@ -498,6 +513,7 @@ const patchUser = (userId: string, patcher: Patcher<UserDetailDto>) => {
};

function buildUserInfo(user: UserDetailDto): UserInfo {
console.log('user?' + user.userId);
return {
authenticationStatus: 'AUTHENTICATED',
userId: user.userId,
Expand All @@ -510,6 +526,19 @@ function buildUserInfo(user: UserDetailDto): UserInfo {
};
}

function buildUnauthenticatedUserInfo(): UserInfo {
return {
authenticationStatus: 'UNAUTHENTICATED',
userId: 'unauthenticated',
roles: ['UNAUTHENTICATED'],
registrationStatus: undefined,
firstName: 'Unauthenticated',
lastName: 'User',
organizationName: 'No Organization',
organizationId: 'unauthenticated',
};
}

const deleteUser = (userId: string): IdResponse => {
delete ALL_USERS[userId];
return {id: userId, changedDate: new Date()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import {
REJECTED_ROUTES,
UNAUTHENTICATED_ROUTES,
} from '../../../app-routing.module';
import {
updateLoggedInUser,
updateLoggedInUserById,
} from '../../api/fake-backend/impl/fake-users';
import {ActiveFeatureSet} from '../../services/config/active-feature-set';
import {AuthorityPortalPageSet} from './authority-portal-page-set';
import {UrlBeforeLoginService} from './url-before-login.service';
Expand All @@ -48,7 +52,17 @@ export class RouteConfigService {
private router: Router,
private urlBeforeLoginService: UrlBeforeLoginService,
private activeFeatureSet: ActiveFeatureSet,
) {}
) {
console.log('RouteConfigService created');
try {
let fakeUserId = localStorage.getItem('fakeUserId');
if (fakeUserId) {
updateLoggedInUserById(JSON.parse(fakeUserId));
}
} catch (e) {
console.error(e);
}
}

decidePageSet(userInfoFetched: Fetched<UserInfo>): AuthorityPortalPageSet {
if (!userInfoFetched.isReady) {
Expand Down Expand Up @@ -106,8 +120,10 @@ export class RouteConfigService {
.then(() => {
if (this.urlBeforeLoginService.originalUrl != '') {
this.urlBeforeLoginService.goToOriginalUrl();
localStorage.removeItem('originalUrl');
} else {
this.router.navigate([this.defaultRoute]);
localStorage.removeItem('originalUrl');
}
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const requiresRole: CanActivateFn = (route: ActivatedRouteSnapshot) => {
if (hasAnyRole) {
return true;
} else {
router.navigate(['/unauthorized']);
router.navigate(['/dashboard']);
return false;
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
.pipe(
takeUntil(this.ngOnDestroy$),
map((data) => data.catalogType === 'my-data-offers'),
distinctUntilChanged(),
tap((isMyDataOffers) => {
this.headerConfig = this.buildHeaderConfig(isMyDataOffers);
}),
switchMap((isMyDataOffers) => {
if (isMyDataOffers) {
return this.globalStateUtils.userInfo$.pipe(
take(1),
map((it) => it.organizationId),
distinctUntilChanged(),
);
}

Expand Down Expand Up @@ -279,7 +278,6 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
}

private setTitle() {
let title;
this.catalogType === 'my-data-offers'
? this.titleService.setTitle('My Data Offers')
: this.titleService.setTitle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
import {Injectable} from '@angular/core';
import {FormBuilder} from '@angular/forms';
import {Observable} from 'rxjs';
import {ignoreElements, switchMap, take, tap} from 'rxjs/operators';
import {
filter,
ignoreElements,
retry,
switchMap,
take,
tap,
} from 'rxjs/operators';
import {Action, State, StateContext} from '@ngxs/store';
import {UserDetailDto} from '@sovity.de/authority-portal-client';
import {ApiService} from 'src/app/core/api/api.service';
Expand Down Expand Up @@ -50,6 +57,7 @@ export class ControlCenterUserEditPageStateImpl {
@Action(Reset)
onReset(ctx: Ctx, action: Reset): Observable<never> {
return this.globalStateUtils.userInfo$.pipe(
filter((user) => user.authenticationStatus === 'AUTHENTICATED'),
take(1),
switchMap((userInfo) =>
this.apiService.getUserDetailDto(userInfo.userId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
import {Inject, Injectable} from '@angular/core';
import {Router} from '@angular/router';
import {Observable} from 'rxjs';
import {ignoreElements, switchMap, take, tap} from 'rxjs/operators';
import {
filter,
ignoreElements,
retry,
switchMap,
take,
takeUntil,
tap,
} from 'rxjs/operators';
import {Action, State, StateContext} from '@ngxs/store';
import {UserDetailDto, UserRoleDto} from '@sovity.de/authority-portal-client';
import {ApiService} from 'src/app/core/api/api.service';
Expand Down Expand Up @@ -49,10 +57,11 @@ export class ControlCenterUserProfilePageStateImpl {
@Action(Reset)
onReset(ctx: Ctx, action: Reset): Observable<never> {
return this.globalStateUtils.userInfo$.pipe(
take(1),
switchMap((userInfo) =>
this.apiService.getUserDetailDto(userInfo.userId),
),
filter((user) => !!user),
take(1),
Fetched.wrap({failureMessage: 'Failed to fetch user details'}),
tap((user) => {
ctx.patchState({
Expand All @@ -67,6 +76,7 @@ export class ControlCenterUserProfilePageStateImpl {
.orElse(null),
});
}),
takeUntil(action.componentLifetime$),
ignoreElements(),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div
class="flex flex-col justify-center items-center h-screen w-screen top-0 left-0 absolute">
<h1 class="full-screen-end-title">Page Not Found</h1>
<h1 class="full-screen-end-title">Oops</h1>
<p class="full-screen-end-prose">
We're sorry, but the page you requested could not be found.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@
</p>
<div class="flex items-center flex-col gap-2">
<a
*ngIf="!this.appConfig.useFakeBackend"
id="btn-login"
class="w-[300px] bg-black hover:bg-black text-white font-bold py-2 px-4 rounded active:scale-[0.99]"
[attr.href]="loginUrl">
(click)="login('')">
Log In
</a>
<select
*ngIf="this.appConfig.useFakeBackend"
class="w-[300px] bg-white text-black border border-gray-700 font-bold py-2 px-4 rounded active:scale-[0.99]"
(change)="login($event)">
<option class="text-center" value="">Select Fake Backend User</option>
<option
*ngFor="let user of fakeBackendUserIds"
class="text-center"
[value]="fakeBackendUsers[user]['userId']">
{{ fakeBackendUsers[user]['firstName'] }}
{{ fakeBackendUsers[user]['lastName'] }}
</option>
</select>
<a
id="btn-register-organization"
class="w-[300px] bg-white text-black border border-gray-700 font-bold py-2 px-4 rounded active:scale-[0.99]"
routerLink="/create-organization">
Register Organization
</a>
</div>
</div>

<!-- footer -->
<app-footer-for-full-page></app-footer-for-full-page>
<!-- footer -->
<app-footer-for-full-page></app-footer-for-full-page>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
*/
import {Component, Inject} from '@angular/core';
import {Title} from '@angular/platform-browser';
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({
selector: 'app-unauthenticated-page',
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');
Expand All @@ -31,4 +41,12 @@ export class UnauthenticatedPageComponent {
url.searchParams.set('redirect_uri', location.href);
return url.toString();
}

login(event: any): void {
if (this.appConfig.useFakeBackend) {
fakeLogin(event.target.value);
} else {
location.href = this.loginUrl;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* sovity GmbH - initial implementation
*/
import {Component, Inject, OnInit, ViewChild} from '@angular/core';
import {Component, Inject, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {MatStepper} from '@angular/material/stepper';
import {Title} from '@angular/platform-browser';
Expand Down Expand Up @@ -59,7 +59,7 @@ import {
selector: 'app-organization-onboard-page',
templateUrl: './organization-onboard-page.component.html',
})
export class OrganizationOnboardPageComponent implements OnInit {
export class OrganizationOnboardPageComponent implements OnInit, OnDestroy {
state = DEFAULT_ORGANIZATION_ONBOARD_PAGE_PAGE_STATE;
parentFormGroup!: FormGroup<OnboardingWizardFormModel>;
showForm: boolean = false;
Expand Down Expand Up @@ -94,7 +94,7 @@ export class OrganizationOnboardPageComponent implements OnInit {
}

ngOnInit(): void {
this.store.dispatch(Reset);
this.store.dispatch(new Reset(this.ngOnDestroy$));
this.startListeningToState();
this.setupFormOnce();
}
Expand Down Expand Up @@ -182,4 +182,9 @@ export class OrganizationOnboardPageComponent implements OnInit {
),
);
}

ngOnDestroy(): void {
this.ngOnDestroy$.next(null);
this.ngOnDestroy$.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Contributors:
* sovity GmbH - initial implementation
*/
import {Observable} from 'rxjs';
import {
OnboardingOrganizationUpdateDto,
OnboardingUserUpdateDto,
Expand All @@ -34,4 +35,5 @@ export class OnboardingProcessFormSubmit {

export class Reset {
static readonly type = `[${tag}] Reset`;
constructor(public componentLifetime$: Observable<any>) {}
}
Loading
Loading