mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05: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:
@@ -6,6 +6,7 @@ import coreModule from 'app/core/core_module';
|
||||
import { store } from 'app/stores/store';
|
||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
import { DatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
import { ContextSrv } from 'app/core/services/context_srv';
|
||||
|
||||
function WrapInProvider(store, Component, props) {
|
||||
return (
|
||||
@@ -16,16 +17,31 @@ function WrapInProvider(store, Component, props) {
|
||||
}
|
||||
|
||||
/** @ngInject */
|
||||
export function reactContainer($route, $location, backendSrv: BackendSrv, datasourceSrv: DatasourceSrv) {
|
||||
export function reactContainer(
|
||||
$route,
|
||||
$location,
|
||||
backendSrv: BackendSrv,
|
||||
datasourceSrv: DatasourceSrv,
|
||||
contextSrv: ContextSrv
|
||||
) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
template: '',
|
||||
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
|
||||
if (component.default) {
|
||||
component = component.default;
|
||||
}
|
||||
|
||||
const props = {
|
||||
backendSrv: backendSrv,
|
||||
datasourceSrv: datasourceSrv,
|
||||
|
||||
@@ -113,6 +113,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
|
||||
.when('/explore/:initial?', {
|
||||
template: '<react-container />',
|
||||
resolve: {
|
||||
roles: () => ['Editor', 'Admin'],
|
||||
component: () => import(/* webpackChunkName: "explore" */ 'app/containers/Explore/Wrapper'),
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user