| 1 | /* |
| 2 | * Copyright (c) 2024 sovity GmbH |
| 3 | * |
| 4 | * This program and the accompanying materials are made available under the |
| 5 | * terms of the Apache License, Version 2.0 which is available at |
| 6 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | * |
| 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Contributors: |
| 11 | * sovity GmbH - initial implementation |
| 12 | */ |
| 13 | import {InjectionToken, NgModule, Type} from '@angular/core'; |
| 14 | import {ActivatedRouteSnapshot, RouterModule, Routes} from '@angular/router'; |
| 15 | import {UserRoleDto} from '@sovity.de/authority-portal-client'; |
| 16 | import {requiresRole} from './core/services/auth/requires-role-guard'; |
| 17 | import {AuthorityConnectorListPageComponent} from './pages/authority-connector-list-page/authority-connector-list-page/authority-connector-list-page.component'; |
| 18 | import {AuthorityOrganizationEditPageComponent} from './pages/authority-organization-edit-page/authority-organization-edit-page/authority-organization-edit-page.component'; |
| 19 | import {AuthorityOrganizationListPageComponent} from './pages/authority-organization-list-page/authority-organization-list-page/authority-organization-list-page.component'; |
| 20 | import {CatalogPageComponent} from './pages/catalog-page/catalog-page/catalog-page.component'; |
| 21 | import {CentralComponentListPageComponent} from './pages/central-component-list-page/central-component-list-page/central-component-list-page.component'; |
| 22 | import {ChooseParticipantCaasComponent} from './pages/choose-participant-caas/choose-participant-caas/choose-participant-caas.component'; |
| 23 | import {ChooseParticipantConnectorComponent} from './pages/choose-participant-connector/choose-participant-connector/choose-participant-connector.component'; |
| 24 | import {ConfigureProvidedConnectorPageComponent} from './pages/component-registration-pages/provide-connector-page/provide-connector-page/configure-provided-connector-page.component'; |
| 25 | import {RegisterCentralComponentPageComponent} from './pages/component-registration-pages/register-central-component-page/register-central-component-page/register-central-component-page.component'; |
| 26 | import {RegisterConnectorPageComponent} from './pages/component-registration-pages/register-connector-page/register-connector-page/register-connector-page.component'; |
| 27 | import {RequestConnectorPageComponent} from './pages/component-registration-pages/request-connector-page/request-connector-page/request-connector-page.component'; |
| 28 | import {ReserveProvidedConnectorPageComponent} from './pages/component-registration-pages/reserve-provided-connector-page/reserve-provided-connector-page/reserve-provided-connector-page.component'; |
| 29 | import {ControlCenterPageComponent} from './pages/control-center-page/control-center-page/control-center-page.component'; |
| 30 | import {CONTROL_CENTER_ROUTES} from './pages/control-center-page/control-center-routes'; |
| 31 | import {DashboardPageComponent} from './pages/dashboard-page/dashboard-page/dashboard-page.component'; |
| 32 | import {LoadingPageComponent} from './pages/empty-pages/loading-page/loading-page/loading-page.component'; |
| 33 | import {PageNotFoundPageComponent} from './pages/empty-pages/page-not-found-page/page-not-found-page/page-not-found-page.component'; |
| 34 | import {UnauthenticatedPageComponent} from './pages/empty-pages/unauthenticated-page/unauthenticated-page/unauthenticated-page.component'; |
| 35 | import {ParticipantOwnConnectorDetailPageComponent} from './pages/participant-own-connector-detail-page/participant-own-connector-detail-page/participant-own-connector-detail-page.component'; |
| 36 | import {ParticipantOwnConnectorListPageComponent} from './pages/participant-own-connector-list-page/participant-own-connector-list-page/participant-own-connector-list-page.component'; |
| 37 | import {OrganizationCreatePageComponent} from './pages/registration-pages/organization-create-page/organization-create-page/organization-create-page.component'; |
| 38 | import {OrganizationOnboardPageComponent} from './pages/registration-pages/organization-onboard-page/organization-onboard-page/organization-onboard-page.component'; |
| 39 | import {OrganizationPendingPageComponent} from './pages/registration-pages/organization-pending-page/organization-pending-page/organization-pending-page.component'; |
| 40 | import {OrganizationRejectedPageComponent} from './pages/registration-pages/organization-rejected-page/organization-rejected-page/organization-rejected-page.component'; |
| 41 | import {SpConnectorListPageComponent} from './pages/sp-connector-list-page/sp-connector-list-page/sp-connector-list-page.component'; |
| 42 | import {PortalLayoutComponent} from './shared/common/portal-layout/portal-layout/portal-layout.component'; |
| 43 | |
| 44 | const EXTERNAL_URL_PROVIDER = new InjectionToken('externalRedirectProvider'); |
| 45 | |
| 46 | export const UNAUTHENTICATED_ROUTES: Routes = [ |
| 47 | { |
| 48 | path: 'create-organization', |
| 49 | component: OrganizationCreatePageComponent, |
| 50 | }, |
| 51 | { |
| 52 | path: '**', |
| 53 | component: UnauthenticatedPageComponent, |
| 54 | }, |
| 55 | ]; |
| 56 | |
| 57 | export const PENDING_ROUTES: Routes = singleComponent( |
| 58 | 'registration/pending', |
| 59 | OrganizationPendingPageComponent, |
| 60 | ); |
| 61 | |
| 62 | export const REJECTED_ROUTES: Routes = singleComponent( |
| 63 | 'registration/rejected', |
| 64 | OrganizationRejectedPageComponent, |
| 65 | ); |
| 66 | |
| 67 | export const ONBOARDING_ROUTES: Routes = singleComponent( |
| 68 | 'onboard', |
| 69 | OrganizationOnboardPageComponent, |
| 70 | ); |
| 71 | |
| 72 | export const LOADING_ROUTES: Routes = [ |
| 73 | { |
| 74 | path: '**', |
| 75 | component: LoadingPageComponent, |
| 76 | }, |
| 77 | ]; |
| 78 | |
| 79 | const REDIRECT_TO_HOME: string[] = [ |
| 80 | '', |
| 81 | 'registration/pending', |
| 82 | 'registration/rejected', |
| 83 | 'onboard', |
| 84 | ]; |
| 85 | |
| 86 | const getProperRedirectUrl = (fallbackUrl: string) => { |
| 87 | const url = localStorage.getItem('originalUrl') || fallbackUrl; |
| 88 | return url; |
| 89 | }; |
| 90 | |
| 91 | export const CATALOG_REDIRECTS: Routes = REDIRECT_TO_HOME.map((path) => ({ |
| 92 | path, |
| 93 | redirectTo: (() => getProperRedirectUrl('catalog'))(), |
| 94 | pathMatch: 'full', |
| 95 | })); |
| 96 | |
| 97 | export const FEATURE_DASHBOARD_ROUTE: Routes = [ |
| 98 | { |
| 99 | path: 'dashboard', |
| 100 | component: DashboardPageComponent, |
| 101 | data: { |
| 102 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 103 | }, |
| 104 | canActivate: [requiresRole], |
| 105 | }, |
| 106 | ]; |
| 107 | |
| 108 | export const AUTHORITY_PORTAL_ROUTES: Routes = [ |
| 109 | // participant own connector registration |
| 110 | { |
| 111 | path: 'my-organization/connectors/new', |
| 112 | component: ChooseParticipantConnectorComponent, |
| 113 | data: { |
| 114 | requiresRole: ['KEY_USER'] satisfies UserRoleDto[], |
| 115 | }, |
| 116 | canActivate: [requiresRole], |
| 117 | }, |
| 118 | { |
| 119 | path: 'my-organization/connectors/new/choose-provider', |
| 120 | component: ChooseParticipantCaasComponent, |
| 121 | data: { |
| 122 | requiresRole: ['KEY_USER'] satisfies UserRoleDto[], |
| 123 | }, |
| 124 | canActivate: [requiresRole], |
| 125 | }, |
| 126 | { |
| 127 | path: 'my-organization/connectors/new/provided', |
| 128 | component: RequestConnectorPageComponent, |
| 129 | data: { |
| 130 | requiresRole: ['KEY_USER'] satisfies UserRoleDto[], |
| 131 | }, |
| 132 | canActivate: [requiresRole], |
| 133 | }, |
| 134 | { |
| 135 | path: 'my-organization/connectors/new/self-hosted', |
| 136 | component: RegisterConnectorPageComponent, |
| 137 | data: { |
| 138 | requiresRole: ['KEY_USER'] satisfies UserRoleDto[], |
| 139 | }, |
| 140 | canActivate: [requiresRole], |
| 141 | }, |
| 142 | |
| 143 | { |
| 144 | path: '', |
| 145 | component: PortalLayoutComponent, |
| 146 | children: [ |
| 147 | { |
| 148 | path: 'catalog', |
| 149 | component: CatalogPageComponent, |
| 150 | data: { |
| 151 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 152 | }, |
| 153 | canActivate: [requiresRole], |
| 154 | children: [ |
| 155 | { |
| 156 | path: ':connectorId/:assetId', |
| 157 | component: CatalogPageComponent, |
| 158 | data: { |
| 159 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 160 | }, |
| 161 | canActivate: [requiresRole], |
| 162 | }, |
| 163 | ], |
| 164 | }, |
| 165 | { |
| 166 | path: 'my-organization/data-offers', |
| 167 | component: CatalogPageComponent, |
| 168 | data: { |
| 169 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 170 | catalogType: 'my-data-offers', |
| 171 | }, |
| 172 | canActivate: [requiresRole], |
| 173 | children: [ |
| 174 | { |
| 175 | path: ':connectorId/:assetId', |
| 176 | component: CatalogPageComponent, |
| 177 | data: { |
| 178 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 179 | }, |
| 180 | canActivate: [requiresRole], |
| 181 | }, |
| 182 | ], |
| 183 | }, |
| 184 | { |
| 185 | path: 'control-center', |
| 186 | component: ControlCenterPageComponent, |
| 187 | data: { |
| 188 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 189 | }, |
| 190 | canActivate: [requiresRole], |
| 191 | children: CONTROL_CENTER_ROUTES, |
| 192 | }, |
| 193 | { |
| 194 | path: 'users-and-roles', |
| 195 | redirectTo: 'control-center/users-and-roles', |
| 196 | pathMatch: 'full', |
| 197 | }, |
| 198 | // My Organization Section |
| 199 | { |
| 200 | path: 'my-organization/connectors', |
| 201 | component: ParticipantOwnConnectorListPageComponent, |
| 202 | data: { |
| 203 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 204 | }, |
| 205 | canActivate: [requiresRole], |
| 206 | }, |
| 207 | { |
| 208 | path: 'my-organization/connectors/:connectorId', |
| 209 | component: ParticipantOwnConnectorDetailPageComponent, |
| 210 | data: { |
| 211 | requiresRole: ['USER'] satisfies UserRoleDto[], |
| 212 | }, |
| 213 | canActivate: [requiresRole], |
| 214 | }, |
| 215 | |
| 216 | // Operator Admin Section |
| 217 | { |
| 218 | path: 'operator/central-components', |
| 219 | component: CentralComponentListPageComponent, |
| 220 | data: { |
| 221 | requiresRole: ['OPERATOR_ADMIN'] satisfies UserRoleDto[], |
| 222 | }, |
| 223 | canActivate: [requiresRole], |
| 224 | }, |
| 225 | { |
| 226 | path: 'operator/central-components/provide', |
| 227 | component: RegisterCentralComponentPageComponent, |
| 228 | data: { |
| 229 | requiresRole: ['OPERATOR_ADMIN'] satisfies UserRoleDto[], |
| 230 | }, |
| 231 | canActivate: [requiresRole], |
| 232 | }, |
| 233 | |
| 234 | // Service Partner Section |
| 235 | { |
| 236 | path: 'service-partner/provided-connectors', |
| 237 | component: SpConnectorListPageComponent, |
| 238 | data: { |
| 239 | requiresRole: ['SERVICE_PARTNER_ADMIN'] satisfies UserRoleDto[], |
| 240 | }, |
| 241 | canActivate: [requiresRole], |
| 242 | }, |
| 243 | { |
| 244 | path: 'service-partner/provided-connectors/:connectorId/configure-connector', |
| 245 | component: ConfigureProvidedConnectorPageComponent, |
| 246 | data: { |
| 247 | requiresRole: ['SERVICE_PARTNER_ADMIN'] satisfies UserRoleDto[], |
| 248 | }, |
| 249 | canActivate: [requiresRole], |
| 250 | }, |
| 251 | { |
| 252 | path: 'service-partner/provided-connectors/provide-connector', |
| 253 | component: ReserveProvidedConnectorPageComponent, |
| 254 | data: { |
| 255 | requiresRole: ['SERVICE_PARTNER_ADMIN'] satisfies UserRoleDto[], |
| 256 | }, |
| 257 | canActivate: [requiresRole], |
| 258 | }, |
| 259 | |
| 260 | // Participant Section |
| 261 | |
| 262 | // Authority Section |
| 263 | { |
| 264 | path: 'authority/organizations', |
| 265 | component: AuthorityOrganizationListPageComponent, |
| 266 | data: { |
| 267 | requiresRole: ['AUTHORITY_USER'] satisfies UserRoleDto[], |
| 268 | }, |
| 269 | canActivate: [requiresRole], |
| 270 | }, |
| 271 | { |
| 272 | path: 'authority/organizations/:organizationId', |
| 273 | component: AuthorityOrganizationListPageComponent, |
| 274 | data: { |
| 275 | requiresRole: ['AUTHORITY_USER'] satisfies UserRoleDto[], |
| 276 | }, |
| 277 | canActivate: [requiresRole], |
| 278 | }, |
| 279 | { |
| 280 | path: 'authority/organizations/:organizationId/edit', |
| 281 | component: AuthorityOrganizationEditPageComponent, |
| 282 | data: { |
| 283 | requiresRole: ['AUTHORITY_ADMIN'] satisfies UserRoleDto[], |
| 284 | }, |
| 285 | canActivate: [requiresRole], |
| 286 | }, |
| 287 | { |
| 288 | path: 'authority/connectors', |
| 289 | component: AuthorityConnectorListPageComponent, |
| 290 | data: { |
| 291 | requiresRole: ['AUTHORITY_USER'] satisfies UserRoleDto[], |
| 292 | }, |
| 293 | canActivate: [requiresRole], |
| 294 | }, |
| 295 | { |
| 296 | path: 'operator/connectors', |
| 297 | component: AuthorityConnectorListPageComponent, |
| 298 | data: { |
| 299 | requiresRole: ['OPERATOR_ADMIN'] satisfies UserRoleDto[], |
| 300 | }, |
| 301 | canActivate: [requiresRole], |
| 302 | }, |
| 303 | ], |
| 304 | }, |
| 305 | { |
| 306 | path: 'externalRedirect', |
| 307 | canActivate: [EXTERNAL_URL_PROVIDER], |
| 308 | component: PageNotFoundPageComponent, |
| 309 | }, |
| 310 | { |
| 311 | path: '**', |
| 312 | component: PageNotFoundPageComponent, |
| 313 | }, |
| 314 | ]; |
| 315 | |
| 316 | function singleComponent(path: string, component: Type<any>): Routes { |
| 317 | return [ |
| 318 | { |
| 319 | path, |
| 320 | component, |
| 321 | }, |
| 322 | { |
| 323 | path: '**', |
| 324 | redirectTo: path, |
| 325 | pathMatch: 'full', |
| 326 | }, |
| 327 | ]; |
| 328 | } |
| 329 | |
| 330 | @NgModule({ |
| 331 | imports: [RouterModule.forRoot(LOADING_ROUTES)], |
| 332 | exports: [RouterModule], |
| 333 | providers: [ |
| 334 | { |
| 335 | provide: EXTERNAL_URL_PROVIDER, |
| 336 | useValue: (route: ActivatedRouteSnapshot) => { |
| 337 | const externalUrl = route.paramMap.get('externalUrl'); |
| 338 | window.open(externalUrl!!, '_self'); |
| 339 | }, |
| 340 | }, |
| 341 | ], |
| 342 | }) |
| 343 | export class AppRoutingModule {} |