Skip to content

Commit d56f4af

Browse files
authored
fix(rbac): conditional access form validation (#1699)
Signed-off-by: Yi Cai <[email protected]>
1 parent ccd80db commit d56f4af

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

plugins/rbac/src/__fixtures__/mockConditionRules.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export const mockConditionRules = [
9191
properties: {
9292
kinds: {
9393
type: 'array',
94-
items: { type: 'string' },
94+
items: { type: 'string' }, // TODO: should be enum?
95+
minItems: 1,
9596
description: 'List of kinds to match at least one of',
9697
},
9798
},
@@ -110,6 +111,7 @@ export const mockConditionRules = [
110111
claims: {
111112
type: 'array',
112113
items: { type: 'string' },
114+
minItems: 1,
113115
description:
114116
'List of claims to match at least one on within ownedBy',
115117
},

plugins/rbac/src/components/ConditionalAccess/ConditionsFormRowFields.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ export const ConditionsFormRowFields = ({
123123
{schema ? (
124124
<Form
125125
schema={paramsSchema}
126-
formData={oldCondition?.params ?? null}
126+
formData={oldCondition?.params || {}}
127127
validator={validator}
128128
uiSchema={uiSchema}
129129
fields={customFields}
130130
onChange={data =>
131131
handleConditionChange({
132132
...oldCondition,
133-
params: data.formData ?? {},
133+
params: data.formData || {},
134134
})
135135
}
136136
transformErrors={errors => {

plugins/rbac/src/components/ConditionalAccess/CustomArrayField.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export const CustomArrayField = (props: FieldProps) => {
3535
label={name}
3636
value={fieldVal}
3737
onChange={e => {
38-
setFieldVal(e.target.value);
39-
onChange(e.target.value.split(',').map(val => val.trim()));
38+
const value = e.target.value;
39+
setFieldVal(value);
40+
onChange(value ? value.split(',').map(val => val.trim()) : []);
4041
}}
4142
className={classes.bgPaper}
4243
required={required}

0 commit comments

Comments
 (0)