From 661503f828d6b707d9cb6399b5f4d0534e2dfbd7 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Wed, 6 Jun 2018 10:50:47 +0200 Subject: [PATCH 1/2] Respect explore settings in config ini Previous explore restrictions only took permissions into consideration. * add `exploreEnabled` to global settings * only bind `x` if enabled * only show explore in panel menu if enabled --- pkg/api/frontendsettings.go | 1 + public/app/core/config.ts | 1 + public/app/core/services/keybindingSrv.ts | 3 ++- public/app/features/panel/metrics_panel_ctrl.ts | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index 84524bad526..c0de4b1bc6b 100644 --- a/pkg/api/frontendsettings.go +++ b/pkg/api/frontendsettings.go @@ -151,6 +151,7 @@ func getFrontendSettingsMap(c *m.ReqContext) (map[string]interface{}, error) { "authProxyEnabled": setting.AuthProxyEnabled, "ldapEnabled": setting.LdapEnabled, "alertingEnabled": setting.AlertingEnabled, + "exploreEnabled": setting.ExploreEnabled, "googleAnalyticsId": setting.GoogleAnalyticsId, "disableLoginForm": setting.DisableLoginForm, "externalUserMngInfo": setting.ExternalUserMngInfo, diff --git a/public/app/core/config.ts b/public/app/core/config.ts index 91b1cfef3a4..e111d0d0e9f 100644 --- a/public/app/core/config.ts +++ b/public/app/core/config.ts @@ -16,6 +16,7 @@ class Settings { defaultDatasource: string; alertingEnabled: boolean; authProxyEnabled: boolean; + exploreEnabled: boolean; ldapEnabled: boolean; oauth: any; disableUserSignUp: boolean; diff --git a/public/app/core/services/keybindingSrv.ts b/public/app/core/services/keybindingSrv.ts index b1021c90adc..cbc7871fbbd 100644 --- a/public/app/core/services/keybindingSrv.ts +++ b/public/app/core/services/keybindingSrv.ts @@ -1,6 +1,7 @@ import $ from 'jquery'; import _ from 'lodash'; +import config from 'app/core/config'; import coreModule from 'app/core/core_module'; import appEvents from 'app/core/app_events'; import { encodePathComponent } from 'app/core/utils/location_util'; @@ -178,7 +179,7 @@ export class KeybindingSrv { }); // jump to explore if permissions allow - if (this.contextSrv.isEditor) { + if (this.contextSrv.isEditor && config.exploreEnabled) { this.bind('x', async () => { if (dashboard.meta.focusPanelId) { const panel = dashboard.getPanelById(dashboard.meta.focusPanelId); diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index cbda8c874db..75c0de3bc6e 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -314,7 +314,7 @@ class MetricsPanelCtrl extends PanelCtrl { getAdditionalMenuItems() { const items = []; - if (this.contextSrv.isEditor && this.datasource && this.datasource.supportsExplore) { + if (config.exploreEnabled && this.contextSrv.isEditor && this.datasource && this.datasource.supportsExplore) { items.push({ text: 'Explore', click: 'ctrl.explore();', From 3bd58446d61aef25a7195f2722e56d117c56527e Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Wed, 6 Jun 2018 11:15:24 +0200 Subject: [PATCH 2/2] Fix metrics panel test by adding config mock --- .../features/panel/specs/metrics_panel_ctrl.jest.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/public/app/features/panel/specs/metrics_panel_ctrl.jest.ts b/public/app/features/panel/specs/metrics_panel_ctrl.jest.ts index 79564e2a123..a28bf92e63b 100644 --- a/public/app/features/panel/specs/metrics_panel_ctrl.jest.ts +++ b/public/app/features/panel/specs/metrics_panel_ctrl.jest.ts @@ -1,8 +1,19 @@ jest.mock('app/core/core', () => ({})); +jest.mock('app/core/config', () => { + return { + exploreEnabled: true, + panels: { + test: { + id: 'test', + name: 'test', + }, + }, + }; +}); -import { MetricsPanelCtrl } from '../metrics_panel_ctrl'; import q from 'q'; import { PanelModel } from 'app/features/dashboard/panel_model'; +import { MetricsPanelCtrl } from '../metrics_panel_ctrl'; describe('MetricsPanelCtrl', () => { let ctrl;