Allow custom index privileges for role management (#88076)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Larry Gregory 2021-01-14 12:17:00 -05:00 committed by GitHub
parent d37852a343
commit d080128cde
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 0 deletions

View file

@ -65,6 +65,7 @@ exports[`it renders without crashing 1`] = `
isClearable={true}
isDisabled={false}
onChange={[Function]}
onCreateOption={[Function]}
options={
Array [
Object {

View file

@ -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: {

View file

@ -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,