Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppServices] Space privilege "Index pattern management" read still shows delete button (#53682) #115390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const confirmModalOptionsDelete = {

export const EditIndexPattern = withRouter(
({ indexPattern, history, location }: EditIndexPatternProps) => {
const { uiSettings, overlays, chrome, data } =
const { application, uiSettings, overlays, chrome, data } =
useKibana<IndexPatternManagmentContext>().services;
const [fields, setFields] = useState<IndexPatternField[]>(indexPattern.getNonScriptedFields());
const [conflictedFields, setConflictedFields] = useState<IndexPatternField[]>(
Expand Down Expand Up @@ -134,12 +134,14 @@ export const EditIndexPattern = withRouter(
const showTagsSection = Boolean(indexPattern.timeFieldName || (tags && tags.length > 0));
const kibana = useKibana();
const docsUrl = kibana.services.docLinks!.links.elasticsearch.mapping;
const userEditPermission = !!application?.capabilities?.indexPatterns?.save;

return (
<div data-test-subj="editIndexPattern" role="region" aria-label={headingAriaLabel}>
<IndexHeader
indexPattern={indexPattern}
setDefault={setDefaultPattern}
deleteIndexPatternClick={removePattern}
{...(userEditPermission ? { deleteIndexPatternClick: removePattern } : {})}
defaultIndex={defaultIndex}
>
{showTagsSection && (
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const items: IndexedFieldItem[] = [
kbnType: 'string',
excluded: false,
isMapped: true,
isUserEditable: true,
hasRuntime: false,
},
{
Expand All @@ -36,6 +37,7 @@ const items: IndexedFieldItem[] = [
info: [],
excluded: false,
isMapped: true,
isUserEditable: true,
hasRuntime: false,
},
{
Expand All @@ -46,6 +48,7 @@ const items: IndexedFieldItem[] = [
info: [],
excluded: false,
isMapped: true,
isUserEditable: true,
hasRuntime: false,
},
{
Expand All @@ -56,6 +59,18 @@ const items: IndexedFieldItem[] = [
info: [],
excluded: false,
isMapped: false,
isUserEditable: true,
hasRuntime: true,
},
{
name: 'noedit',
displayName: 'noedit',
type: 'keyword',
kbnType: 'text',
info: [],
excluded: false,
isMapped: false,
isUserEditable: false,
hasRuntime: true,
},
];
Expand Down Expand Up @@ -114,6 +129,13 @@ describe('Table', () => {
expect(editField).toBeCalled();
});

test('should not allow edit or deletion for user with only read access', () => {
const editAvailable = renderTable().prop('columns')[6].actions[0].available(items[4]);
const deleteAvailable = renderTable().prop('columns')[7].actions[0].available(items[4]);
expect(editAvailable).toBeFalsy();
expect(deleteAvailable).toBeFalsy();
});

test('render name', () => {
const mappedField = {
name: 'customer',
Expand All @@ -122,6 +144,7 @@ describe('Table', () => {
kbnType: 'string',
type: 'keyword',
isMapped: true,
isUserEditable: true,
hasRuntime: false,
};

Expand All @@ -134,6 +157,7 @@ describe('Table', () => {
kbnType: 'string',
type: 'keyword',
isMapped: false,
isUserEditable: true,
hasRuntime: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export class Table extends PureComponent<IndexedFieldProps> {
onClick: editField,
type: 'icon',
'data-test-subj': 'editFieldFormat',
available: (field) => field.isUserEditable,
},
],
width: '40px',
Expand All @@ -333,7 +334,7 @@ export class Table extends PureComponent<IndexedFieldProps> {
onClick: (field) => deleteField(field.name),
type: 'icon',
'data-test-subj': 'deleteField',
available: (field) => !field.isMapped,
available: (field) => !field.isMapped && field.isUserEditable,
},
],
width: '40px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React from 'react';
import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';
import { IndexPatternField, IndexPattern, IndexPatternType } from 'src/plugins/data/public';
import { IndexedFieldsTable } from './indexed_fields_table';
import { getFieldInfo } from '../../utils';
Expand Down Expand Up @@ -78,15 +78,21 @@ const fields = [
displayName: 'Elastic',
searchable: true,
esTypes: ['keyword'],
isUserEditable: true,
},
{ name: 'timestamp', displayName: 'timestamp', esTypes: ['date'] },
{ name: 'conflictingField', displayName: 'conflictingField', esTypes: ['keyword', 'long'] },
{ name: 'amount', displayName: 'amount', esTypes: ['long'] },
{ name: 'timestamp', displayName: 'timestamp', esTypes: ['date'], isUserEditable: true },
{
name: 'conflictingField',
displayName: 'conflictingField',
esTypes: ['keyword', 'long'],
isUserEditable: true,
},
{ name: 'amount', displayName: 'amount', esTypes: ['long'], isUserEditable: true },
].map(mockFieldToIndexPatternField);

describe('IndexedFieldsTable', () => {
test('should render normally', async () => {
const component = shallow(
const component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>> = shallow(
<IndexedFieldsTable
fields={fields}
indexPattern={indexPattern}
Expand All @@ -97,7 +103,7 @@ describe('IndexedFieldsTable', () => {
indexedFieldTypeFilter=""
fieldFilter=""
/>
);
).dive();

await new Promise((resolve) => process.nextTick(resolve));
component.update();
Expand All @@ -106,7 +112,7 @@ describe('IndexedFieldsTable', () => {
});

test('should filter based on the query bar', async () => {
const component = shallow(
const component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>> = shallow(
<IndexedFieldsTable
fields={fields}
indexPattern={indexPattern}
Expand All @@ -117,7 +123,7 @@ describe('IndexedFieldsTable', () => {
indexedFieldTypeFilter=""
fieldFilter=""
/>
);
).dive();

await new Promise((resolve) => process.nextTick(resolve));
component.setProps({ fieldFilter: 'Elast' });
Expand All @@ -127,7 +133,7 @@ describe('IndexedFieldsTable', () => {
});

test('should filter based on the type filter', async () => {
const component = shallow(
const component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>> = shallow(
<IndexedFieldsTable
fields={fields}
indexPattern={indexPattern}
Expand All @@ -138,7 +144,7 @@ describe('IndexedFieldsTable', () => {
indexedFieldTypeFilter=""
fieldFilter=""
/>
);
).dive();

await new Promise((resolve) => process.nextTick(resolve));
component.setProps({ indexedFieldTypeFilter: 'date' });
Expand All @@ -149,7 +155,7 @@ describe('IndexedFieldsTable', () => {

describe('IndexedFieldsTable with rollup index pattern', () => {
test('should render normally', async () => {
const component = shallow(
const component: ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>> = shallow(
<IndexedFieldsTable
fields={fields}
indexPattern={rollupIndexPattern}
Expand All @@ -160,7 +166,7 @@ describe('IndexedFieldsTable', () => {
indexedFieldTypeFilter=""
fieldFilter=""
/>
);
).dive();

await new Promise((resolve) => process.nextTick(resolve));
component.update();
Expand Down
Loading