Skip to content

Commit

Permalink
[8.16] Account for disabledShareUrl prop for rendered sharing options (
Browse files Browse the repository at this point in the history
…#206592) (#206769)

# Backport

This will backport the following commits from `main` to `8.16`:
- [Account for disabledShareUrl prop for rendered sharing options
(#206592)](#206592)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Eyo O.
Eyo","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-15T14:21:15Z","message":"Account
for disabledShareUrl prop for rendered sharing options (#206592)\n\n##
Summary\r\n\r\nCloses #201980.
\r\n\r\nThis PR adds logic to honor the `disabledShareUrl` prop. For the
user\r\nthis means that in instances where the user doesn't have
permissions to\r\ncreate a share url, the link tab doesn't get rendered
to such user.\r\n\r\n## How to test\r\n\r\n- Create a simple user and a
custom role. Assign only Read capabilities\r\nto Visualize Library\r\n-
Now sign up with that user, create a new lens visualization and try
to\r\nshare it\r\n- The share Link tab is not visible.\r\n\r\n<!--
\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following
conditions. \r\n\r\nReviewers should verify this PR satisfies this list
as well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...\r\n\r\n\r\n-->","sha":"44b756c2f5c1b22bc189c65f6b8ade597c5eea90","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:SharingURLs","v9.0.0","Team:SharedUX","backport:prev-major"],"title":"Account
for disabledShareUrl prop for rendered sharing
options","number":206592,"url":"https://github.com/elastic/kibana/pull/206592","mergeCommit":{"message":"Account
for disabledShareUrl prop for rendered sharing options (#206592)\n\n##
Summary\r\n\r\nCloses #201980.
\r\n\r\nThis PR adds logic to honor the `disabledShareUrl` prop. For the
user\r\nthis means that in instances where the user doesn't have
permissions to\r\ncreate a share url, the link tab doesn't get rendered
to such user.\r\n\r\n## How to test\r\n\r\n- Create a simple user and a
custom role. Assign only Read capabilities\r\nto Visualize Library\r\n-
Now sign up with that user, create a new lens visualization and try
to\r\nshare it\r\n- The share Link tab is not visible.\r\n\r\n<!--
\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following
conditions. \r\n\r\nReviewers should verify this PR satisfies this list
as well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...\r\n\r\n\r\n-->","sha":"44b756c2f5c1b22bc189c65f6b8ade597c5eea90"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206592","number":206592,"mergeCommit":{"message":"Account
for disabledShareUrl prop for rendered sharing options (#206592)\n\n##
Summary\r\n\r\nCloses #201980.
\r\n\r\nThis PR adds logic to honor the `disabledShareUrl` prop. For the
user\r\nthis means that in instances where the user doesn't have
permissions to\r\ncreate a share url, the link tab doesn't get rendered
to such user.\r\n\r\n## How to test\r\n\r\n- Create a simple user and a
custom role. Assign only Read capabilities\r\nto Visualize Library\r\n-
Now sign up with that user, create a new lens visualization and try
to\r\nshare it\r\n- The share Link tab is not visible.\r\n\r\n<!--
\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following
conditions. \r\n\r\nReviewers should verify this PR satisfies this list
as well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...\r\n\r\n\r\n-->","sha":"44b756c2f5c1b22bc189c65f6b8ade597c5eea90"}}]}]
BACKPORT-->

Co-authored-by: Eyo O. Eyo <[email protected]>
  • Loading branch information
kibanamachine and eokoneyo authored Jan 15, 2025
1 parent c96baea commit d072c84
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 59 deletions.
125 changes: 71 additions & 54 deletions src/plugins/share/public/components/share_tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import { ShareMenuTabs } from './share_tabs';
import { ShareMenuProvider } from './context';
import { ShareMenuProvider, type IShareContext } from './context';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { KibanaLocation, LocatorGetUrlParams, UrlService } from '../../common/url_service';
import {
Expand Down Expand Up @@ -48,7 +48,9 @@ const service = new UrlService<BrowserShortUrlClientFactoryCreateParams, Browser
locators,
}),
});
const mockShareContext = {

const mockShareContext: IShareContext = {
shareMenuItems: [],
allowEmbed: true,
allowShortUrl: true,
anonymousAccess: { getCapabilities: jest.fn(), getState: jest.fn() },
Expand All @@ -62,66 +64,81 @@ const mockShareContext = {
toasts: toastsServiceMock.createStartContract(),
i18n: i18nServiceMock.createStartContract(),
};

const mockGenerateExport = jest.fn();
const mockGenerateExportUrl = jest.fn().mockImplementation(() => 'generated-export-url');
const CSV = 'CSV' as const;
const PNG = 'PNG' as const;

describe('Share modal tabs', () => {
it('should render export tab when there are share menu items that are not disabled', async () => {
const testItem = [
{
shareMenuItem: { name: 'test', disabled: false },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
describe('link tab', () => {
it('should not render the link tab when the disableShareUrl prop is true', async () => {
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, disabledShareUrl: true }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="link"]').exists()).toBeFalsy();
});
});
it('should not render export tab when the license is disabled', async () => {
const testItems = [
{
shareMenuItem: { name: 'test', disabled: true },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];

const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItems }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
describe('export tab', () => {
it('should render export tab when there are share menu items that are not disabled', async () => {
const testItem = [
{
shareMenuItem: { name: 'test', disabled: false },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
});
it('should not render export tab when the license is disabled', async () => {
const testItems = [
{
shareMenuItem: { name: 'test', disabled: true },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];

expect(wrapper.find('[data-test-subj="export"]').exists()).toBeFalsy();
});
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItems }}>
<ShareMenuTabs />
</ShareMenuProvider>
);

expect(wrapper.find('[data-test-subj="export"]').exists()).toBeFalsy();
});

it('should render export tab is at least one is not disabled', async () => {
const testItem = [
{
shareMenuItem: { name: 'test', disabled: false },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
{
shareMenuItem: { name: 'test', disabled: true },
label: PNG,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
it('would render the export tab when there is at least one export type which is not disabled', async () => {
const testItem = [
{
shareMenuItem: { name: 'test', disabled: false },
label: CSV,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
{
shareMenuItem: { name: 'test', disabled: true },
label: PNG,
generateExport: mockGenerateExport,
generateExportUrl: mockGenerateExportUrl,
},
];
const wrapper = mountWithIntl(
<ShareMenuProvider shareContext={{ ...mockShareContext, shareMenuItems: testItem }}>
<ShareMenuTabs />
</ShareMenuProvider>
);
expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy();
});
});
});
16 changes: 11 additions & 5 deletions src/plugins/share/public/components/share_tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export const ShareMenu: FC<{ shareContext: IShareContext }> = ({ shareContext })
export const ShareMenuTabs = () => {
const shareContext = useShareTabsContext();

const { allowEmbed, objectTypeMeta, onClose, shareMenuItems, anchorElement } = shareContext;
const { allowEmbed, objectTypeMeta, onClose, shareMenuItems, anchorElement, disabledShareUrl } =
shareContext;

const tabs: Array<IModalTabDeclaration<any>> = [linkTab];
const tabs: Array<IModalTabDeclaration<any>> = [];

// do not show the link tab if the share url is disabled
if (!disabledShareUrl) {
tabs.push(linkTab);
}

const enabledItems = shareMenuItems.filter(({ shareMenuItem }) => !shareMenuItem?.disabled);

Expand All @@ -40,15 +46,15 @@ export const ShareMenuTabs = () => {
tabs.push(embedTab);
}

return (
return Boolean(tabs.length) ? (
<TabbedModal
tabs={tabs}
modalWidth={498}
onClose={onClose}
modalTitle={objectTypeMeta.title}
defaultSelectedTabId="link"
defaultSelectedTabId={tabs[0].id}
anchorElement={anchorElement}
data-test-subj="shareContextModal"
/>
);
) : null;
};

0 comments on commit d072c84

Please sign in to comment.