From de160ea89db1173a8aad783f3405cfa8eb040629 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Wed, 20 Oct 2021 17:17:39 +0200 Subject: [PATCH] SONAR-15440 Handle QG action permissions --- .../components/DetailsContent.tsx | 12 ++--- .../__tests__/DetailsContent-test.tsx | 7 +-- .../__snapshots__/Details-test.tsx.snap | 2 +- .../DetailsContent-test.tsx.snap | 44 +++++-------------- server/sonar-web/src/main/js/types/types.d.ts | 1 + 5 files changed, 19 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; 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 (
{isDefault && (qualityGate.conditions === undefined || qualityGate.conditions.length === 0) && ( @@ -89,7 +83,7 @@ export function DetailsContent(props: DetailsContentProps) { /> )}
- {displayPermissions && ( + {actions.delegate && (
@@ -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 = {}) { return shallow( -