]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20532 Do not allow custom roles without any permissions
authorViktor Vorona <viktor.vorona@sonarsource.com>
Wed, 27 Sep 2023 15:18:35 +0000 (17:18 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 28 Sep 2023 20:03:12 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/settings/components/authentication/GitHubMappingModal.tsx
server/sonar-web/src/main/js/apps/settings/components/authentication/GithubAuthenticationTab.tsx
server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 02006c9c4d12173a36645038941f3af67df03cb1..92700f3ea0391108e319c46ab41e9a500a432c40 100644 (file)
@@ -46,7 +46,7 @@ interface PermissionCellProps {
 }
 
 const DEFAULT_CUSTOM_ROLE_PERMISSIONS: GitHubMapping['permissions'] = {
-  user: false,
+  user: true,
   codeViewer: false,
   issueAdmin: false,
   securityHotspotAdmin: false,
@@ -140,8 +140,18 @@ export default function GitHubMappingModal({ mapping, setMapping, onClose }: Rea
     }
   };
 
+  const haveEmptyCustomRoles = !!mapping?.some(
+    (el) => !el.isBaseRole && !Object.values(el.permissions).some(Boolean),
+  );
+
   return (
-    <Modal contentLabel={header} onRequestClose={onClose} shouldCloseOnEsc size="medium">
+    <Modal
+      contentLabel={header}
+      onRequestClose={onClose}
+      shouldCloseOnOverlayClick={false}
+      shouldCloseOnEsc={false}
+      size="medium"
+    >
       <div className="modal-head">
         <h2>{header}</h2>
       </div>
@@ -234,7 +244,17 @@ export default function GitHubMappingModal({ mapping, setMapping, onClose }: Rea
         <Spinner loading={isLoading} />
       </div>
       <div className="modal-foot">
-        <SubmitButton onClick={onClose}>{translate('close')}</SubmitButton>
+        <div className="sw-flex sw-items-center sw-justify-end sw-h-8">
+          <Alert variant="error" className="sw-inline-block sw-mb-0 sw-mr-2">
+            {haveEmptyCustomRoles &&
+              translate(
+                'settings.authentication.github.configuration.roles_mapping.empty_custom_role',
+              )}
+          </Alert>
+          <SubmitButton disabled={haveEmptyCustomRoles} onClick={onClose}>
+            {translate('close')}
+          </SubmitButton>
+        </div>
       </div>
     </Modal>
   );
index 6ba0fc587bc46d96a50000c330ffb780f683ea4e..7bf81e1fc5df3507a9e9fc81e0a54aa43a3ba0b0 100644 (file)
@@ -375,7 +375,7 @@ export default function GithubAuthenticationTab(props: GithubAuthenticationProps
                   >
                     {translate('cancel')}
                   </ResetButtonLink>
-                  <Alert variant="warning" className="sw-w-[300px] sw-mb-0">
+                  <Alert variant="warning" className="sw-mb-0">
                     {hasGithubProvisioningConfigChange &&
                       translate('settings.authentication.github.configuration.unsaved_changes')}
                   </Alert>
index 77a94494869945c1c09ab13fb69ba830a26a4108..d2a216a92d20a211b974134e978659489f041e71 100644 (file)
@@ -163,6 +163,9 @@ const ui = {
     roleExistsError: byRole('dialog', {
       name: 'settings.authentication.github.configuration.roles_mapping.dialog.title',
     }).byText('settings.authentication.github.configuration.roles_mapping.role_exists'),
+    emptyRoleError: byRole('dialog', {
+      name: 'settings.authentication.github.configuration.roles_mapping.dialog.title',
+    }).byText('settings.authentication.github.configuration.roles_mapping.empty_custom_role'),
     deleteCustomRoleCustom2: byRole('button', {
       name: 'settings.authentication.github.configuration.roles_mapping.dialog.delete_custom_role.custom2',
     }),
@@ -1006,13 +1009,18 @@ describe('Github tab', () => {
       await user.click(github.customRoleAddBtn.get());
 
       let custom3Checkboxes = github.mappingCheckbox.getAll(github.getMappingRowByRole('custom3'));
-      expect(custom3Checkboxes[0]).not.toBeChecked();
+      expect(custom3Checkboxes[0]).toBeChecked();
       expect(custom3Checkboxes[1]).not.toBeChecked();
       expect(custom3Checkboxes[2]).not.toBeChecked();
       expect(custom3Checkboxes[3]).not.toBeChecked();
       expect(custom3Checkboxes[4]).not.toBeChecked();
       expect(custom3Checkboxes[5]).not.toBeChecked();
+      await user.click(custom3Checkboxes[0]);
+      expect(await github.emptyRoleError.find()).toBeInTheDocument();
+      expect(github.mappingDialogClose.get()).toBeDisabled();
       await user.click(custom3Checkboxes[1]);
+      expect(github.emptyRoleError.query()).not.toBeInTheDocument();
+      expect(github.mappingDialogClose.get()).toBeEnabled();
       await user.click(github.mappingDialogClose.get());
 
       expect(await github.saveGithubProvisioning.find()).toBeEnabled();
index 5cf3a651a65b366163032577e40cdcd7f5ee447d..8c409b5a0da6a340eba83cf23b40ae3b72299d8a 100644 (file)
@@ -1540,9 +1540,10 @@ settings.authentication.github.configuration.roles_mapping.button_label=Edit map
 settings.authentication.github.configuration.roles_mapping.dialog.title=GitHub Roles Mapping
 settings.authentication.github.configuration.roles_mapping.dialog.roles_column=Roles
 settings.authentication.github.configuration.roles_mapping.dialog.add_custom_role=Add custom role:
-settings.authentication.github.configuration.roles_mapping.role_exists=Role already exists
 settings.authentication.github.configuration.roles_mapping.dialog.custom_roles_description=When a custom role name added here matches an existing GitHub custom role in any of your organizations, the mapping applies to all users with this custom role. If an existing GitHub custom role has no exact match in this list, the permissions of its inherited base role are mapped.
 settings.authentication.github.configuration.roles_mapping.dialog.delete_custom_role=Delete custom role {0}
+settings.authentication.github.configuration.roles_mapping.role_exists=Role already exists.
+settings.authentication.github.configuration.roles_mapping.empty_custom_role=Custom roles should have some permissions.
 settings.authentication.github.configuration.unsaved_changes=You have unsaved changes.
 
 # SAML