Snapshots: Fix deleting snapshot with non existent dashboard ID (#64345)
* Add test for deleting snapshot for non existent dashboard * Add test for failure to fetch guardian other than ErrDashboardNotFound * Fix dashboard snapshot delete
This commit is contained in:
@@ -366,17 +366,19 @@ func (hs *HTTPServer) DeleteDashboardSnapshot(c *contextmodel.ReqContext) respon
|
||||
if dashboardID != 0 {
|
||||
g, err := guardian.New(c.Req.Context(), dashboardID, c.OrgID, c.SignedInUser)
|
||||
if err != nil {
|
||||
return response.Err(err)
|
||||
}
|
||||
if !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return response.Err(err)
|
||||
}
|
||||
} else {
|
||||
canEdit, err := g.CanEdit()
|
||||
// check for permissions only if the dashboard is found
|
||||
if err != nil && !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return response.Error(http.StatusInternalServerError, "Error while checking permissions for snapshot", err)
|
||||
}
|
||||
|
||||
canEdit, err := g.CanEdit()
|
||||
// check for permissions only if the dashboard is found
|
||||
if err != nil && !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return response.Error(http.StatusInternalServerError, "Error while checking permissions for snapshot", err)
|
||||
}
|
||||
|
||||
if !canEdit && queryResult.UserID != c.SignedInUser.UserID && !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return response.Error(http.StatusForbidden, "Access denied to this snapshot", nil)
|
||||
if !canEdit && queryResult.UserID != c.SignedInUser.UserID && !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return response.Error(http.StatusForbidden, "Access denied to this snapshot", nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user