From bb479f8716776ab8a68a9fd24ddabc578f889dc9 Mon Sep 17 00:00:00 2001 From: Matteo Mara Date: Fri, 23 Sep 2022 15:53:13 +0200 Subject: [PATCH] SONAR-17117 migrate project import feature trigger to /api/features/list endpoint --- .../js/apps/projectDump/ProjectDumpApp.tsx | 22 +++++++--------- .../__tests__/ProjectDumpApp-test.tsx | 6 ++--- .../sonar-web/src/main/js/types/appstate.ts | 1 - .../sonar-web/src/main/js/types/features.ts | 3 ++- .../org/sonar/server/ui/ws/GlobalAction.java | 7 ------ .../sonar/server/ui/ws/global-example.json | 1 - .../sonar/server/ui/ws/GlobalActionTest.java | 25 ------------------- 7 files changed, 14 insertions(+), 51 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx b/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx index 471e6f22599..0e9dd698d05 100644 --- a/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx +++ b/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx @@ -20,11 +20,13 @@ import * as React from 'react'; import { getActivity } from '../../api/ce'; import { getStatus } from '../../api/project-dump'; -import withAppStateContext from '../../app/components/app-state/withAppStateContext'; +import withAvailableFeatures, { + WithAvailableFeaturesProps +} from '../../app/components/available-features/withAvailableFeatures'; import withComponentContext from '../../app/components/componentContext/withComponentContext'; import { throwGlobalError } from '../../helpers/error'; import { translate } from '../../helpers/l10n'; -import { AppState } from '../../types/appstate'; +import { Feature } from '../../types/features'; import { DumpStatus, DumpTask } from '../../types/project-dump'; import { ActivityRequestParameters, TaskStatuses, TaskTypes } from '../../types/tasks'; import { Component } from '../../types/types'; @@ -34,8 +36,7 @@ import './styles.css'; const POLL_INTERNAL = 5000; -interface Props { - appState: AppState; +interface Props extends WithAvailableFeaturesProps { component: Component; } @@ -84,10 +85,7 @@ export class ProjectDumpApp extends React.Component { } getLastTaskOfEachType(componentKey: string) { - const { - appState: { projectImportFeatureEnabled } - } = this.props; - + const projectImportFeatureEnabled = this.props.hasFeature(Feature.ProjectImport); const all = projectImportFeatureEnabled ? [ this.getLastTask(componentKey, TaskTypes.ProjectExport), @@ -154,10 +152,8 @@ export class ProjectDumpApp extends React.Component { }; render() { - const { - component, - appState: { projectImportFeatureEnabled } - } = this.props; + const { component } = this.props; + const projectImportFeatureEnabled = this.props.hasFeature(Feature.ProjectImport); const { lastAnalysisTask, lastExportTask, lastImportTask, status } = this.state; return ( @@ -200,4 +196,4 @@ export class ProjectDumpApp extends React.Component { } } -export default withComponentContext(withAppStateContext(ProjectDumpApp)); +export default withComponentContext(withAvailableFeatures(ProjectDumpApp)); diff --git a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-test.tsx b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-test.tsx index 928cf3dd6ff..255e926dca1 100644 --- a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-test.tsx @@ -22,7 +22,7 @@ import * as React from 'react'; import { getActivity } from '../../../api/ce'; import { getStatus } from '../../../api/project-dump'; import { mockComponent } from '../../../helpers/mocks/component'; -import { mockAppState, mockDumpStatus, mockDumpTask } from '../../../helpers/testMocks'; +import { mockDumpStatus, mockDumpTask } from '../../../helpers/testMocks'; import { waitAndUpdate } from '../../../helpers/testUtils'; import { TaskStatuses } from '../../../types/tasks'; import { ProjectDumpApp } from '../ProjectDumpApp'; @@ -58,7 +58,7 @@ it('should render correctly', async () => { expect(wrapper).toMatchSnapshot('loaded'); - wrapper = shallowRender({ appState: mockAppState({ projectImportFeatureEnabled: false }) }); + wrapper = shallowRender({ hasFeature: jest.fn().mockReturnValue(false) }); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot('loaded without import'); }); @@ -91,7 +91,7 @@ it('should poll for task status update', async () => { function shallowRender(overrides: Partial = {}) { return shallow( diff --git a/server/sonar-web/src/main/js/types/appstate.ts b/server/sonar-web/src/main/js/types/appstate.ts index 62555148764..8124f143bb1 100644 --- a/server/sonar-web/src/main/js/types/appstate.ts +++ b/server/sonar-web/src/main/js/types/appstate.ts @@ -29,7 +29,6 @@ export interface AppState { canAdmin?: boolean; edition?: EditionKey; globalPages?: Extension[]; - projectImportFeatureEnabled?: boolean; instanceUsesDefaultAdminCredentials?: boolean; multipleAlmEnabled?: boolean; needIssueSync?: boolean; diff --git a/server/sonar-web/src/main/js/types/features.ts b/server/sonar-web/src/main/js/types/features.ts index cb4210542bc..87363ff5c2f 100644 --- a/server/sonar-web/src/main/js/types/features.ts +++ b/server/sonar-web/src/main/js/types/features.ts @@ -20,5 +20,6 @@ export enum Feature { MonoRepositoryPullRequestDecoration = 'monorepo', - RegulatoryReport = 'regulatory-reports' + RegulatoryReport = 'regulatory-reports', + ProjectImport = 'project-import' } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java index e08588d7149..0eaf0ec4ac5 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java @@ -140,7 +140,6 @@ public class GlobalAction implements NavigationWsAction, Startable { writeBranchSupport(json); writeInstanceUsesDefaultAdminCredentials(json); writeMultipleAlmEnabled(json); - writeProjectImportFeature(json); editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH))); writeNeedIssueSync(json); json.prop("standalone", webServer.isStandalone()); @@ -207,12 +206,6 @@ public class GlobalAction implements NavigationWsAction, Startable { json.prop("multipleAlmEnabled", multipleAlmFeatureProvider.enabled()); } - private void writeProjectImportFeature(JsonWriter json) { - Edition edition = editionProvider.get().orElse(null); - boolean isEnabled = isEditionEEorDCE(edition); - json.prop("projectImportFeatureEnabled", isEnabled); - } - private void writeNeedIssueSync(JsonWriter json) { try (DbSession dbSession = dbClient.openSession(false)) { json.prop("needIssueSync", issueIndexSyncChecker.isIssueSyncInProgress(dbSession)); diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json index 7a110f13d78..700eee264bc 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json @@ -26,7 +26,6 @@ "version": "6.2", "productionDatabase": true, "branchesEnabled": false, - "projectImportFeatureEnabled": false, "canAdmin": false, "standalone": true, "edition": "community" diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java index b37184ad49b..efa3d9568ec 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java @@ -52,7 +52,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.core.platform.EditionProvider.Edition.*; import static org.sonar.test.JsonAssert.assertJson; public class GlobalActionTest { @@ -238,30 +237,6 @@ public class GlobalActionTest { } - @Test - public void project_import_feature_enabled_ee_dce() { - init(); - when(editionProvider.get()).thenReturn(Optional.of(ENTERPRISE)); - assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}"); - - when(editionProvider.get()).thenReturn(Optional.of(DATACENTER)); - assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}"); - } - - @Test - public void project_import_feature_disabled_ce_de() { - init(); - when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY)); - assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}"); - - when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER)); - assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}"); - - when(editionProvider.get()).thenReturn(Optional.empty()); - assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}"); - } - - @Test public void return_need_issue_sync() { init(); -- 2.39.5