Skip to content

Commit

Permalink
[Dashboard] Show empty screen with error message if no permissions (e…
Browse files Browse the repository at this point in the history
…lastic#58584)

* Show empty screen with error message if no permissions

* Renaming function

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Maja Grubic and elasticmachine committed Feb 27, 2020
1 parent dc2dcd8 commit c97bc86
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export interface RenderDeps {
savedDashboards: SavedObjectLoader;
dashboardConfig: KibanaLegacyStart['dashboardConfig'];
dashboardCapabilities: any;
embeddableCapabilities: {
visualizeCapabilities: any;
mapsCapabilities: any;
};
uiSettings: IUiSettingsClient;
chrome: ChromeStart;
addBasePath: (path: string) => string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export class DashboardAppController {
embeddable,
share,
dashboardCapabilities,
embeddableCapabilities: { visualizeCapabilities, mapsCapabilities },
data: { query: queryService },
core: {
notifications,
Expand All @@ -134,7 +135,6 @@ export class DashboardAppController {
} = syncQueryStateWithUrl(queryService, kbnUrlStateStorage);

let lastReloadRequestTime = 0;

const dash = ($scope.dash = $route.current.locals.dash);
if (dash.id) {
chrome.docTitle.change(dash.title);
Expand Down Expand Up @@ -180,11 +180,18 @@ export class DashboardAppController {
dashboardStateManager.getIsViewMode() &&
!dashboardConfig.getHideWriteControls();

const getIsEmptyInReadonlyMode = () =>
!dashboardStateManager.getPanels().length &&
!getShouldShowEditHelp() &&
!getShouldShowViewHelp() &&
dashboardConfig.getHideWriteControls();
const shouldShowUnauthorizedEmptyState = () => {
const readonlyMode =
!dashboardStateManager.getPanels().length &&
!getShouldShowEditHelp() &&
!getShouldShowViewHelp() &&
dashboardConfig.getHideWriteControls();
const userHasNoPermissions =
!dashboardStateManager.getPanels().length &&
!visualizeCapabilities.save &&
!mapsCapabilities.save;
return readonlyMode || userHasNoPermissions;
};

const addVisualization = () => {
navActions[TopNavIds.VISUALIZE]();
Expand Down Expand Up @@ -250,7 +257,7 @@ export class DashboardAppController {
}
const shouldShowEditHelp = getShouldShowEditHelp();
const shouldShowViewHelp = getShouldShowViewHelp();
const isEmptyInReadonlyMode = getIsEmptyInReadonlyMode();
const isEmptyInReadonlyMode = shouldShowUnauthorizedEmptyState();
return {
id: dashboardStateManager.savedDashboard.id || '',
filters: queryFilter.getFilters(),
Expand Down Expand Up @@ -307,7 +314,7 @@ export class DashboardAppController {
dashboardContainer.renderEmpty = () => {
const shouldShowEditHelp = getShouldShowEditHelp();
const shouldShowViewHelp = getShouldShowViewHelp();
const isEmptyInReadOnlyMode = getIsEmptyInReadonlyMode();
const isEmptyInReadOnlyMode = shouldShowUnauthorizedEmptyState();
const isEmptyState = shouldShowEditHelp || shouldShowViewHelp || isEmptyInReadOnlyMode;
return isEmptyState ? (
<DashboardEmptyScreen
Expand Down
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/kibana/public/dashboard/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ export class DashboardPlugin implements Plugin {
savedQueryService: dataStart.query.savedQueries,
embeddable,
dashboardCapabilities: coreStart.application.capabilities.dashboard,
embeddableCapabilities: {
visualizeCapabilities: coreStart.application.capabilities.visualize,
mapsCapabilities: coreStart.application.capabilities.maps,
},
localStorage: new Storage(localStorage),
};
const { renderApp } = await import('./np_ready/application');
Expand Down

0 comments on commit c97bc86

Please sign in to comment.