Bug: Fix delete dashboard snapshot for deleted dashboards (#50919)

* Bug: Fix delete dashboard snapshot for deleted dashboards

* Fix lint and make it work for all the errors

* Fix lint
pull/50942/head
idafurjes 3 years ago committed by GitHub
parent f3e3828279
commit 8ab8ce609b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      pkg/api/dashboard_snapshot.go

@ -3,6 +3,7 @@ package api
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
@ -269,11 +270,12 @@ func (hs *HTTPServer) DeleteDashboardSnapshot(c *models.ReqContext) response.Res
guardian := guardian.New(c.Req.Context(), dashboardID, c.OrgId, c.SignedInUser)
canEdit, err := guardian.CanEdit()
if err != nil {
// check for permissions only if the dahboard is found
if err != nil && !errors.Is(err, models.ErrDashboardNotFound) {
return response.Error(500, "Error while checking permissions for snapshot", err)
}
if !canEdit && query.Result.UserId != c.SignedInUser.UserId {
if !canEdit && query.Result.UserId != c.SignedInUser.UserId && !errors.Is(err, models.ErrDashboardNotFound) {
return response.Error(403, "Access denied to this snapshot", nil)
}

Loading…
Cancel
Save