Dashboards: Allow updating a dashboard if the user doesn't have access to the parent folder (#78075)

* change where folder checks are done for dash creation/updates

* add test for folder not being found

* test fixes

* more test fixes

* add nlint directive to where folder IDs are used

* fix bad merge

* fix test
This commit is contained in:
Ieva
2023-11-16 11:11:35 +00:00
committed by GitHub
parent ba717454e1
commit b0448b92e5
9 changed files with 42 additions and 72 deletions
-26
View File
@@ -3,7 +3,6 @@ package api
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
@@ -468,31 +467,6 @@ func TestDashboardAPIEndpoint(t *testing.T) {
})
})
t.Run("Given a request with incorrect folder uid for creating a dashboard with", func(t *testing.T) {
cmd := dashboards.SaveDashboardCommand{
OrgID: 1,
UserID: 5,
Dashboard: simplejson.NewFromAny(map[string]any{
"title": "Dash",
}),
Overwrite: true,
FolderUID: "folderUID",
IsFolder: false,
Message: "msg",
}
dashboardService := dashboards.NewFakeDashboardService(t)
mockFolder := &foldertest.FakeService{
ExpectedError: errors.New("Error while searching Folder ID"),
}
postDashboardScenario(t, "When calling POST on", "/api/dashboards", "/api/dashboards", cmd, dashboardService, mockFolder, func(sc *scenarioContext) {
callPostDashboard(sc)
assert.Equal(t, http.StatusInternalServerError, sc.resp.Code)
})
})
// This tests that invalid requests returns expected error responses
t.Run("Given incorrect requests for creating a dashboard", func(t *testing.T) {
testCases := []struct {