From d56f4affd2538c5b9554e19b6ec2951d98d2b218 Mon Sep 17 00:00:00 2001 From: Yi Cai Date: Tue, 28 May 2024 01:51:47 -0400 Subject: [PATCH] fix(rbac): conditional access form validation (#1699) Signed-off-by: Yi Cai --- plugins/rbac/src/__fixtures__/mockConditionRules.ts | 4 +++- .../components/ConditionalAccess/ConditionsFormRowFields.tsx | 4 ++-- .../src/components/ConditionalAccess/CustomArrayField.tsx | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/rbac/src/__fixtures__/mockConditionRules.ts b/plugins/rbac/src/__fixtures__/mockConditionRules.ts index cc2c8e11b6..02bd9481f3 100644 --- a/plugins/rbac/src/__fixtures__/mockConditionRules.ts +++ b/plugins/rbac/src/__fixtures__/mockConditionRules.ts @@ -91,7 +91,8 @@ export const mockConditionRules = [ properties: { kinds: { type: 'array', - items: { type: 'string' }, + items: { type: 'string' }, // TODO: should be enum? + minItems: 1, description: 'List of kinds to match at least one of', }, }, @@ -110,6 +111,7 @@ export const mockConditionRules = [ claims: { type: 'array', items: { type: 'string' }, + minItems: 1, description: 'List of claims to match at least one on within ownedBy', }, diff --git a/plugins/rbac/src/components/ConditionalAccess/ConditionsFormRowFields.tsx b/plugins/rbac/src/components/ConditionalAccess/ConditionsFormRowFields.tsx index 84979bdfca..276b895371 100644 --- a/plugins/rbac/src/components/ConditionalAccess/ConditionsFormRowFields.tsx +++ b/plugins/rbac/src/components/ConditionalAccess/ConditionsFormRowFields.tsx @@ -123,14 +123,14 @@ export const ConditionsFormRowFields = ({ {schema ? (
handleConditionChange({ ...oldCondition, - params: data.formData ?? {}, + params: data.formData || {}, }) } transformErrors={errors => { diff --git a/plugins/rbac/src/components/ConditionalAccess/CustomArrayField.tsx b/plugins/rbac/src/components/ConditionalAccess/CustomArrayField.tsx index 5e09500328..e016310463 100644 --- a/plugins/rbac/src/components/ConditionalAccess/CustomArrayField.tsx +++ b/plugins/rbac/src/components/ConditionalAccess/CustomArrayField.tsx @@ -35,8 +35,9 @@ export const CustomArrayField = (props: FieldProps) => { label={name} value={fieldVal} onChange={e => { - setFieldVal(e.target.value); - onChange(e.target.value.split(',').map(val => val.trim())); + const value = e.target.value; + setFieldVal(value); + onChange(value ? value.split(',').map(val => val.trim()) : []); }} className={classes.bgPaper} required={required}