From 47d837b5736ca2e0d71520e9d2cc9deec3388b3f Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Mon, 24 Apr 2023 17:18:45 +0200 Subject: [PATCH] SONAR-19084 Improve github authentication setting --- .../extensions/CreateApplicationForm.tsx | 4 +- .../CreateApplicationForm-test.tsx.snap | 1 - .../AlmBindingDefinitionFormRenderer.tsx | 4 +- .../authentication/Authentication.tsx | 28 +++- ...mField.tsx => AuthenticationFormField.tsx} | 18 +-- ...eld.tsx => AuthenticationSecuredField.tsx} | 37 +++-- ...ield.tsx => AuthenticationToggleField.tsx} | 14 +- ...gurationForm.tsx => ConfigurationForm.tsx} | 38 +++-- .../authentication/GithubAutheticationTab.tsx | 142 ++++++++++++++++++ ...tication.tsx => SamlAuthenticationTab.tsx} | 37 +++-- .../__tests__/Authentication-it.tsx | 4 +- .../authentication/hook/useConfiguration.ts | 125 +++++++++++++++ .../hook/useGithubConfiguration.ts | 54 +++++++ .../hook/useLoadSamlSettings.ts | 105 +++---------- .../main/js/components/controls/BoxedTabs.tsx | 2 +- .../resources/org/sonar/l10n/core.properties | 9 ++ 16 files changed, 452 insertions(+), 170 deletions(-) rename server/sonar-web/src/main/js/apps/settings/components/authentication/{SamlFormField.tsx => AuthenticationFormField.tsx} (83%) rename server/sonar-web/src/main/js/apps/settings/components/authentication/{SamlSecuredField.tsx => AuthenticationSecuredField.tsx} (68%) rename server/sonar-web/src/main/js/apps/settings/components/authentication/{SamlToggleField.tsx => AuthenticationToggleField.tsx} (78%) rename server/sonar-web/src/main/js/apps/settings/components/authentication/{SamlConfigurationForm.tsx => ConfigurationForm.tsx} (83%) create mode 100644 server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAutheticationTab.tsx rename server/sonar-web/src/main/js/apps/settings/components/authentication/{SamlAuthentication.tsx => SamlAuthenticationTab.tsx} (94%) create mode 100644 server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useConfiguration.ts create mode 100644 server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts diff --git a/server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx b/server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx index 674dc5bd20e..450c50989d7 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/CreateApplicationForm.tsx @@ -19,9 +19,9 @@ */ import * as React from 'react'; import { createApplication } from '../../../api/application'; -import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons'; import Radio from '../../../components/controls/Radio'; import SimpleModal from '../../../components/controls/SimpleModal'; +import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import MandatoryFieldMarker from '../../../components/ui/MandatoryFieldMarker'; import MandatoryFieldsExplanation from '../../../components/ui/MandatoryFieldsExplanation'; @@ -104,7 +104,7 @@ export default class CreateApplicationForm extends React.PureComponent {({ onCloseClick, onFormSubmit, submitting }) => ( -
+

{header}

diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/CreateApplicationForm-test.tsx.snap b/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/CreateApplicationForm-test.tsx.snap index eca852deb51..a193f2cd305 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/CreateApplicationForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/__snapshots__/CreateApplicationForm-test.tsx.snap @@ -18,7 +18,6 @@ exports[`should render correctly: form 1`] = ` size="small" >
- +

{header}

diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/Authentication.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/Authentication.tsx index 361c2495e63..a10aa8293f2 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/Authentication.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/Authentication.tsx @@ -37,7 +37,8 @@ import { Feature } from '../../../../types/features'; import { ExtendedSettingDefinition } from '../../../../types/settings'; import { AUTHENTICATION_CATEGORY } from '../../constants'; import CategoryDefinitionsList from '../CategoryDefinitionsList'; -import SamlAuthentication, { SAML } from './SamlAuthentication'; +import GithubAithentication from './GithubAutheticationTab'; +import SamlAuthenticationTab, { SAML } from './SamlAuthenticationTab'; interface Props { definitions: ExtendedSettingDefinition[]; @@ -52,7 +53,7 @@ export type AuthenticationTabs = | AlmKeys.GitLab | AlmKeys.BitbucketServer; -const DOCUMENTATION_LINK_SUFFIXES = { +export const DOCUMENTATION_LINK_SUFFIXES = { [SAML]: 'saml/overview', [AlmKeys.GitHub]: 'github', [AlmKeys.GitLab]: 'gitlab', @@ -109,7 +110,7 @@ export function Authentication(props: Props & WithAvailableFeaturesProps) { ), }, - ]; + ] as const; return ( <> @@ -151,7 +152,10 @@ export function Authentication(props: Props & WithAvailableFeaturesProps) { {tabs.map((tab) => (
- {tab.key === SAML && } + {tab.key === SAML && ( + def.subCategory === SAML)} + /> + )} + + {tab.key === AlmKeys.GitHub && ( + def.subCategory === AlmKeys.GitHub)} + /> + )} - {tab.key !== SAML && ( + {tab.key !== SAML && tab.key !== AlmKeys.GitHub && ( <> {translate('settings.authentication.help.link')} diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlFormField.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationFormField.tsx similarity index 83% rename from server/sonar-web/src/main/js/apps/settings/components/authentication/SamlFormField.tsx rename to server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationFormField.tsx index d86afef207d..85706584951 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/SamlFormField.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/AuthenticationFormField.tsx @@ -23,8 +23,9 @@ import ValidationInput, { } from '../../../../components/controls/ValidationInput'; import MandatoryFieldMarker from '../../../../components/ui/MandatoryFieldMarker'; import { ExtendedSettingDefinition, SettingType } from '../../../../types/settings'; -import SamlSecuredField from './SamlSecuredField'; -import SamlToggleField from './SamlToggleField'; +import { isSecuredDefinition } from '../../utils'; +import AuthenticationSecuredField from './AuthenticationSecuredField'; +import AuthenticationToggleField from './AuthenticationToggleField'; interface SamlToggleFieldProps { settingValue?: string | boolean; @@ -35,7 +36,7 @@ interface SamlToggleFieldProps { error?: string; } -export default function SamlFormField(props: SamlToggleFieldProps) { +export default function AuthenticationFormField(props: SamlToggleFieldProps) { const { mandatory = false, definition, settingValue, isNotSet, error } = props; return ( @@ -50,23 +51,22 @@ export default function SamlFormField(props: SamlToggleFieldProps) { )}
- {definition.type === SettingType.PASSWORD && ( - )} - {definition.type === SettingType.BOOLEAN && ( - props.onFieldChange(definition.key, value)} /> )} - {definition.type === undefined && ( + {!isSecuredDefinition(definition) && definition.type === undefined && ( - {!showSecretField && ( -