mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix: Viewers can edit means that viewers have acces to Explore #14281
This commit is contained in:
@@ -34,6 +34,7 @@ export class Settings {
|
||||
disableUserSignUp: boolean;
|
||||
loginHint: any;
|
||||
loginError: any;
|
||||
viewersCanEdit: boolean;
|
||||
|
||||
constructor(options) {
|
||||
const defaults = {
|
||||
@@ -50,6 +51,7 @@ export class Settings {
|
||||
env: 'production',
|
||||
isEnterprise: false,
|
||||
},
|
||||
viewersCanEdit: false,
|
||||
};
|
||||
|
||||
_.extend(this, defaults, options);
|
||||
|
||||
@@ -8,6 +8,7 @@ import { getExploreUrl } from 'app/core/utils/explore';
|
||||
|
||||
import Mousetrap from 'mousetrap';
|
||||
import 'mousetrap-global-bind';
|
||||
import { ContextSrv } from './context_srv';
|
||||
|
||||
export class KeybindingSrv {
|
||||
helpModal: boolean;
|
||||
@@ -21,7 +22,7 @@ export class KeybindingSrv {
|
||||
private $timeout,
|
||||
private datasourceSrv,
|
||||
private timeSrv,
|
||||
private contextSrv
|
||||
private contextSrv: ContextSrv
|
||||
) {
|
||||
// clear out all shortcuts on route change
|
||||
$rootScope.$on('$routeChangeSuccess', () => {
|
||||
@@ -196,7 +197,7 @@ export class KeybindingSrv {
|
||||
});
|
||||
|
||||
// jump to explore if permissions allow
|
||||
if (this.contextSrv.isEditor && config.exploreEnabled) {
|
||||
if ((this.contextSrv.isEditor || config.viewersCanEdit) && config.exploreEnabled) {
|
||||
this.bind('x', async () => {
|
||||
if (dashboard.meta.focusPanelId) {
|
||||
const panel = dashboard.getPanelById(dashboard.meta.focusPanelId);
|
||||
|
||||
@@ -231,7 +231,7 @@ class MetricsPanelCtrl extends PanelCtrl {
|
||||
|
||||
getAdditionalMenuItems() {
|
||||
const items = [];
|
||||
if (config.exploreEnabled && this.contextSrv.isEditor && this.datasource) {
|
||||
if (config.exploreEnabled && (this.contextSrv.isEditor || config.viewersCanEdit) && this.datasource) {
|
||||
items.push({
|
||||
text: 'Explore',
|
||||
click: 'ctrl.explore();',
|
||||
|
||||
@@ -2,6 +2,7 @@ jest.mock('app/core/core', () => ({}));
|
||||
jest.mock('app/core/config', () => {
|
||||
return {
|
||||
exploreEnabled: true,
|
||||
viewersCanEdit: false,
|
||||
panels: {
|
||||
test: {
|
||||
id: 'test',
|
||||
@@ -14,6 +15,7 @@ jest.mock('app/core/config', () => {
|
||||
import q from 'q';
|
||||
import { PanelModel } from 'app/features/dashboard/panel_model';
|
||||
import { MetricsPanelCtrl } from '../metrics_panel_ctrl';
|
||||
import config from 'app/core/config';
|
||||
|
||||
describe('MetricsPanelCtrl', () => {
|
||||
let ctrl;
|
||||
@@ -46,6 +48,19 @@ describe('MetricsPanelCtrl', () => {
|
||||
expect(additionalItems.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and has datasource set that supports explore and viewersCanEdit is true', () => {
|
||||
beforeEach(() => {
|
||||
config.viewersCanEdit = true;
|
||||
ctrl.contextSrv = { isEditor: false };
|
||||
ctrl.datasource = { meta: { explore: true } };
|
||||
additionalItems = ctrl.getAdditionalMenuItems();
|
||||
});
|
||||
|
||||
it('should not return any items', () => {
|
||||
expect(additionalItems.length).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import UsersListPage from 'app/features/users/UsersListPage';
|
||||
import DataSourceDashboards from 'app/features/datasources/DataSourceDashboards';
|
||||
import DataSourceSettingsPage from '../features/datasources/settings/DataSourceSettingsPage';
|
||||
import OrgDetailsPage from '../features/org/OrgDetailsPage';
|
||||
import config from 'app/core/config';
|
||||
|
||||
/** @ngInject */
|
||||
export function setupAngularRoutes($routeProvider, $locationProvider) {
|
||||
@@ -129,7 +130,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
|
||||
template: '<react-container />',
|
||||
reloadOnSearch: false,
|
||||
resolve: {
|
||||
roles: () => ['Editor', 'Admin'],
|
||||
roles: () => (config.viewersCanEdit ? [] : ['Editor', 'Admin']),
|
||||
component: () => import(/* webpackChunkName: "explore" */ 'app/features/explore/Wrapper'),
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user