]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15440 Handle QG action permissions
authorJeremy Davis <jeremy.davis@sonarsource.com>
Wed, 20 Oct 2021 15:17:39 +0000 (17:17 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 22 Oct 2021 20:03:28 +0000 (20:03 +0000)
server/sonar-web/src/main/js/apps/quality-gates/components/DetailsContent.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsContent-test.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap
server/sonar-web/src/main/js/types/types.d.ts

index ffdc7c0b09f76b36a911a0c17b3628ba2225246b..07fc3d5179ca390081317966a3ada3d185d367b3 100644 (file)
  */
 import * as React from 'react';
 import HelpTooltip from '../../../components/controls/HelpTooltip';
-import { withCurrentUser } from '../../../components/hoc/withCurrentUser';
 import { Alert } from '../../../components/ui/Alert';
 import { translate } from '../../../helpers/l10n';
-import { hasGlobalPermission } from '../../../helpers/users';
-import { Permissions } from '../../../types/permissions';
 import Conditions from './Conditions';
 import Projects from './Projects';
 import QualityGatePermissions from './QualityGatePermissions';
 
 export interface DetailsContentProps {
-  currentUser: T.CurrentUser;
   isDefault?: boolean;
   metrics: T.Dict<T.Metric>;
   onAddCondition: (condition: T.Condition) => void;
@@ -40,12 +36,10 @@ export interface DetailsContentProps {
 }
 
 export function DetailsContent(props: DetailsContentProps) {
-  const { currentUser, isDefault, metrics, qualityGate, updatedConditionId } = props;
+  const { isDefault, metrics, qualityGate, updatedConditionId } = props;
   const conditions = qualityGate.conditions || [];
   const actions = qualityGate.actions || {};
 
-  const displayPermissions = hasGlobalPermission(currentUser, Permissions.QualityGateAdmin);
-
   return (
     <div className="layout-page-main-inner">
       {isDefault && (qualityGate.conditions === undefined || qualityGate.conditions.length === 0) && (
@@ -89,7 +83,7 @@ export function DetailsContent(props: DetailsContentProps) {
             />
           )}
         </div>
-        {displayPermissions && (
+        {actions.delegate && (
           <div className="width-50 big-padded-left">
             <QualityGatePermissions qualityGate={qualityGate} />
           </div>
@@ -99,4 +93,4 @@ export function DetailsContent(props: DetailsContentProps) {
   );
 }
 
-export default React.memo(withCurrentUser(DetailsContent));
+export default React.memo(DetailsContent);
index 1c88e599b0a447231e5cfe9e088f5da9a9faaadc..c7f4d9ff49d5406eba15c46eaad34f1ea7e383bd 100644 (file)
@@ -20,7 +20,7 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import { mockQualityGate } from '../../../../helpers/mocks/quality-gates';
-import { mockCondition, mockLoggedInUser } from '../../../../helpers/testMocks';
+import { mockCondition } from '../../../../helpers/testMocks';
 import { DetailsContent, DetailsContentProps } from '../DetailsContent';
 
 it('should render correctly', () => {
@@ -30,14 +30,15 @@ it('should render correctly', () => {
     shallowRender({ isDefault: true, qualityGate: mockQualityGate({ conditions: [] }) })
   ).toMatchSnapshot('is default, no conditions');
   expect(
-    shallowRender({ currentUser: mockLoggedInUser({ permissions: { global: ['gateadmin'] } }) })
+    shallowRender({
+      qualityGate: mockQualityGate({ actions: { delegate: true } })
+    })
   ).toMatchSnapshot('Admin');
 });
 
 function shallowRender(props: Partial<DetailsContentProps> = {}) {
   return shallow(
     <DetailsContent
-      currentUser={mockLoggedInUser()}
       metrics={{}}
       onAddCondition={jest.fn()}
       onRemoveCondition={jest.fn()}
index 68f3b08cce18102c75597b7badedfdaae626cf25..ba5a76662eb205c14556317ad96dc323ace583ea 100644 (file)
@@ -24,7 +24,7 @@ exports[`should render correctly: loaded 1`] = `
       refreshItem={[Function]}
       refreshList={[MockFunction]}
     />
-    <Memo(Connect(withCurrentUser(DetailsContent)))
+    <Memo(DetailsContent)
       isDefault={false}
       metrics={Object {}}
       onAddCondition={[Function]}
index 1be520d5214e6441710c335272dc34580d6d7b4e..c1f3da95dad56ab1e3489775a37c7b250b447d3c 100644 (file)
@@ -6,30 +6,16 @@ exports[`should render correctly: Admin 1`] = `
 >
   <Connect(withAppState(Conditions))
     canEdit={false}
-    conditions={
-      Array [
-        Object {
-          "error": "10",
-          "id": 1,
-          "metric": "coverage",
-          "op": "LT",
-        },
-      ]
-    }
+    conditions={Array []}
     metrics={Object {}}
     onAddCondition={[MockFunction]}
     onRemoveCondition={[MockFunction]}
     onSaveCondition={[MockFunction]}
     qualityGate={
       Object {
-        "conditions": Array [
-          Object {
-            "error": "10",
-            "id": 1,
-            "metric": "coverage",
-            "op": "LT",
-          },
-        ],
+        "actions": Object {
+          "delegate": true,
+        },
         "id": "1",
         "name": "qualitygate",
       }
@@ -63,14 +49,9 @@ exports[`should render correctly: Admin 1`] = `
         key="1"
         qualityGate={
           Object {
-            "conditions": Array [
-              Object {
-                "error": "10",
-                "id": 1,
-                "metric": "coverage",
-                "op": "LT",
-              },
-            ],
+            "actions": Object {
+              "delegate": true,
+            },
             "id": "1",
             "name": "qualitygate",
           }
@@ -83,14 +64,9 @@ exports[`should render correctly: Admin 1`] = `
       <QualityGatePermissions
         qualityGate={
           Object {
-            "conditions": Array [
-              Object {
-                "error": "10",
-                "id": 1,
-                "metric": "coverage",
-                "op": "LT",
-              },
-            ],
+            "actions": Object {
+              "delegate": true,
+            },
             "id": "1",
             "name": "qualitygate",
           }
index 74ccbfd754b5b80375098195f27f0a839b4b62b8..6884cc8643508107f2d4ce208b035c5ee1c464a8 100644 (file)
@@ -621,6 +621,7 @@ declare namespace T {
     actions?: {
       associateProjects?: boolean;
       copy?: boolean;
+      delegate?: boolean;
       delete?: boolean;
       manageConditions?: boolean;
       rename?: boolean;