]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20393 Add provision project visibility option on auto provisioning
authorMathieu Suen <mathieu.suen@sonarsource.com>
Tue, 12 Sep 2023 13:44:08 +0000 (15:44 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 12 Sep 2023 20:02:42 +0000 (20:02 +0000)
server/sonar-web/src/main/js/api/mocks/SettingsServiceMock.ts
server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAuthenticationTab.tsx
server/sonar-web/src/main/js/apps/settings/components/authentication/hook/useGithubConfiguration.ts
server/sonar-web/src/main/js/helpers/mocks/definitions-list.ts

index 9d28dd63c5426382d76a29d28e8ab8509fc8e25d..3c9d84e6828f3aebd86145bb07f19521013db421 100644 (file)
@@ -111,6 +111,15 @@ export const DEFAULT_DEFINITIONS_MOCK = [
     description: 'Lets do it',
     type: SettingType.BOOLEAN,
   }),
+  mockDefinition({
+    category: 'authentication',
+    defaultValue: 'false',
+    key: 'provisioning.github.project.visibility.enabled',
+    subCategory: 'github',
+    name: 'Compilation Constants',
+    description: 'Lets do it',
+    type: SettingType.BOOLEAN,
+  }),
 ];
 
 export default class SettingsServiceMock {
index 7d378000a46f0c4625f04bbcfec2ade8127c8b30..8445bc7b6c3f819bd8f43ed09a7ecc6701f0ce4d 100644 (file)
@@ -41,14 +41,18 @@ import AuthenticationFormField from './AuthenticationFormField';
 import AutoProvisioningConsent from './AutoProvisionningConsent';
 import ConfigurationForm from './ConfigurationForm';
 import GitHubConfigurationValidity from './GitHubConfigurationValidity';
-import useGithubConfiguration, { GITHUB_JIT_FIELDS } from './hook/useGithubConfiguration';
+import useGithubConfiguration, {
+  GITHUB_ADDITIONAL_FIELDS,
+  GITHUB_JIT_FIELDS,
+  GITHUB_PROVISIONING_FIELDS,
+} from './hook/useGithubConfiguration';
 
 interface GithubAuthenticationProps {
   definitions: ExtendedSettingDefinition[];
   currentTab: AuthenticationTabs;
 }
 
-const GITHUB_EXCLUDED_FIELD = ['sonar.auth.github.enabled', 'sonar.auth.github.allowUsersToSignUp'];
+const GITHUB_EXCLUDED_FIELD = ['sonar.auth.github.enabled', ...GITHUB_ADDITIONAL_FIELDS];
 
 export default function GithubAuthenticationTab(props: GithubAuthenticationProps) {
   const { definitions, currentTab } = props;
@@ -276,7 +280,7 @@ export default function GithubAuthenticationTab(props: GithubAuthenticationProps
 
                           {githubProvisioningStatus && <GitHubSynchronisationWarning />}
 
-                          <div className="sw-flex sw-flex-1">
+                          <div className="sw-flex sw-flex-1 spacer-bottom">
                             <Button
                               className="spacer-top width-30"
                               onClick={synchronizeNow}
@@ -285,6 +289,29 @@ export default function GithubAuthenticationTab(props: GithubAuthenticationProps
                               {translate('settings.authentication.github.synchronize_now')}
                             </Button>
                           </div>
+                          {(newGithubProvisioningStatus ?? githubProvisioningStatus) && (
+                            <>
+                              <hr />
+                              {Object.values(values).map((val) => {
+                                if (!GITHUB_PROVISIONING_FIELDS.includes(val.key)) {
+                                  return null;
+                                }
+                                return (
+                                  <div key={val.key}>
+                                    <AuthenticationFormField
+                                      settingValue={
+                                        values[val.key]?.newValue ?? values[val.key]?.value
+                                      }
+                                      definition={val.definition}
+                                      mandatory={val.mandatory}
+                                      onFieldChange={setNewValue}
+                                      isNotSet={val.isNotSet}
+                                    />
+                                  </div>
+                                );
+                              })}
+                            </>
+                          )}
                         </>
                       ) : (
                         <p>
index 6f9ac390726924d373564e03b3eb74e760d3c153..c6d8c8db224e3e2ae913bf1a59fcfb2df5a4f0fc 100644 (file)
@@ -34,12 +34,14 @@ export const GITHUB_APP_ID_FIELD = 'sonar.auth.github.appId';
 export const GITHUB_API_URL_FIELD = 'sonar.auth.github.apiUrl';
 export const GITHUB_CLIENT_ID_FIELD = 'sonar.auth.github.clientId.secured';
 export const GITHUB_JIT_FIELDS = ['sonar.auth.github.allowUsersToSignUp'];
+export const GITHUB_PROVISIONING_FIELDS = ['provisioning.github.project.visibility.enabled'];
+
+export const GITHUB_ADDITIONAL_FIELDS = [...GITHUB_JIT_FIELDS, ...GITHUB_PROVISIONING_FIELDS];
 export const OPTIONAL_FIELDS = [
   GITHUB_ENABLED_FIELD,
-  ...GITHUB_JIT_FIELDS,
+  ...GITHUB_ADDITIONAL_FIELDS,
   'sonar.auth.github.organizations',
   'sonar.auth.github.groupsSync',
-  'provisioning.github.project.visibility.enabled',
 ];
 
 export interface SamlSettingValue {
@@ -65,10 +67,10 @@ export default function useGithubConfiguration(definitions: ExtendedSettingDefin
     newGithubProvisioningStatus !== undefined &&
     newGithubProvisioningStatus !== githubProvisioningStatus;
   const hasGithubProvisioningConfigChange =
-    some(GITHUB_JIT_FIELDS, isValueChange) || hasGithubProvisioningTypeChange;
+    some(GITHUB_ADDITIONAL_FIELDS, isValueChange) || hasGithubProvisioningTypeChange;
 
   const resetJitSetting = () => {
-    GITHUB_JIT_FIELDS.forEach((s) => setNewValue(s));
+    GITHUB_ADDITIONAL_FIELDS.forEach((s) => setNewValue(s));
   };
 
   const { mutate: saveSetting } = useSaveValueMutation();
@@ -89,7 +91,7 @@ export default function useGithubConfiguration(definitions: ExtendedSettingDefin
   };
 
   const saveGroup = () => {
-    const newValues = GITHUB_JIT_FIELDS.map((settingKey) => values[settingKey]);
+    const newValues = GITHUB_ADDITIONAL_FIELDS.map((settingKey) => values[settingKey]);
     saveSettings(newValues);
   };
 
index 3d92f418a3a7ef53cf41dd3fee064f6a4ab448e0..354aa3925f515721443b37197674726f23523583 100644 (file)
@@ -2527,4 +2527,16 @@ export const definitions: ExtendedSettingDefinition[] = [
     options: [],
     fields: [],
   },
+  {
+    name: 'Provision project visibility',
+    key: 'provisioning.github.project.visibility.enabled',
+    description:
+      'Change project visibility based on GitHub repository visibility. If disabled, every provisioned project will be private and will be seen only for those users that have explicit GitHub permissions for the according repository.',
+    type: SettingType.BOOLEAN,
+    category: 'authentication',
+    subCategory: 'github',
+    defaultValue: 'true',
+    options: [],
+    fields: [],
+  },
 ];