Allow custom index privileges for role management (#88076)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
d37852a343
commit
d080128cde
|
@ -65,6 +65,7 @@ exports[`it renders without crashing 1`] = `
|
|||
isClearable={true}
|
||||
isDisabled={false}
|
||||
onChange={[Function]}
|
||||
onCreateOption={[Function]}
|
||||
options={
|
||||
Array [
|
||||
Object {
|
||||
|
|
|
@ -36,6 +36,40 @@ test('it renders without crashing', () => {
|
|||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('it allows for custom index privileges', () => {
|
||||
const props = {
|
||||
indexPrivilege: {
|
||||
names: ['foo'],
|
||||
privileges: ['existing-custom', 'read'],
|
||||
query: '',
|
||||
field_security: {
|
||||
grant: [],
|
||||
},
|
||||
},
|
||||
formIndex: 0,
|
||||
indexPatterns: [],
|
||||
availableFields: [],
|
||||
availableIndexPrivileges: ['all', 'read', 'write', 'index'],
|
||||
isRoleReadOnly: false,
|
||||
allowDocumentLevelSecurity: true,
|
||||
allowFieldLevelSecurity: true,
|
||||
validator: new RoleValidator(),
|
||||
onChange: jest.fn(),
|
||||
onDelete: jest.fn(),
|
||||
intl: {} as any,
|
||||
};
|
||||
|
||||
const wrapper = mountWithIntl(<IndexPrivilegeForm {...props} />);
|
||||
|
||||
const indexPrivsSelect = wrapper.find('EuiComboBox[data-test-subj="privilegesInput0"]');
|
||||
|
||||
(indexPrivsSelect.props() as any).onCreateOption('custom-index-privilege');
|
||||
|
||||
expect(props.onChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ privileges: ['existing-custom', 'read', 'custom-index-privilege'] })
|
||||
);
|
||||
});
|
||||
|
||||
describe('delete button', () => {
|
||||
const props = {
|
||||
indexPrivilege: {
|
||||
|
|
|
@ -128,6 +128,7 @@ export class IndexPrivilegeForm extends Component<Props, State> {
|
|||
options={this.props.availableIndexPrivileges.map(toOption)}
|
||||
selectedOptions={this.props.indexPrivilege.privileges.map(toOption)}
|
||||
onChange={this.onPrivilegeChange}
|
||||
onCreateOption={this.onCreateCustomPrivilege}
|
||||
isDisabled={this.props.isRoleReadOnly}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
|
@ -390,6 +391,13 @@ export class IndexPrivilegeForm extends Component<Props, State> {
|
|||
});
|
||||
};
|
||||
|
||||
private onCreateCustomPrivilege = (customPrivilege: string) => {
|
||||
this.props.onChange({
|
||||
...this.props.indexPrivilege,
|
||||
privileges: [...this.props.indexPrivilege.privileges, customPrivilege],
|
||||
});
|
||||
};
|
||||
|
||||
private onQueryChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
this.props.onChange({
|
||||
...this.props.indexPrivilege,
|
||||
|
|
Loading…
Reference in a new issue