diff --git a/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.test.tsx b/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.test.tsx index 7ff8b4a3bb..2e9e8766b5 100644 --- a/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.test.tsx +++ b/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.test.tsx @@ -76,4 +76,40 @@ describe('ConditionsForm', () => { expect(getByTestId('save-conditions')).toBeDisabled(); }); + + it('shows Multiple levels of nested conditions warning', () => { + const { getByTestId } = renderComponent({ + conditionsFormVal: { + anyOf: [ + { + rule: 'HAS_ANOTTATION', + resourceType: selPluginResourceType, + params: {}, + }, + { + allOf: [ + { + rule: 'HAS_ANOTTATION', + resourceType: selPluginResourceType, + params: {}, + }, + { + not: { + rule: 'HAS_LABEL', + resourceType: selPluginResourceType, + params: { + label: 'temp', + }, + }, + }, + ], + }, + ], + }, + }); + + expect( + getByTestId('multi-level-nested-conditions-warning'), + ).toBeInTheDocument(); + }); }); diff --git a/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.tsx b/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.tsx index f2108cb2f5..ab0a37965b 100644 --- a/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.tsx +++ b/plugins/rbac/src/components/ConditionalAccess/ConditionsForm.tsx @@ -3,6 +3,8 @@ import React from 'react'; import { PermissionCondition } from '@backstage/plugin-permission-common'; import { makeStyles } from '@material-ui/core'; +import { Alert, AlertTitle } from '@material-ui/lab'; +import WarningIcon from '@mui/icons-material/Warning'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import { RJSFValidationError } from '@rjsf/utils'; @@ -169,6 +171,32 @@ export const ConditionsForm = ({ ); }; + const hasMultiLevelNestedConditions = (): boolean => { + if (!Array.isArray(conditions[criteria as keyof ConditionsData])) { + return false; + } + + return (conditions[criteria as keyof ConditionsData] as Condition[]) + .filter(condition => !('rule' in condition)) + .some((firstLevelNestedCondition: Condition) => { + const nestedConditionCriteria = Object.keys( + firstLevelNestedCondition, + )[0]; + return ( + Array.isArray( + firstLevelNestedCondition[ + nestedConditionCriteria as keyof Condition + ], + ) && + ( + firstLevelNestedCondition[ + nestedConditionCriteria as keyof Condition + ] as Condition[] + ).some((con: Condition) => !('rule' in con)) + ); + }); + }; + return ( <> @@ -182,6 +210,28 @@ export const ConditionsForm = ({ handleSetErrors={handleSetErrors} setRemoveAllClicked={setRemoveAllClicked} /> + {hasMultiLevelNestedConditions() && ( + } + style={{ margin: '1.5rem 0 1rem 0' }} + severity="warning" + data-testid="multi-level-nested-conditions-warning" + > + + Multiple levels of nested conditions are not supported + + Only one level is displayed. Please use the{' '} + + CLI + {' '} + to view all nested conditions. + + )}