From 7d27960b5b9e31b85ba0b1140651222cca165942 Mon Sep 17 00:00:00 2001 From: Stefan Hauke Date: Tue, 2 Feb 2021 15:28:05 +0100 Subject: [PATCH] fix: add feature toggle route guard for 'punchout' routes (#527) - separate PunchoutRoutingModule and PunchoutAccountRoutingModule (rule of one) --- .../pages/punchout-account-routing.module.ts | 30 ++++++++++++++ .../punchout/pages/punchout-routing.module.ts | 39 ++++--------------- src/app/pages/account/account-page.module.ts | 14 +++++-- 3 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 src/app/extensions/punchout/pages/punchout-account-routing.module.ts diff --git a/src/app/extensions/punchout/pages/punchout-account-routing.module.ts b/src/app/extensions/punchout/pages/punchout-account-routing.module.ts new file mode 100644 index 0000000000..7fde25ccbb --- /dev/null +++ b/src/app/extensions/punchout/pages/punchout-account-routing.module.ts @@ -0,0 +1,30 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; + +const routes: Routes = [ + { + path: '', + loadChildren: () => + import('./account-punchout/account-punchout-page.module').then(m => m.AccountPunchoutPageModule), + }, + { + path: 'create', + loadChildren: () => + import('./account-punchout-create/account-punchout-create-page.module').then( + m => m.AccountPunchoutCreatePageModule + ), + }, + { + path: ':PunchoutLogin', + loadChildren: () => + import('./account-punchout-details/account-punchout-details-page.module').then( + m => m.AccountPunchoutDetailsPageModule + ), + }, +]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule], +}) +export class PunchoutAccountRoutingModule {} diff --git a/src/app/extensions/punchout/pages/punchout-routing.module.ts b/src/app/extensions/punchout/pages/punchout-routing.module.ts index b9b4d92519..88644188cf 100644 --- a/src/app/extensions/punchout/pages/punchout-routing.module.ts +++ b/src/app/extensions/punchout/pages/punchout-routing.module.ts @@ -1,42 +1,19 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; -const routes: Routes = [ - { path: 'punchout', loadChildren: () => import('./punchout/punchout-page.module').then(m => m.PunchoutPageModule) }, -]; - -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule], -}) -export class PunchoutRoutingModule {} +import { FeatureToggleGuard } from 'ish-core/feature-toggle.module'; -// tslint:disable-next-line: project-structure -const accountRoutes: Routes = [ - { - path: '', - loadChildren: () => - import('./account-punchout/account-punchout-page.module').then(m => m.AccountPunchoutPageModule), - }, - { - path: 'create', - loadChildren: () => - import('./account-punchout-create/account-punchout-create-page.module').then( - m => m.AccountPunchoutCreatePageModule - ), - }, +const routes: Routes = [ { - path: ':PunchoutLogin', - loadChildren: () => - import('./account-punchout-details/account-punchout-details-page.module').then( - m => m.AccountPunchoutDetailsPageModule - ), + path: 'punchout', + canActivate: [FeatureToggleGuard], + data: { feature: 'punchout' }, + loadChildren: () => import('./punchout/punchout-page.module').then(m => m.PunchoutPageModule), }, ]; @NgModule({ - imports: [RouterModule.forChild(accountRoutes)], + imports: [RouterModule.forChild(routes)], exports: [RouterModule], }) -// tslint:disable-next-line: project-structure -export class AccountPunchoutRoutingModule {} +export class PunchoutRoutingModule {} diff --git a/src/app/pages/account/account-page.module.ts b/src/app/pages/account/account-page.module.ts index 0ee552d563..aa635e2115 100644 --- a/src/app/pages/account/account-page.module.ts +++ b/src/app/pages/account/account-page.module.ts @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { AuthorizationToggleGuard } from 'ish-core/authorization-toggle.module'; +import { FeatureToggleGuard } from 'ish-core/feature-toggle.module'; import { SharedModule } from 'ish-shared/shared.module'; import { AccountOverviewPageModule } from '../account-overview/account-overview-page.module'; @@ -84,10 +85,17 @@ const accountPageRoutes: Routes = [ }, { path: 'punchout', - data: { breadcrumbData: [{ key: 'account.punchout.link' }], permission: 'APP_B2B_MANAGE_PUNCHOUT' }, - canActivate: [AuthorizationToggleGuard], + canActivate: [FeatureToggleGuard, AuthorizationToggleGuard], + data: { + feature: 'punchout', + permission: 'APP_B2B_MANAGE_PUNCHOUT', + breadcrumbData: [{ key: 'account.punchout.link' }], + }, loadChildren: () => - import('../../extensions/punchout/pages/punchout-routing.module').then(m => m.AccountPunchoutRoutingModule), + import('../../extensions/punchout/pages/punchout-account-routing.module').then( + m => m.PunchoutAccountRoutingModule + ), + }, ], },