From 19015abd9133202a4ae05eaf6f508b0c803bce92 Mon Sep 17 00:00:00 2001 From: guillaume-peoch-sonarsource Date: Wed, 3 May 2023 10:45:29 +0200 Subject: [PATCH] SONAR-19084 Disable Github Provisioning for community edition --- .../authentication/GithubAutheticationTab.tsx | 232 ++++++++++-------- .../__tests__/Authentication-it.tsx | 28 ++- .../resources/org/sonar/l10n/core.properties | 1 + 3 files changed, 147 insertions(+), 114 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAutheticationTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAutheticationTab.tsx index 70b7e03a676..da6fb4043ae 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAutheticationTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAutheticationTab.tsx @@ -172,128 +172,148 @@ export default function GithubAithentication(props: GithubAuthenticationProps) { - {hasGithubProvisioning && ( -
-
{ - e.preventDefault(); - if (newGithubProvisioningStatus !== githubProvisioningStatus) { - setShowConfirmProvisioningModal(true); - } else { - await handleSaveGroup(); - } - }} - > -
- +
+ { + e.preventDefault(); + if (newGithubProvisioningStatus !== githubProvisioningStatus) { + setShowConfirmProvisioningModal(true); + } else { + await handleSaveGroup(); + } + }} + > +
+ - {enabled ? ( -
- setNewGithubProvisioningStatus(true)} - > -

- {translate( - 'settings.authentication.github.form.provisioning_with_github.description' - )} -

+ {enabled ? ( +
+ setNewGithubProvisioningStatus(true)} + disabled={!hasGithubProvisioning} + > + {hasGithubProvisioning ? ( + <> +

+ {translate( + 'settings.authentication.github.form.provisioning_with_github.description' + )} +

+

+ + {translate('documentation')} + + ), + }} + /> +

+ + ) : (

+ // Documentation page not ready yet. + {translate('documentation')} ), }} />

-
- setNewGithubProvisioningStatus(false)} - > - {Object.values(values).map((val) => { - if (!GITHUB_JIT_FIELDS.includes(val.key)) { - return null; - } - return ( -
- -
- ); - })} -
-
- ) : ( - - {translate('settings.authentication.github.enable_first')} - - )} -
- {enabled && ( - <> - - {translate('save')} - - { - setNewGithubProvisioningStatus(undefined); - resetJitSetting(); - }} - disabled={!hasGithubProvisioningConfigChange} + )} + + setNewGithubProvisioningStatus(false)} > - {translate('cancel')} - - + {Object.values(values).map((val) => { + if (!GITHUB_JIT_FIELDS.includes(val.key)) { + return null; + } + return ( +
+ +
+ ); + })} + +
+ ) : ( + + {translate('settings.authentication.github.enable_first')} + )} - {showConfirmProvisioningModal && ( - handleConfirmChangeProvisioning()} - header={translate( - 'settings.authentication.github.confirm', - newGithubProvisioningStatus ? 'auto' : 'jit' - )} - onClose={() => setShowConfirmProvisioningModal(false)} - isDestructive={!newGithubProvisioningStatus} - confirmButtonText={translate('yes')} +
+ {enabled && ( + <> + + {translate('save')} + + { + setNewGithubProvisioningStatus(undefined); + resetJitSetting(); + }} + disabled={!hasGithubProvisioningConfigChange} > - {translate( - 'settings.authentication.github.confirm', - newGithubProvisioningStatus ? 'auto' : 'jit', - 'description' - )} - - )} - -
- )} + {translate('cancel')} + + + )} + {showConfirmProvisioningModal && ( + handleConfirmChangeProvisioning()} + header={translate( + 'settings.authentication.github.confirm', + newGithubProvisioningStatus ? 'auto' : 'jit' + )} + onClose={() => setShowConfirmProvisioningModal(false)} + isDestructive={!newGithubProvisioningStatus} + confirmButtonText={translate('yes')} + > + {translate( + 'settings.authentication.github.confirm', + newGithubProvisioningStatus ? 'auto' : 'jit', + 'description' + )} + + )} + + )} diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx index dc5235e8cd5..d3a55581d5f 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx @@ -112,6 +112,7 @@ const ui = { saveGithubProvisioning: byRole('button', { name: 'save' }), groupAttribute: byRole('textbox', { name: 'property.sonar.auth.github.group.name.name' }), enableConfigButton: byRole('button', { name: 'settings.authentication.form.enable' }), + disableConfigButton: byRole('button', { name: 'settings.authentication.form.disable' }), editConfigButton: byRole('button', { name: 'settings.authentication.form.edit' }), enableFirstMessage: byText('settings.authentication.github.enable_first'), jitProvisioningButton: byRole('radio', { @@ -125,8 +126,6 @@ const ui = { await act(async () => { await user.type(await github.clientId.find(), 'Awsome GITHUB config'); await user.type(github.clientSecret.get(), 'Client shut'); - // await user.type(github.githubAppId.get(), 'http://test.org'); - // await user.type(github.privateKey.get(), '-secret-'); await user.type(github.githubApiUrl.get(), 'API Url'); await user.type(github.githubWebUrl.get(), 'WEb Url'); }); @@ -284,20 +283,33 @@ describe('Github tab', () => { }); it('should be able to enable/disable configuration', async () => { - const { github, saml } = ui; + const { github } = ui; const user = userEvent.setup(); renderAuthentication(); await user.click(await github.tab.find()); await github.createConfiguration(user); - await user.click(await saml.enableConfigButton.find()); + await user.click(await github.enableConfigButton.find()); - expect(await saml.disableConfigButton.find()).toBeInTheDocument(); - await user.click(saml.disableConfigButton.get()); - expect(saml.disableConfigButton.query()).not.toBeInTheDocument(); + expect(await github.disableConfigButton.find()).toBeInTheDocument(); + await user.click(github.disableConfigButton.get()); + expect(github.disableConfigButton.query()).not.toBeInTheDocument(); - expect(await saml.enableConfigButton.find()).toBeInTheDocument(); + expect(await github.enableConfigButton.find()).toBeInTheDocument(); + }); + + it('should not allow edtion below Enterprise to select Github provisioning', async () => { + const { github } = ui; + const user = userEvent.setup(); + + renderAuthentication(); + + await github.createConfiguration(user); + await user.click(await github.enableConfigButton.find()); + + expect(await github.jitProvisioningButton.find()).toBeChecked(); + expect(github.githubProvisioningButton.get()).toHaveAttribute('aria-disabled', 'true'); }); it('should be able to choose provisioning', async () => { diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 64fb16e4836..cf2f7c9fd62 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1345,6 +1345,7 @@ settings.authentication.github.enable_first=Enable your Github configuration for settings.authentication.github.form.provisioning_with_github=Automatic user and group provisioning settings.authentication.github.form.provisioning_with_github.description=Users and groups are automatically provisioned from your GitHub organizations. Once activated, managed users and groups can only be modified from your GitHub organizations/teams. Existing local users and groups will be kept. settings.authentication.github.form.provisioning_with_github.description.doc=For more details, see {documentation}. +settings.authentication.github.form.provisioning.disabled=Your current edition does not support provisioning with Github. See the {documentation} for more information. # SAML settings.authentication.form.create.saml=New SAML configuration -- 2.39.5