From 843b2de3a8d7472e5f32d6a2e3508e2958654cb1 Mon Sep 17 00:00:00 2001 From: Masum ULU Date: Thu, 18 May 2023 16:50:39 +0300 Subject: [PATCH] Guards mapped & refactored --- .../account/src/lib/account-routing.module.ts | 19 +++--- .../lib/guards/authentication-flow.guard.ts | 9 ++- .../src/lib/guards/extensions.guard.ts | 28 ++++----- .../core/src/lib/abstracts/abstract-guard.ts | 9 +++ .../core/src/lib/abstracts/auth.guard.ts | 7 ++- .../packages/core/src/lib/abstracts/index.ts | 1 + .../core/src/lib/guards/permission.guard.ts | 28 +++++---- .../src/lib/guards/extensions.guard.ts | 57 ++++++++---------- .../src/lib/identity-routing.module.ts | 16 +++-- .../oauth/src/lib/guards/oauth.guard.ts | 19 +++--- .../lib/setting-management-routing.module.ts | 6 +- .../src/lib/guards/extensions.guard.ts | 59 ++++++++----------- .../lib/tenant-management-routing.module.ts | 8 ++- 13 files changed, 138 insertions(+), 128 deletions(-) create mode 100644 npm/ng-packs/packages/core/src/lib/abstracts/abstract-guard.ts diff --git a/npm/ng-packs/packages/account/src/lib/account-routing.module.ts b/npm/ng-packs/packages/account/src/lib/account-routing.module.ts index e4b18a717b..0b188f3751 100644 --- a/npm/ng-packs/packages/account/src/lib/account-routing.module.ts +++ b/npm/ng-packs/packages/account/src/lib/account-routing.module.ts @@ -1,20 +1,22 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes, mapToCanActivate } from '@angular/router'; + import { AuthGuard, ReplaceableComponents, ReplaceableRouteContainerComponent, RouterOutletComponent, } from '@abp/ng.core'; -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; + import { ForgotPasswordComponent } from './components/forgot-password/forgot-password.component'; import { LoginComponent } from './components/login/login.component'; import { ManageProfileComponent } from './components/manage-profile/manage-profile.component'; import { RegisterComponent } from './components/register/register.component'; import { ResetPasswordComponent } from './components/reset-password/reset-password.component'; import { eAccountComponents } from './enums/components'; -import { AuthenticationFlowGuard } from './guards/authentication-flow.guard'; -import { AccountExtensionsGuard } from './guards'; +import { AccountExtensionsGuard, AuthenticationFlowGuard } from './guards'; +const canActivate = mapToCanActivate([AuthenticationFlowGuard]); const routes: Routes = [ { path: '', pathMatch: 'full', redirectTo: 'login' }, @@ -25,7 +27,7 @@ const routes: Routes = [ { path: 'login', component: ReplaceableRouteContainerComponent, - canActivate: [AuthenticationFlowGuard], + canActivate, data: { replaceableComponent: { key: eAccountComponents.Login, @@ -36,7 +38,7 @@ const routes: Routes = [ { path: 'register', component: ReplaceableRouteContainerComponent, - canActivate: [AuthenticationFlowGuard], + canActivate, data: { replaceableComponent: { key: eAccountComponents.Register, @@ -47,7 +49,8 @@ const routes: Routes = [ { path: 'forgot-password', component: ReplaceableRouteContainerComponent, - canActivate: [AuthenticationFlowGuard], + canActivate, + data: { replaceableComponent: { key: eAccountComponents.ForgotPassword, @@ -70,7 +73,7 @@ const routes: Routes = [ { path: 'manage', component: ReplaceableRouteContainerComponent, - canActivate: [AuthGuard, AccountExtensionsGuard], + canActivate: mapToCanActivate([AuthGuard, AccountExtensionsGuard]), data: { replaceableComponent: { key: eAccountComponents.ManageProfile, diff --git a/npm/ng-packs/packages/account/src/lib/guards/authentication-flow.guard.ts b/npm/ng-packs/packages/account/src/lib/guards/authentication-flow.guard.ts index c669e32a97..c00cee3156 100644 --- a/npm/ng-packs/packages/account/src/lib/guards/authentication-flow.guard.ts +++ b/npm/ng-packs/packages/account/src/lib/guards/authentication-flow.guard.ts @@ -1,10 +1,9 @@ -import { AuthService } from '@abp/ng.core'; -import { Injectable } from '@angular/core'; - +import { AuthService, IAbpGuard } from '@abp/ng.core'; +import { Injectable, inject } from '@angular/core'; @Injectable() -export class AuthenticationFlowGuard { - constructor(private authService: AuthService) {} +export class AuthenticationFlowGuard implements IAbpGuard { + protected readonly authService = inject(AuthService); canActivate() { if (this.authService.isInternalAuth) return true; diff --git a/npm/ng-packs/packages/account/src/lib/guards/extensions.guard.ts b/npm/ng-packs/packages/account/src/lib/guards/extensions.guard.ts index be000782c2..8df8aede51 100644 --- a/npm/ng-packs/packages/account/src/lib/guards/extensions.guard.ts +++ b/npm/ng-packs/packages/account/src/lib/guards/extensions.guard.ts @@ -1,46 +1,46 @@ -import { Injectable, Injector } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; import { Observable } from 'rxjs'; +import { tap, map } from 'rxjs/operators'; + +import { ConfigStateService, IAbpGuard } from '@abp/ng.core'; import { ExtensionsService, getObjectExtensionEntitiesFromStore, mapEntitiesToContributors, mergeWithDefaultProps, } from '@abp/ng.theme.shared/extensions'; -import { ConfigStateService } from '@abp/ng.core'; -import { tap, map, mapTo } from 'rxjs/operators'; + import { ACCOUNT_EDIT_FORM_PROP_CONTRIBUTORS, DEFAULT_ACCOUNT_FORM_PROPS, } from '../tokens/extensions.token'; -import { AccountEditFormPropContributors } from '../models/config-options'; import { eAccountComponents } from '../enums/components'; @Injectable() -export class AccountExtensionsGuard { - constructor(private injector: Injector) {} +export class AccountExtensionsGuard implements IAbpGuard { + protected readonly configState = inject(ConfigStateService); + protected readonly extensions = inject(ExtensionsService); canActivate(): Observable { - const extensions: ExtensionsService = this.injector.get(ExtensionsService); + const config = { optional: true }; - const editFormContributors: AccountEditFormPropContributors = - this.injector.get(ACCOUNT_EDIT_FORM_PROP_CONTRIBUTORS, null) || {}; + const editFormContributors = inject(ACCOUNT_EDIT_FORM_PROP_CONTRIBUTORS, config) || {}; - const configState = this.injector.get(ConfigStateService); - return getObjectExtensionEntitiesFromStore(configState, 'Identity').pipe( + return getObjectExtensionEntitiesFromStore(this.configState, 'Identity').pipe( map(entities => ({ [eAccountComponents.PersonalSettings]: entities.User, })), - mapEntitiesToContributors(configState, 'AbpIdentity'), + mapEntitiesToContributors(this.configState, 'AbpIdentity'), tap(objectExtensionContributors => { mergeWithDefaultProps( - extensions.editFormProps, + this.extensions.editFormProps, DEFAULT_ACCOUNT_FORM_PROPS, objectExtensionContributors.editForm, editFormContributors, ); }), - mapTo(true), + map(() => true), ); } } diff --git a/npm/ng-packs/packages/core/src/lib/abstracts/abstract-guard.ts b/npm/ng-packs/packages/core/src/lib/abstracts/abstract-guard.ts new file mode 100644 index 0000000000..7593326903 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/abstracts/abstract-guard.ts @@ -0,0 +1,9 @@ +import { ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { Observable } from 'rxjs'; + +export interface IAbpGuard { + canActivate( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot, + ): Observable | Promise | boolean | UrlTree; +} diff --git a/npm/ng-packs/packages/core/src/lib/abstracts/auth.guard.ts b/npm/ng-packs/packages/core/src/lib/abstracts/auth.guard.ts index 8e380a46e3..8fb4f4dc25 100644 --- a/npm/ng-packs/packages/core/src/lib/abstracts/auth.guard.ts +++ b/npm/ng-packs/packages/core/src/lib/abstracts/auth.guard.ts @@ -1,13 +1,14 @@ +import { Injectable } from '@angular/core'; import { UrlTree } from '@angular/router'; import { Observable } from 'rxjs'; -import { Injectable } from '@angular/core'; +import { IAbpGuard } from './abstract-guard'; + @Injectable({ providedIn: 'root', }) -export class AuthGuard implements IAuthGuard { +export class AuthGuard implements IAbpGuard { canActivate(): Observable | boolean | UrlTree { console.error('You should add @abp/ng-oauth packages or create your own auth packages.'); return false; } } -export interface IAuthGuard {} diff --git a/npm/ng-packs/packages/core/src/lib/abstracts/index.ts b/npm/ng-packs/packages/core/src/lib/abstracts/index.ts index e1ff2f106b..f9b4794de0 100644 --- a/npm/ng-packs/packages/core/src/lib/abstracts/index.ts +++ b/npm/ng-packs/packages/core/src/lib/abstracts/index.ts @@ -1,3 +1,4 @@ +export * from './abstract-guard'; export * from './ng-model.component'; export * from './auth.guard'; export * from './auth.service'; diff --git a/npm/ng-packs/packages/core/src/lib/guards/permission.guard.ts b/npm/ng-packs/packages/core/src/lib/guards/permission.guard.ts index 01df2d4556..ae3fdb6e37 100644 --- a/npm/ng-packs/packages/core/src/lib/guards/permission.guard.ts +++ b/npm/ng-packs/packages/core/src/lib/guards/permission.guard.ts @@ -1,23 +1,25 @@ -import { HttpErrorResponse } from '@angular/common/http'; -import { Injectable } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router'; +import { HttpErrorResponse } from '@angular/common/http'; + import { Observable, of } from 'rxjs'; import { tap } from 'rxjs/operators'; -import { HttpErrorReporterService } from '../services/http-error-reporter.service'; -import { PermissionService } from '../services/permission.service'; -import { RoutesService } from '../services/routes.service'; + +import { OAuthService } from 'angular-oauth2-oidc'; + +import { IAbpGuard } from '../abstracts'; import { findRoute, getRoutePath } from '../utils/route-utils'; +import { RoutesService, PermissionService, HttpErrorReporterService } from '../services'; @Injectable({ providedIn: 'root', }) -export class PermissionGuard { - constructor( - private router: Router, - private routesService: RoutesService, - private permissionService: PermissionService, - private httpErrorReporter: HttpErrorReporterService, - ) {} +export class PermissionGuard implements IAbpGuard { + protected readonly router = inject(Router); + protected readonly routesService = inject(RoutesService); + protected readonly oAuthService = inject(OAuthService); + protected readonly permissionService = inject(PermissionService); + protected readonly httpErrorReporter = inject(HttpErrorReporterService); canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { let { requiredPolicy } = route.data || {}; @@ -31,7 +33,7 @@ export class PermissionGuard { return this.permissionService.getGrantedPolicy$(requiredPolicy).pipe( tap(access => { - if (!access) { + if (!access && this.oAuthService.hasValidAccessToken()) { this.httpErrorReporter.reportError({ status: 403 } as HttpErrorResponse); } }), diff --git a/npm/ng-packs/packages/identity/src/lib/guards/extensions.guard.ts b/npm/ng-packs/packages/identity/src/lib/guards/extensions.guard.ts index 5fc747c6fb..172b599f91 100644 --- a/npm/ng-packs/packages/identity/src/lib/guards/extensions.guard.ts +++ b/npm/ng-packs/packages/identity/src/lib/guards/extensions.guard.ts @@ -1,4 +1,9 @@ -import { ConfigStateService } from '@abp/ng.core'; +import { Injectable, inject } from '@angular/core'; + +import { Observable } from 'rxjs'; +import { map, tap } from 'rxjs/operators'; + +import { ConfigStateService, IAbpGuard } from '@abp/ng.core'; import { ExtensionsService, getObjectExtensionEntitiesFromStore, @@ -6,18 +11,8 @@ import { mergeWithDefaultActions, mergeWithDefaultProps, } from '@abp/ng.theme.shared/extensions'; -import { Injectable, Injector } from '@angular/core'; -import { Observable } from 'rxjs'; -import { map, mapTo, tap } from 'rxjs/operators'; import { eIdentityComponents } from '../enums/components'; -import { - IdentityCreateFormPropContributors, - IdentityEditFormPropContributors, - IdentityEntityActionContributors, - IdentityEntityPropContributors, - IdentityToolbarActionContributors, -} from '../models/config-options'; import { DEFAULT_IDENTITY_CREATE_FORM_PROPS, DEFAULT_IDENTITY_EDIT_FORM_PROPS, @@ -32,60 +27,56 @@ import { } from '../tokens/extensions.token'; @Injectable() -export class IdentityExtensionsGuard { - constructor(private injector: Injector) {} +export class IdentityExtensionsGuard implements IAbpGuard { + protected readonly configState = inject(ConfigStateService); + protected readonly extensions = inject(ExtensionsService); canActivate(): Observable { - const extensions: ExtensionsService = this.injector.get(ExtensionsService); - const actionContributors: IdentityEntityActionContributors = - this.injector.get(IDENTITY_ENTITY_ACTION_CONTRIBUTORS, null) || {}; - const toolbarContributors: IdentityToolbarActionContributors = - this.injector.get(IDENTITY_TOOLBAR_ACTION_CONTRIBUTORS, null) || {}; - const propContributors: IdentityEntityPropContributors = - this.injector.get(IDENTITY_ENTITY_PROP_CONTRIBUTORS, null) || {}; - const createFormContributors: IdentityCreateFormPropContributors = - this.injector.get(IDENTITY_CREATE_FORM_PROP_CONTRIBUTORS, null) || {}; - const editFormContributors: IdentityEditFormPropContributors = - this.injector.get(IDENTITY_EDIT_FORM_PROP_CONTRIBUTORS, null) || {}; + const config = { optional: true }; + + const actionContributors = inject(IDENTITY_ENTITY_ACTION_CONTRIBUTORS, config) || {}; + const toolbarContributors = inject(IDENTITY_TOOLBAR_ACTION_CONTRIBUTORS, config) || {}; + const propContributors = inject(IDENTITY_ENTITY_PROP_CONTRIBUTORS, config) || {}; + const createFormContributors = inject(IDENTITY_CREATE_FORM_PROP_CONTRIBUTORS, config) || {}; + const editFormContributors = inject(IDENTITY_EDIT_FORM_PROP_CONTRIBUTORS, config) || {}; - const configState = this.injector.get(ConfigStateService); - return getObjectExtensionEntitiesFromStore(configState, 'Identity').pipe( + return getObjectExtensionEntitiesFromStore(this.configState, 'Identity').pipe( map(entities => ({ [eIdentityComponents.Roles]: entities.Role, [eIdentityComponents.Users]: entities.User, })), - mapEntitiesToContributors(configState, 'AbpIdentity'), + mapEntitiesToContributors(this.configState, 'AbpIdentity'), tap(objectExtensionContributors => { mergeWithDefaultActions( - extensions.entityActions, + this.extensions.entityActions, DEFAULT_IDENTITY_ENTITY_ACTIONS, actionContributors, ); mergeWithDefaultActions( - extensions.toolbarActions, + this.extensions.toolbarActions, DEFAULT_IDENTITY_TOOLBAR_ACTIONS, toolbarContributors, ); mergeWithDefaultProps( - extensions.entityProps, + this.extensions.entityProps, DEFAULT_IDENTITY_ENTITY_PROPS, objectExtensionContributors.prop, propContributors, ); mergeWithDefaultProps( - extensions.createFormProps, + this.extensions.createFormProps, DEFAULT_IDENTITY_CREATE_FORM_PROPS, objectExtensionContributors.createForm, createFormContributors, ); mergeWithDefaultProps( - extensions.editFormProps, + this.extensions.editFormProps, DEFAULT_IDENTITY_EDIT_FORM_PROPS, objectExtensionContributors.editForm, editFormContributors, ); }), - mapTo(true), + map(() => true), ); } } diff --git a/npm/ng-packs/packages/identity/src/lib/identity-routing.module.ts b/npm/ng-packs/packages/identity/src/lib/identity-routing.module.ts index 790d5fe688..33c8f53d5a 100644 --- a/npm/ng-packs/packages/identity/src/lib/identity-routing.module.ts +++ b/npm/ng-packs/packages/identity/src/lib/identity-routing.module.ts @@ -1,21 +1,25 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes, mapToCanActivate } from '@angular/router'; + import { - AuthGuard, PermissionGuard, + AuthGuard, + PermissionGuard, ReplaceableComponents, - ReplaceableRouteContainerComponent, RouterOutletComponent + ReplaceableRouteContainerComponent, + RouterOutletComponent, } from '@abp/ng.core'; -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; + import { RolesComponent } from './components/roles/roles.component'; import { UsersComponent } from './components/users/users.component'; import { eIdentityComponents } from './enums/components'; -import { IdentityExtensionsGuard } from './guards/extensions.guard'; +import { IdentityExtensionsGuard } from './guards'; const routes: Routes = [ { path: '', redirectTo: 'roles', pathMatch: 'full' }, { path: '', component: RouterOutletComponent, - canActivate: [AuthGuard, PermissionGuard, IdentityExtensionsGuard], + canActivate: mapToCanActivate([AuthGuard, PermissionGuard, IdentityExtensionsGuard]), children: [ { path: 'roles', diff --git a/npm/ng-packs/packages/oauth/src/lib/guards/oauth.guard.ts b/npm/ng-packs/packages/oauth/src/lib/guards/oauth.guard.ts index 80fb17ebdd..84e4a76f49 100644 --- a/npm/ng-packs/packages/oauth/src/lib/guards/oauth.guard.ts +++ b/npm/ng-packs/packages/oauth/src/lib/guards/oauth.guard.ts @@ -1,22 +1,27 @@ -import { Injectable } from '@angular/core'; +import { Injectable, inject } from '@angular/core'; import { UrlTree } from '@angular/router'; -import { OAuthService } from 'angular-oauth2-oidc'; +import { HttpErrorResponse } from '@angular/common/http'; + import { Observable } from 'rxjs'; -import { AuthService, IAuthGuard } from '@abp/ng.core'; +import { OAuthService } from 'angular-oauth2-oidc'; + +import { AuthService, HttpErrorReporterService, IAbpGuard } from '@abp/ng.core'; @Injectable({ providedIn: 'root', }) -export class AbpOAuthGuard implements IAuthGuard { - constructor(private oauthService: OAuthService, private authService: AuthService) {} +export class AbpOAuthGuard implements IAbpGuard { + protected readonly oAuthService = inject(OAuthService); + protected readonly authService = inject(AuthService); + protected readonly httpErrorReporter = inject(HttpErrorReporterService); canActivate(): Observable | boolean | UrlTree { - const hasValidAccessToken = this.oauthService.hasValidAccessToken(); + const hasValidAccessToken = this.oAuthService.hasValidAccessToken(); if (hasValidAccessToken) { return true; } - this.authService.navigateToLogin(); + this.httpErrorReporter.reportError({ status: 401 } as HttpErrorResponse); return false; } } diff --git a/npm/ng-packs/packages/setting-management/src/lib/setting-management-routing.module.ts b/npm/ng-packs/packages/setting-management/src/lib/setting-management-routing.module.ts index ea16e33286..1fc5fd7c7b 100644 --- a/npm/ng-packs/packages/setting-management/src/lib/setting-management-routing.module.ts +++ b/npm/ng-packs/packages/setting-management/src/lib/setting-management-routing.module.ts @@ -1,11 +1,11 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes, mapToCanActivate } from '@angular/router'; import { AuthGuard, ReplaceableComponents, ReplaceableRouteContainerComponent, RouterOutletComponent, } from '@abp/ng.core'; -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; import { SettingManagementComponent } from './components/setting-management.component'; import { eSettingManagementComponents } from './enums/components'; @@ -13,7 +13,7 @@ const routes: Routes = [ { path: '', component: RouterOutletComponent, - canActivate: [AuthGuard], + canActivate: mapToCanActivate([AuthGuard]), children: [ { path: '', diff --git a/npm/ng-packs/packages/tenant-management/src/lib/guards/extensions.guard.ts b/npm/ng-packs/packages/tenant-management/src/lib/guards/extensions.guard.ts index cbe63210da..bdadb7e78a 100644 --- a/npm/ng-packs/packages/tenant-management/src/lib/guards/extensions.guard.ts +++ b/npm/ng-packs/packages/tenant-management/src/lib/guards/extensions.guard.ts @@ -1,4 +1,9 @@ -import { ConfigStateService } from '@abp/ng.core'; +import { Injectable, inject } from '@angular/core'; + +import { Observable } from 'rxjs'; +import { map, tap } from 'rxjs/operators'; + +import { ConfigStateService, IAbpGuard } from '@abp/ng.core'; import { ExtensionsService, getObjectExtensionEntitiesFromStore, @@ -6,18 +11,8 @@ import { mergeWithDefaultActions, mergeWithDefaultProps, } from '@abp/ng.theme.shared/extensions'; -import { Injectable, Injector } from '@angular/core'; -import { Observable } from 'rxjs'; -import { map, mapTo, tap } from 'rxjs/operators'; import { eTenantManagementComponents } from '../enums/components'; -import { - TenantManagementCreateFormPropContributors, - TenantManagementEditFormPropContributors, - TenantManagementEntityActionContributors, - TenantManagementEntityPropContributors, - TenantManagementToolbarActionContributors, -} from '../models/config-options'; import { DEFAULT_TENANT_MANAGEMENT_CREATE_FORM_PROPS, DEFAULT_TENANT_MANAGEMENT_EDIT_FORM_PROPS, @@ -32,59 +27,57 @@ import { } from '../tokens/extensions.token'; @Injectable() -export class TenantManagementExtensionsGuard { - constructor(private injector: Injector) {} +export class TenantManagementExtensionsGuard implements IAbpGuard { + protected readonly configState = inject(ConfigStateService); + protected readonly extensions = inject(ExtensionsService); canActivate(): Observable { - const extensions: ExtensionsService = this.injector.get(ExtensionsService); - const actionContributors: TenantManagementEntityActionContributors = - this.injector.get(TENANT_MANAGEMENT_ENTITY_ACTION_CONTRIBUTORS, null) || {}; - const toolbarContributors: TenantManagementToolbarActionContributors = - this.injector.get(TENANT_MANAGEMENT_TOOLBAR_ACTION_CONTRIBUTORS, null) || {}; - const propContributors: TenantManagementEntityPropContributors = - this.injector.get(TENANT_MANAGEMENT_ENTITY_PROP_CONTRIBUTORS, null) || {}; - const createFormContributors: TenantManagementCreateFormPropContributors = - this.injector.get(TENANT_MANAGEMENT_CREATE_FORM_PROP_CONTRIBUTORS, null) || {}; - const editFormContributors: TenantManagementEditFormPropContributors = - this.injector.get(TENANT_MANAGEMENT_EDIT_FORM_PROP_CONTRIBUTORS, null) || {}; + const config = { optional: true }; + + const actionContributors = inject(TENANT_MANAGEMENT_ENTITY_ACTION_CONTRIBUTORS, config) || {}; + const toolbarContributors = inject(TENANT_MANAGEMENT_TOOLBAR_ACTION_CONTRIBUTORS, config) || {}; + const propContributors = inject(TENANT_MANAGEMENT_ENTITY_PROP_CONTRIBUTORS, config) || {}; + const createFormContributors = + inject(TENANT_MANAGEMENT_CREATE_FORM_PROP_CONTRIBUTORS, config) || {}; + const editFormContributors = + inject(TENANT_MANAGEMENT_EDIT_FORM_PROP_CONTRIBUTORS, config) || {}; - const configState = this.injector.get(ConfigStateService); - return getObjectExtensionEntitiesFromStore(configState, 'TenantManagement').pipe( + return getObjectExtensionEntitiesFromStore(this.configState, 'TenantManagement').pipe( map(entities => ({ [eTenantManagementComponents.Tenants]: entities.Tenant, })), - mapEntitiesToContributors(configState, 'TenantManagement'), + mapEntitiesToContributors(this.configState, 'TenantManagement'), tap(objectExtensionContributors => { mergeWithDefaultActions( - extensions.entityActions, + this.extensions.entityActions, DEFAULT_TENANT_MANAGEMENT_ENTITY_ACTIONS, actionContributors, ); mergeWithDefaultActions( - extensions.toolbarActions, + this.extensions.toolbarActions, DEFAULT_TENANT_MANAGEMENT_TOOLBAR_ACTIONS, toolbarContributors, ); mergeWithDefaultProps( - extensions.entityProps, + this.extensions.entityProps, DEFAULT_TENANT_MANAGEMENT_ENTITY_PROPS, objectExtensionContributors.prop, propContributors, ); mergeWithDefaultProps( - extensions.createFormProps, + this.extensions.createFormProps, DEFAULT_TENANT_MANAGEMENT_CREATE_FORM_PROPS, objectExtensionContributors.createForm, createFormContributors, ); mergeWithDefaultProps( - extensions.editFormProps, + this.extensions.editFormProps, DEFAULT_TENANT_MANAGEMENT_EDIT_FORM_PROPS, objectExtensionContributors.editForm, editFormContributors, ); }), - mapTo(true), + map(() => true), ); } } diff --git a/npm/ng-packs/packages/tenant-management/src/lib/tenant-management-routing.module.ts b/npm/ng-packs/packages/tenant-management/src/lib/tenant-management-routing.module.ts index f2b7180c1e..06e2f0369e 100644 --- a/npm/ng-packs/packages/tenant-management/src/lib/tenant-management-routing.module.ts +++ b/npm/ng-packs/packages/tenant-management/src/lib/tenant-management-routing.module.ts @@ -1,3 +1,6 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes, mapToCanActivate } from '@angular/router'; + import { AuthGuard, PermissionGuard, @@ -5,8 +8,7 @@ import { ReplaceableRouteContainerComponent, RouterOutletComponent, } from '@abp/ng.core'; -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; + import { TenantsComponent } from './components/tenants/tenants.component'; import { eTenantManagementComponents } from './enums/components'; import { TenantManagementExtensionsGuard } from './guards'; @@ -16,7 +18,7 @@ const routes: Routes = [ { path: '', component: RouterOutletComponent, - canActivate: [AuthGuard, PermissionGuard, TenantManagementExtensionsGuard], + canActivate: mapToCanActivate([AuthGuard, PermissionGuard, TenantManagementExtensionsGuard]), children: [ { path: 'tenants',