Dashboard: Restore panel edit permission check, fixes 26555' (#26556)

(cherry picked from commit 1df4f71197)
This commit is contained in:
Torkel Ödegaard
2020-07-24 12:08:01 +02:00
committed by Leonard Gram
parent e44acff11c
commit 5b7d1c7fe1
2 changed files with 20 additions and 0 deletions
@@ -139,6 +139,20 @@ describe('DashboardPage', () => {
});
});
dashboardPageScenario('When user goes into panel edit but has no edit permissions', ctx => {
ctx.setup(() => {
ctx.mount();
ctx.setDashboardProp({}, { canEdit: false });
ctx.wrapper?.setProps({
urlEditPanelId: '1',
});
});
it('Should update component state to fullscreen and edit', () => {
const state = ctx.wrapper?.state();
expect(state?.editPanel).toBe(null);
});
});
dashboardPageScenario('When user goes back to dashboard from view panel', ctx => {
ctx.setup(() => {
ctx.mount();
@@ -117,6 +117,12 @@ export class DashboardPage extends PureComponent<Props, State> {
// entering edit mode
if (!editPanel && urlEditPanelId) {
this.getPanelByIdFromUrlParam(urlEditPanelId, panel => {
// if no edit permission show error
if (!dashboard.canEditPanel(panel)) {
this.props.notifyApp(createErrorNotification('Permission to edit panel denied'));
return;
}
this.setState({ editPanel: panel });
});
}