From cda30832b9af1294d0e6ad7e2eff90f889007d94 Mon Sep 17 00:00:00 2001 From: Sarath Nair <91882341+sarath-nair-sonarsource@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:57:57 +0200 Subject: [PATCH] SONAR-22947 Force re-sync when auto-provisioning setting change (#11764) --- .../authentication/__tests__/Authentication-Github-it.tsx | 4 ++++ server/sonar-web/src/main/js/queries/dop-translation.ts | 6 ++++++ .../src/main/js/queries/identity-provider/gitlab.ts | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-Github-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-Github-it.tsx index 44bf87f1407..13a0f954738 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-Github-it.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-Github-it.tsx @@ -25,6 +25,7 @@ import { byLabelText, byRole, byText } from '~sonar-aligned/helpers/testSelector import ComputeEngineServiceMock from '../../../../../api/mocks/ComputeEngineServiceMock'; import DopTranslationServiceMock from '../../../../../api/mocks/DopTranslationServiceMock'; import GithubProvisioningServiceMock from '../../../../../api/mocks/GithubProvisioningServiceMock'; +import GitlabProvisioningServiceMock from '../../../../../api/mocks/GitlabProvisioningServiceMock'; import SettingsServiceMock from '../../../../../api/mocks/SettingsServiceMock'; import SystemServiceMock from '../../../../../api/mocks/SystemServiceMock'; import { AvailableFeaturesContext } from '../../../../../app/components/available-features/AvailableFeaturesContext'; @@ -42,6 +43,7 @@ let system: SystemServiceMock; let settingsHandler: SettingsServiceMock; let computeEngineHandler: ComputeEngineServiceMock; let dopTranslationHandler: DopTranslationServiceMock; +let gitlabHandler: GitlabProvisioningServiceMock; const mockedGitHubConfigurationResponse = mockGitHubConfiguration({ apiUrl: 'API url', @@ -56,6 +58,7 @@ beforeEach(() => { system = new SystemServiceMock(); settingsHandler = new SettingsServiceMock(); computeEngineHandler = new ComputeEngineServiceMock(); + gitlabHandler = new GitlabProvisioningServiceMock(); }); afterEach(() => { @@ -64,6 +67,7 @@ afterEach(() => { system.reset(); computeEngineHandler.reset(); dopTranslationHandler.reset(); + gitlabHandler.reset(); }); const ghContainer = byRole('tabpanel', { name: 'github GitHub' }); diff --git a/server/sonar-web/src/main/js/queries/dop-translation.ts b/server/sonar-web/src/main/js/queries/dop-translation.ts index c2879fd1359..44180d545bb 100644 --- a/server/sonar-web/src/main/js/queries/dop-translation.ts +++ b/server/sonar-web/src/main/js/queries/dop-translation.ts @@ -29,6 +29,8 @@ import { updateGitHubConfiguration, } from '../api/dop-translation'; import { translate } from '../helpers/l10n'; +import { ProvisioningType } from '../types/provisioning'; +import { useSyncWithGitHubNow } from './identity-provider/github'; /* * Project bindings @@ -87,6 +89,7 @@ export function useCreateGitHubConfigurationMutation() { export function useUpdateGitHubConfigurationMutation() { const client = useQueryClient(); + const { canSyncNow, synchronizeNow } = useSyncWithGitHubNow(); return useMutation({ mutationFn: ({ gitHubConfiguration, @@ -106,6 +109,9 @@ export function useUpdateGitHubConfigurationMutation() { }); client.setQueryData(['dop-translation', 'github-configs', 'fetch'], gitHubConfiguration); client.invalidateQueries({ queryKey: ['identity_provider'] }); + if (canSyncNow && gitHubConfiguration.provisioningType === ProvisioningType.auto) { + synchronizeNow(); + } addGlobalSuccessMessage(translate('settings.authentication.form.settings.save_success')); }, }); diff --git a/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts b/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts index a88cb9612b3..59d56b0ef4a 100644 --- a/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts +++ b/server/sonar-web/src/main/js/queries/identity-provider/gitlab.ts @@ -36,7 +36,7 @@ import { translate } from '../../helpers/l10n'; import { mapReactQueryResult } from '../../helpers/react-query'; import { AlmSyncStatus, DevopsRolesMapping, ProvisioningType } from '../../types/provisioning'; import { TaskStatuses, TaskTypes } from '../../types/tasks'; -import { createQueryHook, StaleTime } from '../common'; +import { StaleTime, createQueryHook } from '../common'; export function useGitLabConfigurationsQuery() { return useQuery({ @@ -65,6 +65,8 @@ export function useCreateGitLabConfigurationMutation() { export function useUpdateGitLabConfigurationMutation() { const client = useQueryClient(); + const { canSyncNow, synchronizeNow } = useSyncWithGitLabNow(); + return useMutation({ mutationFn: ({ id, @@ -83,6 +85,9 @@ export function useUpdateGitLabConfigurationMutation() { total: 1, }, }); + if (canSyncNow && data.provisioningType === ProvisioningType.auto) { + synchronizeNow(); + } addGlobalSuccessMessage(translate('settings.authentication.form.settings.save_success')); }, }); -- 2.39.5