Skip to content

Commit

Permalink
Show empty screen with error message if no permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Feb 26, 2020
1 parent 10bf90f commit f20a936
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 @@ -57,6 +57,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 {
} = syncQuery(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 @@ -171,11 +171,18 @@ export class DashboardAppController {
dashboardStateManager.getIsViewMode() &&
!dashboardConfig.getHideWriteControls();

const getIsEmptyInReadonlyMode = () =>
!dashboardStateManager.getPanels().length &&
!getShouldShowEditHelp() &&
!getShouldShowViewHelp() &&
dashboardConfig.getHideWriteControls();
const getIsEmptyInReadonlyModeOrUserHasNoPermissions = () => {
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 @@ -241,7 +248,7 @@ export class DashboardAppController {
}
const shouldShowEditHelp = getShouldShowEditHelp();
const shouldShowViewHelp = getShouldShowViewHelp();
const isEmptyInReadonlyMode = getIsEmptyInReadonlyMode();
const isEmptyInReadonlyMode = getIsEmptyInReadonlyModeOrUserHasNoPermissions();
return {
id: dashboardStateManager.savedDashboard.id || '',
filters: queryFilter.getFilters(),
Expand Down Expand Up @@ -298,7 +305,7 @@ export class DashboardAppController {
dashboardContainer.renderEmpty = () => {
const shouldShowEditHelp = getShouldShowEditHelp();
const shouldShowViewHelp = getShouldShowViewHelp();
const isEmptyInReadOnlyMode = getIsEmptyInReadonlyMode();
const isEmptyInReadOnlyMode = getIsEmptyInReadonlyModeOrUserHasNoPermissions();
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 @@ -145,6 +145,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 f20a936

Please sign in to comment.