mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Restrict Explore UI to Editor and Admin roles
Access is restricted via not showing in the following places: * hide from sidemenu * hide from panel header menu * disable keybinding `x` Also adds a `roles` property to reactContainer routes that will be checked if `roles` is set, and on failure redirects to `/`.
This commit is contained in:
parent
7a3c1e162c
commit
f69654fcd5
@ -128,7 +128,7 @@ func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
|
|||||||
Children: dashboardChildNavs,
|
Children: dashboardChildNavs,
|
||||||
})
|
})
|
||||||
|
|
||||||
if setting.ExploreEnabled {
|
if setting.ExploreEnabled && (c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR) {
|
||||||
data.NavTree = append(data.NavTree, &dtos.NavLink{
|
data.NavTree = append(data.NavTree, &dtos.NavLink{
|
||||||
Text: "Explore",
|
Text: "Explore",
|
||||||
Id: "explore",
|
Id: "explore",
|
||||||
|
@ -14,7 +14,7 @@ export class KeybindingSrv {
|
|||||||
timepickerOpen = false;
|
timepickerOpen = false;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private $rootScope, private $location, private datasourceSrv, private timeSrv) {
|
constructor(private $rootScope, private $location, private datasourceSrv, private timeSrv, private contextSrv) {
|
||||||
// clear out all shortcuts on route change
|
// clear out all shortcuts on route change
|
||||||
$rootScope.$on('$routeChangeSuccess', () => {
|
$rootScope.$on('$routeChangeSuccess', () => {
|
||||||
Mousetrap.reset();
|
Mousetrap.reset();
|
||||||
@ -177,21 +177,24 @@ export class KeybindingSrv {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.bind('x', async () => {
|
// jump to explore if permissions allow
|
||||||
if (dashboard.meta.focusPanelId) {
|
if (this.contextSrv.isEditor) {
|
||||||
const panel = dashboard.getPanelById(dashboard.meta.focusPanelId);
|
this.bind('x', async () => {
|
||||||
const datasource = await this.datasourceSrv.get(panel.datasource);
|
if (dashboard.meta.focusPanelId) {
|
||||||
if (datasource && datasource.supportsExplore) {
|
const panel = dashboard.getPanelById(dashboard.meta.focusPanelId);
|
||||||
const range = this.timeSrv.timeRangeForUrl();
|
const datasource = await this.datasourceSrv.get(panel.datasource);
|
||||||
const state = {
|
if (datasource && datasource.supportsExplore) {
|
||||||
...datasource.getExploreState(panel),
|
const range = this.timeSrv.timeRangeForUrl();
|
||||||
range,
|
const state = {
|
||||||
};
|
...datasource.getExploreState(panel),
|
||||||
const exploreState = encodePathComponent(JSON.stringify(state));
|
range,
|
||||||
this.$location.url(`/explore/${exploreState}`);
|
};
|
||||||
|
const exploreState = encodePathComponent(JSON.stringify(state));
|
||||||
|
this.$location.url(`/explore/${exploreState}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
// delete panel
|
// delete panel
|
||||||
this.bind('p r', () => {
|
this.bind('p r', () => {
|
||||||
|
@ -16,6 +16,7 @@ class MetricsPanelCtrl extends PanelCtrl {
|
|||||||
datasourceName: any;
|
datasourceName: any;
|
||||||
$q: any;
|
$q: any;
|
||||||
$timeout: any;
|
$timeout: any;
|
||||||
|
contextSrv: any;
|
||||||
datasourceSrv: any;
|
datasourceSrv: any;
|
||||||
timeSrv: any;
|
timeSrv: any;
|
||||||
templateSrv: any;
|
templateSrv: any;
|
||||||
@ -37,6 +38,7 @@ class MetricsPanelCtrl extends PanelCtrl {
|
|||||||
// make metrics tab the default
|
// make metrics tab the default
|
||||||
this.editorTabIndex = 1;
|
this.editorTabIndex = 1;
|
||||||
this.$q = $injector.get('$q');
|
this.$q = $injector.get('$q');
|
||||||
|
this.contextSrv = $injector.get('contextSrv');
|
||||||
this.datasourceSrv = $injector.get('datasourceSrv');
|
this.datasourceSrv = $injector.get('datasourceSrv');
|
||||||
this.timeSrv = $injector.get('timeSrv');
|
this.timeSrv = $injector.get('timeSrv');
|
||||||
this.templateSrv = $injector.get('templateSrv');
|
this.templateSrv = $injector.get('templateSrv');
|
||||||
@ -312,7 +314,7 @@ class MetricsPanelCtrl extends PanelCtrl {
|
|||||||
|
|
||||||
getAdditionalMenuItems() {
|
getAdditionalMenuItems() {
|
||||||
const items = [];
|
const items = [];
|
||||||
if (this.datasource && this.datasource.supportsExplore) {
|
if (this.contextSrv.isEditor && this.datasource && this.datasource.supportsExplore) {
|
||||||
items.push({
|
items.push({
|
||||||
text: 'Explore',
|
text: 'Explore',
|
||||||
click: 'ctrl.explore();',
|
click: 'ctrl.explore();',
|
||||||
|
@ -6,6 +6,7 @@ import coreModule from 'app/core/core_module';
|
|||||||
import { store } from 'app/stores/store';
|
import { store } from 'app/stores/store';
|
||||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||||
import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
|
import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||||
|
import { ContextSrv } from 'app/core/services/context_srv';
|
||||||
|
|
||||||
function WrapInProvider(store, Component, props) {
|
function WrapInProvider(store, Component, props) {
|
||||||
return (
|
return (
|
||||||
@ -16,16 +17,31 @@ function WrapInProvider(store, Component, props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
export function reactContainer($route, $location, backendSrv: BackendSrv, datasourceSrv: DatasourceSrv) {
|
export function reactContainer(
|
||||||
|
$route,
|
||||||
|
$location,
|
||||||
|
backendSrv: BackendSrv,
|
||||||
|
datasourceSrv: DatasourceSrv,
|
||||||
|
contextSrv: ContextSrv
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
template: '',
|
template: '',
|
||||||
link(scope, elem) {
|
link(scope, elem) {
|
||||||
let component = $route.current.locals.component;
|
// Check permissions for this component
|
||||||
|
const { roles } = $route.current.locals;
|
||||||
|
if (roles && roles.length) {
|
||||||
|
if (!roles.some(r => contextSrv.hasRole(r))) {
|
||||||
|
$location.url('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let { component } = $route.current.locals;
|
||||||
// Dynamic imports return whole module, need to extract default export
|
// Dynamic imports return whole module, need to extract default export
|
||||||
if (component.default) {
|
if (component.default) {
|
||||||
component = component.default;
|
component = component.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
backendSrv: backendSrv,
|
backendSrv: backendSrv,
|
||||||
datasourceSrv: datasourceSrv,
|
datasourceSrv: datasourceSrv,
|
||||||
|
@ -113,6 +113,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
|
|||||||
.when('/explore/:initial?', {
|
.when('/explore/:initial?', {
|
||||||
template: '<react-container />',
|
template: '<react-container />',
|
||||||
resolve: {
|
resolve: {
|
||||||
|
roles: () => ['Editor', 'Admin'],
|
||||||
component: () => import(/* webpackChunkName: "explore" */ 'app/containers/Explore/Wrapper'),
|
component: () => import(/* webpackChunkName: "explore" */ 'app/containers/Explore/Wrapper'),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user