From 4d21e5a6e936caf7e178d1f6af5a47c3b7a0aa53 Mon Sep 17 00:00:00 2001 From: Richard Cox Date: Thu, 4 Jun 2020 14:05:47 +0100 Subject: [PATCH] Change following review #2 - Fix cf package module file name - Make CUSTOM_USER_PERMISSION_CHECKERS optional - Remove need to inject CUSTOM_USER_PERMISSION_CHECKERS in multiple cf modules --- ...undry.module.ts => cloud-foundry-package.module.ts} | 2 ++ .../src/features/applications/applications.module.ts | 2 -- .../src/features/cloud-foundry/cloud-foundry.module.ts | 2 -- .../features/service-catalog/service-catalog.module.ts | 4 ---- .../src/features/services/services.module.ts | 4 ---- .../cloud-foundry/src/shared/cf-shared.module.ts | 4 +--- .../src/store/cloud-foundry.store.module.ts | 4 ---- src/frontend/packages/core/src/app.module.ts | 10 ++++++---- src/frontend/packages/core/src/core/core.module.ts | 9 --------- .../permissions/current-user-permissions.service.ts | 8 +++++--- .../endpoints-page/endpoints-page.component.spec.ts | 3 ++- .../edit-profile-info.component.spec.ts | 3 ++- .../endpoint/endpoints-list-config.service.spec.ts | 3 ++- .../src/shared/components/list/list.component.spec.ts | 4 +++- .../core/src/shared/user-permission.directive.spec.ts | 5 ++--- .../packages/core/test-framework/core-test.helper.ts | 6 +++++- 16 files changed, 30 insertions(+), 43 deletions(-) rename src/frontend/packages/cloud-foundry/src/{cloud-foundry.module.ts => cloud-foundry-package.module.ts} (93%) diff --git a/src/frontend/packages/cloud-foundry/src/cloud-foundry.module.ts b/src/frontend/packages/cloud-foundry/src/cloud-foundry-package.module.ts similarity index 93% rename from src/frontend/packages/cloud-foundry/src/cloud-foundry.module.ts rename to src/frontend/packages/cloud-foundry/src/cloud-foundry-package.module.ts index 1b0d5ebf3f..6e088679f4 100644 --- a/src/frontend/packages/cloud-foundry/src/cloud-foundry.module.ts +++ b/src/frontend/packages/cloud-foundry/src/cloud-foundry-package.module.ts @@ -16,6 +16,7 @@ import { LongRunningCfOperationsService } from './shared/data-services/long-runn import { ServiceActionHelperService } from './shared/data-services/service-action-helper.service'; import { CloudFoundryUserProvidedServicesService } from './shared/services/cloud-foundry-user-provided-services.service'; import { CloudFoundryStoreModule } from './store/cloud-foundry.store.module'; +import { cfCurrentUserPermissionsService } from './user-permissions/cf-user-permissions-checkers'; @NgModule({ imports: [ @@ -37,6 +38,7 @@ import { CloudFoundryStoreModule } from './store/cloud-foundry.store.module'; // ]) ], providers: [ + ...cfCurrentUserPermissionsService, CfUserService, CloudFoundryService, ServiceActionHelperService, diff --git a/src/frontend/packages/cloud-foundry/src/features/applications/applications.module.ts b/src/frontend/packages/cloud-foundry/src/features/applications/applications.module.ts index 11b02a71f7..ce3afe8842 100644 --- a/src/frontend/packages/cloud-foundry/src/features/applications/applications.module.ts +++ b/src/frontend/packages/cloud-foundry/src/features/applications/applications.module.ts @@ -4,7 +4,6 @@ import { NgModule } from '@angular/core'; import { CoreModule } from '../../../../core/src/core/core.module'; import { SharedModule } from '../../../../core/src/shared/shared.module'; import { CloudFoundrySharedModule } from '../../shared/cf-shared.module'; -import { cfCurrentUserPermissionsService } from '../../user-permissions/cf-user-permissions-checkers'; import { ApplicationDeleteComponent } from './application-delete/application-delete.component'; import { DeleteAppServiceInstancesComponent, @@ -78,7 +77,6 @@ import { SshApplicationComponent } from './ssh-application/ssh-application.compo ApplicationMonitorService, DatePipe, ApplicationDeploySourceTypes, - ...cfCurrentUserPermissionsService ] }) export class ApplicationsModule { } diff --git a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/cloud-foundry.module.ts b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/cloud-foundry.module.ts index 9bffecd85b..76e9e15ff3 100644 --- a/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/cloud-foundry.module.ts +++ b/src/frontend/packages/cloud-foundry/src/features/cloud-foundry/cloud-foundry.module.ts @@ -8,7 +8,6 @@ import { CloudFoundrySharedModule } from '../../shared/cf-shared.module'; import { CFEndpointsListConfigService, } from '../../shared/components/list/list-types/cf-endpoints/cf-endpoints-list-config.service'; -import { cfCurrentUserPermissionsService } from '../../user-permissions/cf-user-permissions-checkers'; import { AddOrganizationComponent } from './add-organization/add-organization.component'; import { CreateOrganizationStepComponent, @@ -229,7 +228,6 @@ import { RemoveUserComponent } from './users/remove-user/remove-user.component'; CloudFoundryCellService, UserInviteService, UserInviteConfigureService, - ...cfCurrentUserPermissionsService ], entryComponents: [ UserInviteConfigurationDialogComponent diff --git a/src/frontend/packages/cloud-foundry/src/features/service-catalog/service-catalog.module.ts b/src/frontend/packages/cloud-foundry/src/features/service-catalog/service-catalog.module.ts index 93f1c8d797..a959216d92 100644 --- a/src/frontend/packages/cloud-foundry/src/features/service-catalog/service-catalog.module.ts +++ b/src/frontend/packages/cloud-foundry/src/features/service-catalog/service-catalog.module.ts @@ -4,7 +4,6 @@ import { NgModule } from '@angular/core'; import { CoreModule } from '../../../../core/src/core/core.module'; import { SharedModule } from '../../../../core/src/shared/shared.module'; import { CloudFoundrySharedModule } from '../../shared/cf-shared.module'; -import { cfCurrentUserPermissionsService } from '../../user-permissions/cf-user-permissions-checkers'; import { CreateApplicationModule } from '../applications/create-application/create-application.module'; import { ServiceBaseComponent } from './service-base/service-base.component'; import { ServiceCatalogPageComponent } from './service-catalog-page/service-catalog-page.component'; @@ -34,9 +33,6 @@ import { ServiceTabsBaseComponent } from './service-tabs-base/service-tabs-base. ], exports: [ ServiceTabsBaseComponent, - ], - providers: [ - ...cfCurrentUserPermissionsService ] }) export class ServiceCatalogModule { } diff --git a/src/frontend/packages/cloud-foundry/src/features/services/services.module.ts b/src/frontend/packages/cloud-foundry/src/features/services/services.module.ts index ae6a9ca71d..628dced999 100644 --- a/src/frontend/packages/cloud-foundry/src/features/services/services.module.ts +++ b/src/frontend/packages/cloud-foundry/src/features/services/services.module.ts @@ -8,7 +8,6 @@ import { ServiceCatalogModule } from '../../../../cloud-foundry/src/features/ser import { CoreModule } from '../../../../core/src/core/core.module'; import { SharedModule } from '../../../../core/src/shared/shared.module'; import { CloudFoundrySharedModule } from '../../shared/cf-shared.module'; -import { cfCurrentUserPermissionsService } from '../../user-permissions/cf-user-permissions-checkers'; import { DetachAppsComponent } from './detach-service-instance/detach-apps/detach-apps.component'; import { DetachServiceInstanceComponent } from './detach-service-instance/detach-service-instance.component'; import { ServicesWallComponent } from './services-wall/services-wall.component'; @@ -28,9 +27,6 @@ import { ServicesRoutingModule } from './services.routing'; ServicesWallComponent, DetachServiceInstanceComponent, DetachAppsComponent - ], - providers: [ - ...cfCurrentUserPermissionsService ] }) export class ServicesModule { } diff --git a/src/frontend/packages/cloud-foundry/src/shared/cf-shared.module.ts b/src/frontend/packages/cloud-foundry/src/shared/cf-shared.module.ts index 424e0e08c7..7da0831fa8 100644 --- a/src/frontend/packages/cloud-foundry/src/shared/cf-shared.module.ts +++ b/src/frontend/packages/cloud-foundry/src/shared/cf-shared.module.ts @@ -8,7 +8,6 @@ import { SharedModule } from '../../../core/src/shared/shared.module'; import { ApplicationInstanceChartComponent, } from '../features/applications/application/application-instance-chart/application-instance-chart.component'; -import { cfCurrentUserPermissionsService } from '../user-permissions/cf-user-permissions-checkers'; import { AddServiceInstanceBaseStepComponent, } from './components/add-service-instance/add-service-instance-base-step/add-service-instance-base-step.component'; @@ -380,8 +379,7 @@ const cfListCards: Type>[] = [ providers: [ ApplicationStateService, GitSCMService, - CloudFoundryUserProvidedServicesService, - ...cfCurrentUserPermissionsService + CloudFoundryUserProvidedServicesService ] }) export class CloudFoundrySharedModule { } diff --git a/src/frontend/packages/cloud-foundry/src/store/cloud-foundry.store.module.ts b/src/frontend/packages/cloud-foundry/src/store/cloud-foundry.store.module.ts index d209acc642..f2c9b707bd 100644 --- a/src/frontend/packages/cloud-foundry/src/store/cloud-foundry.store.module.ts +++ b/src/frontend/packages/cloud-foundry/src/store/cloud-foundry.store.module.ts @@ -1,7 +1,6 @@ import { NgModule } from '@angular/core'; import { EffectsModule } from '@ngrx/effects'; -import { cfCurrentUserPermissionsService } from '../user-permissions/cf-user-permissions-checkers'; import { CloudFoundryReducersModule } from './cloud-foundry.reducers.module'; import { AppVariablesEffect } from './effects/app-variables.effects'; import { AppEffects } from './effects/app.effects'; @@ -31,9 +30,6 @@ import { UsersRolesEffects } from './effects/users-roles.effects'; CfValidateEffects, UsersRolesEffects ]) - ], - providers: [ - ...cfCurrentUserPermissionsService ] }) export class CloudFoundryStoreModule { } diff --git a/src/frontend/packages/core/src/app.module.ts b/src/frontend/packages/core/src/app.module.ts index 1cb71ceaa0..7ba9fb46a1 100644 --- a/src/frontend/packages/core/src/app.module.ts +++ b/src/frontend/packages/core/src/app.module.ts @@ -1,13 +1,13 @@ -import { NgModule, Injectable } from '@angular/core'; +import { Injectable, NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { Params, RouteReuseStrategy, RouterStateSnapshot } from '@angular/router'; -import { RouterStateSerializer, StoreRouterConnectingModule, DefaultRouterStateSerializer } from '@ngrx/router-store'; +import { DefaultRouterStateSerializer, RouterStateSerializer, StoreRouterConnectingModule } from '@ngrx/router-store'; import { Store } from '@ngrx/store'; import { debounceTime, filter, withLatestFrom } from 'rxjs/operators'; import { CfAutoscalerModule } from '../../cf-autoscaler/src/cf-autoscaler.module'; -import { CloudFoundryPackageModule } from '../../cloud-foundry/src/cloud-foundry.module'; +import { CloudFoundryPackageModule } from '../../cloud-foundry/src/cloud-foundry-package.module'; import { SetRecentlyVisitedEntityAction } from '../../store/src/actions/recently-visited.actions'; import { UpdateUserFavoriteMetadataAction, @@ -35,6 +35,7 @@ import { CustomizationService } from './core/customizations.types'; import { DynamicExtensionRoutes } from './core/extension/dynamic-extension-routes'; import { ExtensionService } from './core/extension/extension-service'; import { getGitHubAPIURL, GITHUB_API_URL } from './core/github.helpers'; +import { CurrentUserPermissionsService } from './core/permissions/current-user-permissions.service'; import { UserFavoriteManager } from './core/user-favorite-manager'; import { CustomImportModule } from './custom-import.module'; import { AboutModule } from './features/about/about.module'; @@ -116,7 +117,8 @@ export class CustomRouterStateSerializer SidePanelService, { provide: GITHUB_API_URL, useFactory: getGitHubAPIURL }, { provide: RouterStateSerializer, useClass: CustomRouterStateSerializer }, // Create action for router navigation - { provide: RouteReuseStrategy, useClass: CustomReuseStrategy } + { provide: RouteReuseStrategy, useClass: CustomReuseStrategy }, + CurrentUserPermissionsService ], bootstrap: [AppComponent] }) diff --git a/src/frontend/packages/core/src/core/core.module.ts b/src/frontend/packages/core/src/core/core.module.ts index e726c6eed2..ff8b4eb280 100644 --- a/src/frontend/packages/core/src/core/core.module.ts +++ b/src/frontend/packages/core/src/core/core.module.ts @@ -29,10 +29,6 @@ import { MDAppModule } from './md.module'; import { NotSetupGuardService } from './not-setup-guard.service'; import { PageHeaderService } from './page-header-service/page-header.service'; import { PageNotFoundComponentComponent } from './page-not-found-component/page-not-found-component.component'; -import { - CurrentUserPermissionsService, - CUSTOM_USER_PERMISSION_CHECKERS, -} from './permissions/current-user-permissions.service'; import { SafeImgPipe } from './safe-img.pipe'; import { StatefulIconComponent } from './stateful-icon/stateful-icon.component'; import { TruncatePipe } from './truncate.pipe'; @@ -88,11 +84,6 @@ import { WindowRef } from './window-ref/window-ref.service'; PaginationMonitorFactory, UserProfileService, EntityServiceFactory, - { - provide: CUSTOM_USER_PERMISSION_CHECKERS, - useValue: [] - }, - CurrentUserPermissionsService, { provide: APP_TITLE, useFactory: appTitleFactory, diff --git a/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts b/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts index 3d407620cd..0a7490fb0c 100644 --- a/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts +++ b/src/frontend/packages/core/src/core/permissions/current-user-permissions.service.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable } from '@angular/core'; +import { Inject, Injectable, Optional } from '@angular/core'; import { Store } from '@ngrx/store'; import { combineLatest, Observable, of } from 'rxjs'; import { distinctUntilChanged, map, switchMap } from 'rxjs/operators'; @@ -30,12 +30,14 @@ export class CurrentUserPermissionsService { private allCheckers: ICurrentUserPermissionsChecker[]; constructor( private store: Store, - @Inject(CUSTOM_USER_PERMISSION_CHECKERS) customCheckers: ICurrentUserPermissionsChecker[], + @Optional() @Inject(CUSTOM_USER_PERMISSION_CHECKERS) customCheckers: ICurrentUserPermissionsChecker[], private logger: LoggerService ) { + // Cannot set default value for parameter as the Optional decorator sets it to null + const nullSafeCustomCheckers = customCheckers || []; this.allCheckers = [ new StratosUserPermissionsChecker(store), - ...customCheckers + ...nullSafeCustomCheckers ] } /** diff --git a/src/frontend/packages/core/src/features/endpoints/endpoints-page/endpoints-page.component.spec.ts b/src/frontend/packages/core/src/features/endpoints/endpoints-page/endpoints-page.component.spec.ts index ce469196e9..2906a26a9d 100644 --- a/src/frontend/packages/core/src/features/endpoints/endpoints-page/endpoints-page.component.spec.ts +++ b/src/frontend/packages/core/src/features/endpoints/endpoints-page/endpoints-page.component.spec.ts @@ -9,6 +9,7 @@ import { appReducers } from '../../../../../store/src/reducers.module'; import { TabNavService } from '../../../../tab-nav.service'; import { CoreTestingModule } from '../../../../test-framework/core-test.modules'; import { CoreModule } from '../../../core/core.module'; +import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service'; import { SharedModule } from '../../../shared/shared.module'; import { SidePanelService } from './../../../shared/services/side-panel.service'; import { EndpointsPageComponent } from './endpoints-page.component'; @@ -33,7 +34,7 @@ describe('EndpointsPageComponent', () => { ), NoopAnimationsModule ], - providers: [TabNavService, SidePanelService] + providers: [TabNavService, SidePanelService, CurrentUserPermissionsService] }) .compileComponents(); })); diff --git a/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.spec.ts b/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.spec.ts index 13c1bae7e3..89281e1382 100644 --- a/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.spec.ts +++ b/src/frontend/packages/core/src/features/user-profile/edit-profile-info/edit-profile-info.component.spec.ts @@ -7,6 +7,7 @@ import { createBasicStoreModule } from '@stratosui/store/testing'; import { TabNavService } from '../../../../tab-nav.service'; import { CoreTestingModule } from '../../../../test-framework/core-test.modules'; import { CoreModule } from '../../../core/core.module'; +import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service'; import { UserProfileService } from '../../../core/user-profile.service'; import { SharedModule } from '../../../shared/shared.module'; import { EditProfileInfoComponent } from './edit-profile-info.component'; @@ -27,7 +28,7 @@ describe('EditProfileInfoComponent', () => { CoreTestingModule, createBasicStoreModule() ], - providers: [UserProfileService, TabNavService], + providers: [UserProfileService, TabNavService, CurrentUserPermissionsService], }) .compileComponents(); }); diff --git a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-list-config.service.spec.ts b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-list-config.service.spec.ts index d1a7a63121..25c6056137 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-list-config.service.spec.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-types/endpoint/endpoints-list-config.service.spec.ts @@ -4,6 +4,7 @@ import { createBasicStoreModule } from '@stratosui/store/testing'; import { CoreTestingModule } from '../../../../../../test-framework/core-test.modules'; import { CoreModule } from '../../../../../core/core.module'; +import { CurrentUserPermissionsService } from '../../../../../core/permissions/current-user-permissions.service'; import { SharedModule } from '../../../../shared.module'; import { EndpointListHelper } from './endpoint-list.helpers'; import { EndpointsListConfigService } from './endpoints-list-config.service'; @@ -11,7 +12,7 @@ import { EndpointsListConfigService } from './endpoints-list-config.service'; describe('EndpointsListConfigService', () => { beforeEach(() => { TestBed.configureTestingModule({ - providers: [EndpointsListConfigService, EndpointListHelper], + providers: [EndpointsListConfigService, EndpointListHelper, CurrentUserPermissionsService], imports: [ CommonModule, CoreModule, diff --git a/src/frontend/packages/core/src/shared/components/list/list.component.spec.ts b/src/frontend/packages/core/src/shared/components/list/list.component.spec.ts index 573d0cbabf..79d01782ed 100644 --- a/src/frontend/packages/core/src/shared/components/list/list.component.spec.ts +++ b/src/frontend/packages/core/src/shared/components/list/list.component.spec.ts @@ -14,6 +14,7 @@ import { APIResource } from '../../../../../store/src/types/api.types'; import { EndpointModel } from '../../../../../store/src/types/endpoint.types'; import { CoreTestingModule } from '../../../../test-framework/core-test.modules'; import { CoreModule } from '../../../core/core.module'; +import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service'; import { SharedModule } from '../../shared.module'; import { EndpointCardComponent } from './list-types/endpoint/endpoint-card/endpoint-card.component'; import { EndpointListHelper } from './list-types/endpoint/endpoint-list.helpers'; @@ -125,7 +126,8 @@ describe('ListComponent', () => { // ApplicationStateService, PaginationMonitorFactory, EntityMonitorFactory, - EndpointListHelper + EndpointListHelper, + CurrentUserPermissionsService ], imports: [ CoreModule, diff --git a/src/frontend/packages/core/src/shared/user-permission.directive.spec.ts b/src/frontend/packages/core/src/shared/user-permission.directive.spec.ts index 6e3ea57118..d1e89790c6 100644 --- a/src/frontend/packages/core/src/shared/user-permission.directive.spec.ts +++ b/src/frontend/packages/core/src/shared/user-permission.directive.spec.ts @@ -1,8 +1,7 @@ -import { Component, TemplateRef } from '@angular/core'; +import { Component } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { BaseTestModules, generateBaseTestStoreModules } from '../../test-framework/core-test.helper'; -import { UserPermissionDirective } from './user-permission.directive'; +import { BaseTestModules } from '../../test-framework/core-test.helper'; @Component({ template: `` diff --git a/src/frontend/packages/core/test-framework/core-test.helper.ts b/src/frontend/packages/core/test-framework/core-test.helper.ts index 50ff5a7509..bad6c14d0f 100644 --- a/src/frontend/packages/core/test-framework/core-test.helper.ts +++ b/src/frontend/packages/core/test-framework/core-test.helper.ts @@ -9,6 +9,7 @@ import { EntityCatalogHelper } from '../../store/src/entity-catalog/entity-catal import { EntityCatalogHelpers } from '../../store/src/entity-catalog/entity-catalog.helper'; import { appReducers } from '../../store/src/reducers.module'; import { CoreModule } from '../src/core/core.module'; +import { CurrentUserPermissionsService } from '../src/core/permissions/current-user-permissions.service'; import { ApplicationStateIconComponent, } from '../src/shared/components/application-state/application-state-icon/application-state-icon.component'; @@ -35,7 +36,10 @@ import { CoreTestingModule } from './core-test.modules'; @NgModule({ - imports: [CoreModule] + imports: [CoreModule], + providers: [ + CurrentUserPermissionsService + ] }) export class AppTestModule { constructor(