diff options
author | Jeremy Davis <jeremy.davis@sonarsource.com> | 2021-10-20 17:17:39 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-10-22 20:03:28 +0000 |
commit | de160ea89db1173a8aad783f3405cfa8eb040629 (patch) | |
tree | 24c54af1215747ea99094965cb570b1a3c51aaf3 /server/sonar-web/src/main/js/apps | |
parent | 29533e50f4add1d6bfd61761b0f5ebab6576fe61 (diff) | |
download | sonarqube-de160ea89db1173a8aad783f3405cfa8eb040629.tar.gz sonarqube-de160ea89db1173a8aad783f3405cfa8eb040629.zip |
SONAR-15440 Handle QG action permissions
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
4 files changed, 18 insertions, 47 deletions
diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/DetailsContent.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/DetailsContent.tsx index ffdc7c0b09f..07fc3d5179c 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/DetailsContent.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/DetailsContent.tsx @@ -19,17 +19,13 @@ */ 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); diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsContent-test.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsContent-test.tsx index 1c88e599b0a..c7f4d9ff49d 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsContent-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/DetailsContent-test.tsx @@ -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()} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap index 68f3b08cce1..ba5a76662eb 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Details-test.tsx.snap @@ -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]} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap index 1be520d5214..c1f3da95dad 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/DetailsContent-test.tsx.snap @@ -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", } |