From 3eaaa5d32d835f76bba93336710143b24895f7ba Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Mon, 23 Apr 2018 17:44:29 +0200 Subject: [PATCH 1/4] fixed so user who can edit dashboard can edit row, fixes #11466 --- public/app/features/dashboard/dashgrid/DashboardRow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/dashboard/dashgrid/DashboardRow.tsx b/public/app/features/dashboard/dashgrid/DashboardRow.tsx index c2a84cb7da9..a95130de1f2 100644 --- a/public/app/features/dashboard/dashgrid/DashboardRow.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardRow.tsx @@ -95,7 +95,7 @@ export class DashboardRow extends React.Component { {title} ({hiddenPanels} hidden panels) - {config.bootData.user.orgRole !== 'Viewer' && ( + {this.dashboard.meta.canEdit === true && (
From 45e6d9fcc4e4d613b3e18b246d7ef7321207ada3 Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Mon, 23 Apr 2018 17:45:51 +0200 Subject: [PATCH 2/4] removed import config --- public/app/features/dashboard/dashgrid/DashboardRow.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/public/app/features/dashboard/dashgrid/DashboardRow.tsx b/public/app/features/dashboard/dashgrid/DashboardRow.tsx index a95130de1f2..b133d4450bb 100644 --- a/public/app/features/dashboard/dashgrid/DashboardRow.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardRow.tsx @@ -4,7 +4,6 @@ import { PanelModel } from '../panel_model'; import { PanelContainer } from './PanelContainer'; import templateSrv from 'app/features/templating/template_srv'; import appEvents from 'app/core/app_events'; -import config from 'app/core/config'; export interface DashboardRowProps { panel: PanelModel; From 1446f5444787a4e2250cc596bd5c59ed232a1eef Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Tue, 24 Apr 2018 09:45:53 +0200 Subject: [PATCH 3/4] fixed test --- .../app/features/dashboard/specs/DashboardRow.jest.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/public/app/features/dashboard/specs/DashboardRow.jest.tsx b/public/app/features/dashboard/specs/DashboardRow.jest.tsx index c0ac172aa26..fa1e6acead2 100644 --- a/public/app/features/dashboard/specs/DashboardRow.jest.tsx +++ b/public/app/features/dashboard/specs/DashboardRow.jest.tsx @@ -2,19 +2,13 @@ import React from 'react'; import { shallow } from 'enzyme'; import { DashboardRow } from '../dashgrid/DashboardRow'; import { PanelModel } from '../panel_model'; -import config from '../../../core/config'; describe('DashboardRow', () => { let wrapper, panel, getPanelContainer, dashboardMock; beforeEach(() => { dashboardMock = { toggleRow: jest.fn() }; - - config.bootData = { - user: { - orgRole: 'Admin', - }, - }; + dashboardMock.meta = { canEdit: true }; getPanelContainer = jest.fn().mockReturnValue({ getDashboard: jest.fn().mockReturnValue(dashboardMock), @@ -42,7 +36,7 @@ describe('DashboardRow', () => { }); it('should have zero actions as viewer', () => { - config.bootData.user.orgRole = 'Viewer'; + dashboardMock.meta.canEdit = false; panel = new PanelModel({ collapsed: false }); wrapper = shallow(); expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(0); From 38a4a2dc60581b0b74e703ef6650a08ae54fc92c Mon Sep 17 00:00:00 2001 From: Patrick O'Carroll Date: Tue, 24 Apr 2018 11:22:58 +0200 Subject: [PATCH 4/4] changed test name and dashboardMock code --- .../app/features/dashboard/specs/DashboardRow.jest.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard/specs/DashboardRow.jest.tsx b/public/app/features/dashboard/specs/DashboardRow.jest.tsx index fa1e6acead2..8424346b0c5 100644 --- a/public/app/features/dashboard/specs/DashboardRow.jest.tsx +++ b/public/app/features/dashboard/specs/DashboardRow.jest.tsx @@ -7,8 +7,12 @@ describe('DashboardRow', () => { let wrapper, panel, getPanelContainer, dashboardMock; beforeEach(() => { - dashboardMock = { toggleRow: jest.fn() }; - dashboardMock.meta = { canEdit: true }; + dashboardMock = { + toggleRow: jest.fn(), + meta: { + canEdit: true, + }, + }; getPanelContainer = jest.fn().mockReturnValue({ getDashboard: jest.fn().mockReturnValue(dashboardMock), @@ -35,7 +39,7 @@ describe('DashboardRow', () => { expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(2); }); - it('should have zero actions as viewer', () => { + it('should have zero actions when cannot edit', () => { dashboardMock.meta.canEdit = false; panel = new PanelModel({ collapsed: false }); wrapper = shallow();