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

* Bug: Fix delete dashboard snapshot for deleted dashboards

* Fix lint and make it work for all the errors

* Fix lint

(cherry picked from commit 8ab8ce609b)

Co-authored-by: idafurjes <36131195+idafurjes@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-06-16 13:27:16 +02:00
committed by GitHub
co-authored by idafurjes
parent 87a325e6df
commit 50c729c23e
+4 -2
View File
@@ -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)
}