Skip to content

Commit

Permalink
Hide "Manage Searches" if insufficient permissions (#109099)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Roes authored Aug 18, 2021
1 parent 05d1e32 commit 92dcef9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.

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 @@ -9,18 +9,38 @@
import React from 'react';
import { shallow } from 'enzyme';

const mockCapabilities = jest.fn().mockReturnValue({
savedObjectsManagement: {
edit: true,
},
});

jest.mock('../../../../../kibana_services', () => {
return {
getServices: () => ({
core: { uiSettings: {}, savedObjects: {} },
addBasePath: (path: string) => path,
capabilities: mockCapabilities(),
}),
};
});

import { OpenSearchPanel } from './open_search_panel';

test('render', () => {
const component = shallow(<OpenSearchPanel onClose={jest.fn()} makeUrl={jest.fn()} />);
expect(component).toMatchSnapshot();
describe('OpenSearchPanel', () => {
test('render', () => {
const component = shallow(<OpenSearchPanel onClose={jest.fn()} makeUrl={jest.fn()} />);
expect(component).toMatchSnapshot();
});

test('should not render manage searches button without permissions', () => {
mockCapabilities.mockReturnValue({
savedObjectsManagement: {
edit: false,
delete: false,
},
});
const component = shallow(<OpenSearchPanel onClose={jest.fn()} makeUrl={jest.fn()} />);
expect(component.find('[data-test-subj="manageSearches"]').exists()).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ export function OpenSearchPanel(props: OpenSearchPanelProps) {
const {
core: { uiSettings, savedObjects },
addBasePath,
capabilities,
} = getServices();

const hasSavedObjectPermission =
capabilities.savedObjectsManagement?.edit || capabilities.savedObjectsManagement?.delete;

return (
<EuiFlyout ownFocus onClose={props.onClose} data-test-subj="loadSearchForm">
<EuiFlyoutHeader hasBorder>
Expand Down Expand Up @@ -73,25 +77,28 @@ export function OpenSearchPanel(props: OpenSearchPanelProps) {
savedObjects={savedObjects}
/>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="flexEnd">
<EuiFlexItem grow={false}>
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButton
fill
onClick={props.onClose}
href={addBasePath(
`/app/management/kibana/objects?_a=${rison.encode({ tab: SEARCH_OBJECT_TYPE })}`
)}
>
<FormattedMessage
id="discover.topNav.openSearchPanel.manageSearchesButtonLabel"
defaultMessage="Manage searches"
/>
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlyoutFooter>
{hasSavedObjectPermission && (
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="flexEnd">
<EuiFlexItem grow={false}>
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButton
fill
onClick={props.onClose}
data-test-subj="manageSearchesBtn"
href={addBasePath(
`/app/management/kibana/objects?_a=${rison.encode({ tab: SEARCH_OBJECT_TYPE })}`
)}
>
<FormattedMessage
id="discover.topNav.openSearchPanel.manageSearchesButtonLabel"
defaultMessage="Manage searches"
/>
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlyoutFooter>
)}
</EuiFlyout>
);
}

0 comments on commit 92dcef9

Please sign in to comment.