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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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 @@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {Subject, interval} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {Store} from '@ngxs/store';
Expand Down Expand Up @@ -60,7 +61,10 @@ export class AuthorityConnectorListPageComponent implements OnInit, OnDestroy {
private store: Store,
private globalStateUtils: GlobalStateUtils,
private slideOverService: SlideOverService,
) {}
private titleService: Title,
) {
this.titleService.setTitle('All Connectors');
}

ngOnInit() {
this.initializeHeaderBar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
import {MatDialog} from '@angular/material/dialog';
import {Title} from '@angular/platform-browser';
import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {Store} from '@ngxs/store';
Expand Down Expand Up @@ -73,7 +74,10 @@ export class AuthorityOrganizationListPageComponent
public dialog: MatDialog,
private slideOverService: SlideOverService,
private globalStateUtils: GlobalStateUtils,
) {}
private titleService: Title,
) {
this.titleService.setTitle('Participant Management');
}

ngOnInit() {
this.initializeHeaderBar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@angular/core';
import {FormControl} from '@angular/forms';
import {PageEvent} from '@angular/material/paginator';
import {Title} from '@angular/platform-browser';
import {ActivatedRoute, Router} from '@angular/router';
import {Subject, distinctUntilChanged, of, switchMap, tap} from 'rxjs';
import {finalize, map, take, takeUntil} from 'rxjs/operators';
Expand Down Expand Up @@ -66,6 +67,8 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
// only tracked to prevent the component from resetting
expandedFilterId = '';

catalogType = this.route.snapshot.data.catalogType;

catalogSpelling = this.activeFeatureSet.usesBritishCatalogue()
? 'Catalogue'
: 'Catalog';
Expand All @@ -78,7 +81,10 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
private globalStateUtils: GlobalStateUtils,
private deploymentEnvironmentUrlSyncService: DeploymentEnvironmentUrlSyncService,
private activeFeatureSet: ActiveFeatureSet,
) {}
private titleService: Title,
) {
this.setTitle();
}

ngOnInit(): void {
this.deploymentEnvironmentUrlSyncService.updateFromUrlOnce(
Expand All @@ -102,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 @@ -181,6 +186,7 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
.pipe(
finalize(() => {
this.changeUrlToCatalogRoot();
this.setTitle();
}),
)
.subscribe();
Expand Down Expand Up @@ -270,4 +276,10 @@ export class CatalogPageComponent implements OnInit, OnDestroy {
headerActions: [],
};
}

private setTitle() {
this.catalogType === 'my-data-offers'
? this.titleService.setTitle('My Data Offers')
: this.titleService.setTitle(this.catalogSpelling);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
import {Component, HostBinding, OnDestroy, OnInit} from '@angular/core';
import {MatDialog} from '@angular/material/dialog';
import {Title} from '@angular/platform-browser';
import {Router} from '@angular/router';
import {Subject} from 'rxjs';
import {filter, takeUntil} from 'rxjs/operators';
Expand Down Expand Up @@ -54,7 +55,10 @@ export class CentralComponentListPageComponent implements OnInit, OnDestroy {
private globalStateUtils: GlobalStateUtils,
private router: Router,
private dialog: MatDialog,
) {}
private titleService: Title,
) {
this.titleService.setTitle('Central Components');
}

ngOnInit() {
this.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {ActivatedRoute} from '@angular/router';
import {Subject, takeUntil} from 'rxjs';
import {Store} from '@ngxs/store';
Expand All @@ -32,7 +33,13 @@ export class ControlCenterOrganizationMemberDetailPageComponent
state: ControlCenterOrganizationMemberDetailPageState =
DEFAULT_CONTROL_CENTER_ORGANIZATION_MEMBER_DETAIL_PAGE_STATE;

constructor(private store: Store, private activatedRoute: ActivatedRoute) {}
constructor(
private store: Store,
private activatedRoute: ActivatedRoute,
private titleService: Title,
) {
this.titleService.setTitle('Member Details');
}

ngOnInit(): void {
this.startRefreshingOnRouteChanges();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {Router} from '@angular/router';
import {Subject, takeUntil} from 'rxjs';
import {Store} from '@ngxs/store';
Expand Down Expand Up @@ -39,7 +40,10 @@ export class ControlCenterOrganizationMembersPageComponent
private router: Router,
private breadcrumbService: BreadcrumbService,
private globalStateUtils: GlobalStateUtils,
) {}
private titleService: Title,
) {
this.titleService.setTitle('Users and Roles');
}

ngOnInit(): void {
this.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {Subject, takeUntil} from 'rxjs';
import {Store} from '@ngxs/store';
import {GlobalStateUtils} from 'src/app/core/global-state/global-state-utils';
Expand All @@ -34,7 +35,10 @@ export class ControlCenterOrganizationProfilePageComponent
constructor(
private store: Store,
private globalStateUtils: GlobalStateUtils,
) {}
private titleService: Title,
) {
this.titleService.setTitle('My Organization');
}

ngOnInit(): void {
this.refresh();
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 @@ -11,6 +11,7 @@
* sovity GmbH - initial implementation
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {Subject, takeUntil} from 'rxjs';
import {Store} from '@ngxs/store';
import {GlobalStateUtils} from 'src/app/core/global-state/global-state-utils';
Expand All @@ -34,7 +35,10 @@ export class ControlCenterUserProfilePageComponent
constructor(
private store: Store,
private globalStateUtils: GlobalStateUtils,
) {}
private titleService: Title,
) {
this.titleService.setTitle('My Profile');
}

ngOnInit(): void {
this.refresh();
Expand Down
Loading
Loading