mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Security Solution] Create Field READ access of data view management bug fix (#122463)
This commit is contained in:
parent
83621d6100
commit
fa5d7de684
2 changed files with 35 additions and 9 deletions
|
@ -18,23 +18,26 @@ import { useKibana } from '../../../common/lib/kibana';
|
|||
import type { DataView } from '../../../../../../../src/plugins/data/common';
|
||||
import { TimelineId } from '../../../../common/types';
|
||||
|
||||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
|
||||
|
||||
let mockIndexPatternFieldEditor: Start;
|
||||
jest.mock('../../../common/lib/kibana');
|
||||
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
|
||||
|
||||
const runAllPromises = () => new Promise(setImmediate);
|
||||
|
||||
describe('CreateFieldButton', () => {
|
||||
beforeEach(() => {
|
||||
mockIndexPatternFieldEditor = indexPatternFieldEditorPluginMock.createStartContract();
|
||||
mockIndexPatternFieldEditor.userPermissions.editIndexPattern = () => true;
|
||||
useKibanaMock().services.dataViewFieldEditor = mockIndexPatternFieldEditor;
|
||||
useKibanaMock().services.data.dataViews.get = () => new Promise(() => undefined);
|
||||
|
||||
useKibanaMock().services.application.capabilities = {
|
||||
...useKibanaMock().services.application.capabilities,
|
||||
indexPatterns: { save: true },
|
||||
};
|
||||
});
|
||||
|
||||
it('displays the button when user has permissions', () => {
|
||||
mockIndexPatternFieldEditor.userPermissions.editIndexPattern = () => true;
|
||||
|
||||
// refactor below tests once resolved: https://github.com/elastic/kibana/issues/122462
|
||||
it('displays the button when user has read permissions and write permissions', () => {
|
||||
render(
|
||||
<CreateFieldButton
|
||||
selectedDataViewId={'dataViewId'}
|
||||
|
@ -49,7 +52,7 @@ describe('CreateFieldButton', () => {
|
|||
expect(screen.getByRole('button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("doesn't display the button when user doesn't have permissions", () => {
|
||||
it("doesn't display the button when user doesn't have read permissions", () => {
|
||||
mockIndexPatternFieldEditor.userPermissions.editIndexPattern = () => false;
|
||||
render(
|
||||
<CreateFieldButton
|
||||
|
@ -65,8 +68,26 @@ describe('CreateFieldButton', () => {
|
|||
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("doesn't display the button when user doesn't have write permissions", () => {
|
||||
useKibanaMock().services.application.capabilities = {
|
||||
...useKibanaMock().services.application.capabilities,
|
||||
indexPatterns: { save: false },
|
||||
};
|
||||
render(
|
||||
<CreateFieldButton
|
||||
selectedDataViewId={'dataViewId'}
|
||||
onClick={() => undefined}
|
||||
timelineId={TimelineId.detectionsPage}
|
||||
/>,
|
||||
{
|
||||
wrapper: TestProviders,
|
||||
}
|
||||
);
|
||||
|
||||
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calls 'onClick' param when the button is clicked", async () => {
|
||||
mockIndexPatternFieldEditor.userPermissions.editIndexPattern = () => true;
|
||||
useKibanaMock().services.data.dataViews.get = () => Promise.resolve({} as DataView);
|
||||
|
||||
const onClickParam = jest.fn();
|
||||
|
|
|
@ -41,6 +41,7 @@ export const CreateFieldButton = React.memo<CreateFieldButtonProps>(
|
|||
const {
|
||||
dataViewFieldEditor,
|
||||
data: { dataViews },
|
||||
application: { capabilities },
|
||||
} = useKibana().services;
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -83,7 +84,11 @@ export const CreateFieldButton = React.memo<CreateFieldButtonProps>(
|
|||
timelineId,
|
||||
]);
|
||||
|
||||
if (!dataViewFieldEditor?.userPermissions.editIndexPattern()) {
|
||||
if (
|
||||
!dataViewFieldEditor?.userPermissions.editIndexPattern() ||
|
||||
// remove below check once resolved: https://github.com/elastic/kibana/issues/122462
|
||||
!capabilities.indexPatterns.save
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue