Skip to content

Commit

Permalink
Clean up dashboard privileges for read only dashboard roles
Browse files Browse the repository at this point in the history
  • Loading branch information
poffdeluxe committed Feb 8, 2021
1 parent 1b64837 commit ebb645d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ export function SavedObjectSaveModalDashboard(props: SaveModalDashboardProps) {
const initialCopyOnSave = !Boolean(documentId);

const { capabilities } = pluginServices.getHooks();
const { canAccessDashboards } = capabilities.useService();
const { canAccessDashboards, canCreateNewDashboards } = capabilities.useService();

const disableDashboardOptions = !canAccessDashboards();
// Disable the dashboard options if the user can't access dashboards or if they're read-only
const disableDashboardOptions = !canAccessDashboards() || !canCreateNewDashboards();

const [dashboardOption, setDashboardOption] = useState<'new' | 'existing' | null>(
documentId || disableDashboardOptions ? null : 'existing'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export interface SaveModalDashboardSelectorProps {

export function SaveModalDashboardSelector(props: SaveModalDashboardSelectorProps) {
const { documentId, onSelectDashboard, dashboardOption, onChange, copyOnSave } = props;
const { capabilities } = pluginServices.getHooks();
const { canCreateNewDashboards } = capabilities.useService();

const isDisabled = !copyOnSave && !!documentId;

return (
Expand Down Expand Up @@ -92,25 +89,22 @@ export function SaveModalDashboardSelector(props: SaveModalDashboardSelectorProp
</div>
<EuiSpacer size="s" />
</>
{canCreateNewDashboards() && (
<>
{' '}
<EuiRadio
checked={dashboardOption === 'new'}
id="new-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.newDashboardOptionLabel',
{
defaultMessage: 'New',
}
)}
onChange={() => onChange('new')}
disabled={isDisabled}
/>
<EuiSpacer size="s" />
</>
)}
<>
<EuiRadio
checked={dashboardOption === 'new'}
id="new-dashboard-option"
name="dashboard-option"
label={i18n.translate(
'presentationUtil.saveModalDashboard.newDashboardOptionLabel',
{
defaultMessage: 'New',
}
)}
onChange={() => onChange('new')}
disabled={isDisabled}
/>
<EuiSpacer size="s" />
</>
<EuiRadio
checked={dashboardOption === null}
id="add-to-library-option"
Expand Down
18 changes: 2 additions & 16 deletions x-pack/test/functional/apps/lens/add_to_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(hasPrompt).to.eql(false);
});

it('should only display "Existing" add-to-dashboard option', async () => {
it('should not display add-to-dashboard options', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await PageObjects.lens.goToTimeRange();
Expand All @@ -235,21 +235,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.click('lnsApp_saveButton');

const hasOptions = await testSubjects.exists('add-to-dashboard-options');
expect(hasOptions).to.eql(true);

const hasCreateNewOption = await find.existsByCssSelector(
'input[id="new-dashboard-option"]'
);
const hasExistingOption = await find.existsByCssSelector(
'input[id="existing-dashboard-option"]'
);
const hasAddToLibraryOption = await find.existsByCssSelector(
'input[id="add-to-library-option"]'
);

expect(hasCreateNewOption).to.eql(false);
expect(hasExistingOption).to.eql(true);
expect(hasAddToLibraryOption).to.eql(true);
expect(hasOptions).to.eql(false);
});
});
});
Expand Down

0 comments on commit ebb645d

Please sign in to comment.