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

This commit is contained in:
Torkel Ödegaard 2020-07-24 07:29:33 +02:00 committed by GitHub
parent a94745af00
commit 1df4f71197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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();

View File

@ -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 });
});
}