mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove Result from dashboard models (#61997)
* Chore: Remove Result from dashboard models * Fix lint tests * Fix dashboard service tests * Fix API tests * Remove commented out code * Chore: Merge main - cleanup
This commit is contained in:
@@ -51,7 +51,7 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response {
|
||||
// When dashboard UID present in the request, we ignore dashboard ID
|
||||
if query.DashboardUid != "" {
|
||||
dq := dashboards.GetDashboardQuery{UID: query.DashboardUid, OrgID: c.OrgID}
|
||||
err := hs.DashboardService.GetDashboard(c.Req.Context(), &dq)
|
||||
dqResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &dq)
|
||||
if err != nil {
|
||||
if hs.Features.IsEnabled(featuremgmt.FlagDashboardsFromStorage) {
|
||||
// OK... the storage UIDs do not (yet?) exist in the DashboardService
|
||||
@@ -59,7 +59,7 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response {
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard UID in annotation request", err)
|
||||
}
|
||||
} else {
|
||||
query.DashboardId = dq.Result.ID
|
||||
query.DashboardId = dqResult.ID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,10 +80,10 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response {
|
||||
item.DashboardUID = val
|
||||
} else {
|
||||
query := dashboards.GetDashboardQuery{ID: item.DashboardId, OrgID: c.OrgID}
|
||||
err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
if err == nil && query.Result != nil {
|
||||
item.DashboardUID = &query.Result.UID
|
||||
dashboardCache[item.DashboardId] = &query.Result.UID
|
||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
if err == nil && queryResult != nil {
|
||||
item.DashboardUID = &queryResult.UID
|
||||
dashboardCache[item.DashboardId] = &queryResult.UID
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,9 +123,9 @@ func (hs *HTTPServer) PostAnnotation(c *models.ReqContext) response.Response {
|
||||
// overwrite dashboardId when dashboardUID is not empty
|
||||
if cmd.DashboardUID != "" {
|
||||
query := dashboards.GetDashboardQuery{OrgID: c.OrgID, UID: cmd.DashboardUID}
|
||||
err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
if err == nil {
|
||||
cmd.DashboardId = query.Result.ID
|
||||
cmd.DashboardId = queryResult.ID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,9 +380,9 @@ func (hs *HTTPServer) MassDeleteAnnotations(c *models.ReqContext) response.Respo
|
||||
|
||||
if cmd.DashboardUID != "" {
|
||||
query := dashboards.GetDashboardQuery{OrgID: c.OrgID, UID: cmd.DashboardUID}
|
||||
err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
if err == nil {
|
||||
cmd.DashboardId = query.Result.ID
|
||||
cmd.DashboardId = queryResult.ID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -227,13 +227,8 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
|
||||
|
||||
t.Run("Should be able to do anything", func(t *testing.T) {
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil)
|
||||
result := &dashboards.Dashboard{}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(result, nil)
|
||||
postAnnotationScenario(t, "When calling POST on", "/api/annotations", "/api/annotations", role, cmd, store, dashSvc, func(sc *scenarioContext) {
|
||||
setUpACL()
|
||||
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
|
||||
@@ -244,6 +239,7 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
|
||||
setUpACL()
|
||||
sc.fakeReqWithParams("POST", sc.url, map[string]string{}).exec()
|
||||
assert.Equal(t, 200, sc.resp.Code)
|
||||
|
||||
dashSvc.AssertCalled(t, "GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery"))
|
||||
})
|
||||
|
||||
@@ -267,13 +263,17 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
dashSvc = dashboards.NewFakeDashboardService(t)
|
||||
result = &dashboards.Dashboard{
|
||||
ID: 1,
|
||||
UID: deleteWithDashboardUIDCmd.DashboardUID,
|
||||
}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
ID: 1,
|
||||
result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: deleteWithDashboardUIDCmd.DashboardUID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(result, nil)
|
||||
deleteAnnotationsScenario(t, "When calling POST with dashboardUID on", "/api/annotations/mass-delete",
|
||||
"/api/annotations/mass-delete", role, deleteWithDashboardUIDCmd, mockStore, dashSvc, func(sc *scenarioContext) {
|
||||
setUpACL()
|
||||
@@ -287,13 +287,15 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
|
||||
}
|
||||
|
||||
func postAnnotationScenario(t *testing.T, desc string, url string, routePattern string, role org.RoleType,
|
||||
cmd dtos.PostAnnotationsCmd, store db.DB, dashSvc dashboards.DashboardService, fn scenarioFunc) {
|
||||
cmd dtos.PostAnnotationsCmd, store db.DB, dashSvc *dashboards.FakeDashboardService, fn scenarioFunc) {
|
||||
t.Run(fmt.Sprintf("%s %s", desc, url), func(t *testing.T) {
|
||||
hs := setupSimpleHTTPServer(nil)
|
||||
hs.SQLStore = store
|
||||
hs.DashboardService = dashSvc
|
||||
|
||||
sc := setupScenarioContext(t, url)
|
||||
sc.dashboardService = dashSvc
|
||||
|
||||
sc.defaultHandler = routing.Wrap(func(c *models.ReqContext) response.Response {
|
||||
c.Req.Body = mockRequestBody(cmd)
|
||||
c.Req.Header.Add("Content-Type", "application/json")
|
||||
@@ -301,12 +303,10 @@ func postAnnotationScenario(t *testing.T, desc string, url string, routePattern
|
||||
sc.context.UserID = testUserID
|
||||
sc.context.OrgID = testOrgID
|
||||
sc.context.OrgRole = role
|
||||
|
||||
return hs.PostAnnotation(c)
|
||||
})
|
||||
|
||||
sc.m.Post(routePattern, sc.defaultHandler)
|
||||
|
||||
fn(sc)
|
||||
})
|
||||
}
|
||||
@@ -680,20 +680,22 @@ func setUpACL() {
|
||||
store := dbtest.NewFakeDB()
|
||||
teamSvc := &teamtest.FakeService{}
|
||||
dashSvc := &dashboards.FakeDashboardService{}
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
}).Return(nil)
|
||||
// q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
|
||||
}).Return(qResult, nil)
|
||||
var result *dashboards.Dashboard
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(result, nil)
|
||||
|
||||
guardian.InitLegacyGuardian(store, dashSvc, teamSvc)
|
||||
}
|
||||
|
||||
@@ -188,6 +188,7 @@ type scenarioContext struct {
|
||||
authInfoService *logintest.AuthInfoServiceFake
|
||||
dashboardVersionService dashver.Service
|
||||
userService user.Service
|
||||
dashboardService dashboards.DashboardService
|
||||
}
|
||||
|
||||
func (sc *scenarioContext) exec() {
|
||||
@@ -538,10 +539,8 @@ func setUp(confs ...setUpConf) *HTTPServer {
|
||||
}
|
||||
teamSvc := &teamtest.FakeService{}
|
||||
dashSvc := &dashboards.FakeDashboardService{}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = aclMockResp
|
||||
}).Return(nil)
|
||||
qResult := aclMockResp
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
guardian.InitLegacyGuardian(store, dashSvc, teamSvc)
|
||||
return hs
|
||||
}
|
||||
|
||||
@@ -190,15 +190,16 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
|
||||
// lookup folder title
|
||||
if dash.FolderID > 0 {
|
||||
query := dashboards.GetDashboardQuery{ID: dash.FolderID, OrgID: c.OrgID}
|
||||
if err := hs.DashboardService.GetDashboard(c.Req.Context(), &query); err != nil {
|
||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
if errors.Is(err, dashboards.ErrFolderNotFound) {
|
||||
return response.Error(404, "Folder not found", err)
|
||||
}
|
||||
return response.Error(500, "Dashboard folder could not be read", err)
|
||||
}
|
||||
meta.FolderUid = query.Result.UID
|
||||
meta.FolderTitle = query.Result.Title
|
||||
meta.FolderUrl = query.Result.GetURL()
|
||||
meta.FolderUid = queryResult.UID
|
||||
meta.FolderTitle = queryResult.Title
|
||||
meta.FolderUrl = queryResult.GetURL()
|
||||
}
|
||||
|
||||
provisioningData, err := hs.dashboardProvisioningService.GetProvisionedDashboardDataByDashboardID(c.Req.Context(), dash.ID)
|
||||
@@ -281,11 +282,12 @@ func (hs *HTTPServer) getDashboardHelper(ctx context.Context, orgID int64, id in
|
||||
query = dashboards.GetDashboardQuery{ID: id, OrgID: orgID}
|
||||
}
|
||||
|
||||
if err := hs.DashboardService.GetDashboard(ctx, &query); err != nil {
|
||||
queryResult, err := hs.DashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
return nil, response.Error(404, "Dashboard not found", err)
|
||||
}
|
||||
|
||||
return query.Result, nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
// DeleteDashboardByUID swagger:route DELETE /dashboards/uid/{uid} dashboards deleteDashboardByUID
|
||||
@@ -531,9 +533,9 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
|
||||
|
||||
if preference.HomeDashboardID != 0 {
|
||||
slugQuery := dashboards.GetDashboardRefByIDQuery{ID: preference.HomeDashboardID}
|
||||
err := hs.DashboardService.GetDashboardUIDByID(c.Req.Context(), &slugQuery)
|
||||
slugQueryResult, err := hs.DashboardService.GetDashboardUIDByID(c.Req.Context(), &slugQuery)
|
||||
if err == nil {
|
||||
url := dashboards.GetDashboardURL(slugQuery.Result.UID, slugQuery.Result.Slug)
|
||||
url := dashboards.GetDashboardURL(slugQueryResult.UID, slugQueryResult.Slug)
|
||||
dashRedirect := dtos.DashboardRedirect{RedirectUri: url}
|
||||
return response.JSON(http.StatusOK, &dashRedirect)
|
||||
}
|
||||
@@ -1016,13 +1018,13 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext) response.Res
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetDashboardTags(c *models.ReqContext) {
|
||||
query := dashboards.GetDashboardTagsQuery{OrgID: c.OrgID}
|
||||
err := hs.DashboardService.GetDashboardTags(c.Req.Context(), &query)
|
||||
queryResult, err := hs.DashboardService.GetDashboardTags(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to get tags from database", err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, query.Result)
|
||||
c.JSON(http.StatusOK, queryResult)
|
||||
}
|
||||
|
||||
// GetDashboardUIDs converts internal ids to UIDs
|
||||
@@ -1037,11 +1039,11 @@ func (hs *HTTPServer) GetDashboardUIDs(c *models.ReqContext) {
|
||||
continue
|
||||
}
|
||||
q.ID = id
|
||||
err = hs.DashboardService.GetDashboardUIDByID(c.Req.Context(), q)
|
||||
qResult, err := hs.DashboardService.GetDashboardUIDByID(c.Req.Context(), q)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
uids = append(uids, q.Result.UID)
|
||||
uids = append(uids, qResult.UID)
|
||||
}
|
||||
c.JSON(http.StatusOK, uids)
|
||||
}
|
||||
|
||||
@@ -27,13 +27,8 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
t.Run("Dashboard permissions test", func(t *testing.T) {
|
||||
settings := setting.NewCfg()
|
||||
dashboardStore := &dashboards.FakeDashboardStore{}
|
||||
dashboardStore.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil, nil)
|
||||
qResult := &dashboards.Dashboard{}
|
||||
dashboardStore.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
defer dashboardStore.AssertExpectations(t)
|
||||
|
||||
features := featuremgmt.WithFeatures()
|
||||
|
||||
@@ -72,14 +72,15 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
|
||||
teamSvc := &teamtest.FakeService{}
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
var qResult *dashboards.Dashboard
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
qResult = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil).Maybe()
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil).Maybe()
|
||||
}).Return(qResult, nil).Maybe()
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil, nil).Maybe()
|
||||
hs.DashboardService = dashSvc
|
||||
|
||||
guardian.InitLegacyGuardian(sc.sqlStore, dashSvc, teamSvc)
|
||||
@@ -118,13 +119,11 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
t.Run("When user is editor and dashboard has default ACL", func(t *testing.T) {
|
||||
teamSvc := &teamtest.FakeService{}
|
||||
dashSvc := &dashboards.FakeDashboardService{}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
|
||||
loggedInUserScenarioWithRole(t, "Should be able to delete a snapshot when calling DELETE on", "DELETE",
|
||||
"/api/snapshots/12345", "/api/snapshots/:key", org.RoleEditor, func(sc *scenarioContext) {
|
||||
@@ -134,20 +133,13 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
externalRequest = req
|
||||
})
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
OrgID: q.OrgID,
|
||||
}
|
||||
}).Return(nil).Maybe()
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := &dashboards.Dashboard{}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil).Maybe()
|
||||
qResultACL := []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResultACL, nil)
|
||||
guardian.InitLegacyGuardian(sc.sqlStore, dashSvc, teamSvc)
|
||||
hs := &HTTPServer{dashboardsnapshotsService: setUpSnapshotTest(t, 0, ts.URL), DashboardService: dashSvc}
|
||||
sc.handlerFunc = hs.DeleteDashboardSnapshot
|
||||
|
||||
@@ -137,10 +137,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDashboardVersionService.ExpectedDashboardVersion = &dashver.DashboardVersionDTO{}
|
||||
teamService := &teamtest.FakeService{}
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = fakeDash
|
||||
}).Return(nil)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(fakeDash, nil)
|
||||
mockSQLStore := dbtest.NewFakeDB()
|
||||
|
||||
hs := &HTTPServer{
|
||||
@@ -158,13 +155,11 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
setUp := func() {
|
||||
viewerRole := org.RoleViewer
|
||||
editorRole := org.RoleEditor
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{Role: &viewerRole, Permission: models.PERMISSION_VIEW},
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
guardian.InitLegacyGuardian(mockSQLStore, dashboardService, teamService)
|
||||
}
|
||||
|
||||
@@ -245,20 +240,16 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDashboardVersionService.ExpectedDashboardVersion = &dashver.DashboardVersionDTO{}
|
||||
teamService := &teamtest.FakeService{}
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = fakeDash
|
||||
}).Return(nil)
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{
|
||||
DashboardID: 1,
|
||||
Permission: models.PERMISSION_EDIT,
|
||||
UserID: 200,
|
||||
},
|
||||
}
|
||||
}).Return(nil)
|
||||
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(fakeDash, nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{
|
||||
DashboardID: 1,
|
||||
Permission: models.PERMISSION_EDIT,
|
||||
UserID: 200,
|
||||
},
|
||||
}
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
|
||||
mockSQLStore := dbtest.NewFakeDB()
|
||||
cfg := setting.NewCfg()
|
||||
@@ -381,12 +372,10 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
setting.ViewersCanEdit = false
|
||||
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
guardian.InitLegacyGuardian(mockSQLStore, dashboardService, teamService)
|
||||
}
|
||||
|
||||
@@ -404,10 +393,8 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
loggedInUserScenarioWithRole(t, "When calling DELETE on", "DELETE", "/api/dashboards/uid/abcdefghi", "/api/dashboards/uid/:uid", role, func(sc *scenarioContext) {
|
||||
setUpInner()
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = dashboards.NewDashboard("test")
|
||||
}).Return(nil)
|
||||
qResult := dashboards.NewDashboard("test")
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
dashboardService.On("DeleteDashboard", mock.Anything, mock.AnythingOfType("int64"), mock.AnythingOfType("int64")).Return(nil)
|
||||
|
||||
hs.callDeleteDashboardByUID(t, sc, dashboardService)
|
||||
@@ -443,12 +430,10 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
setting.ViewersCanEdit = true
|
||||
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
guardian.InitLegacyGuardian(mockSQLStore, dashboardService, teamService)
|
||||
}
|
||||
|
||||
@@ -483,12 +468,10 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
setting.ViewersCanEdit = true
|
||||
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_ADMIN},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_ADMIN},
|
||||
}
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
guardian.InitLegacyGuardian(mockSQLStore, dashboardService, teamService)
|
||||
}
|
||||
|
||||
@@ -506,10 +489,8 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
setUpInner()
|
||||
sc.sqlStore = mockSQLStore
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = dashboards.NewDashboard("test")
|
||||
}).Return(nil)
|
||||
qResult := dashboards.NewDashboard("test")
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
dashboardService.On("DeleteDashboard", mock.Anything, mock.AnythingOfType("int64"), mock.AnythingOfType("int64")).Return(nil)
|
||||
hs.callDeleteDashboardByUID(t, sc, dashboardService)
|
||||
|
||||
@@ -536,12 +517,10 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUpInner := func() {
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{OrgID: 1, DashboardID: 2, UserID: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
guardian.InitLegacyGuardian(mockSQLStore, dashboardService, teamService)
|
||||
}
|
||||
|
||||
@@ -808,14 +787,9 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
setUp := func() {
|
||||
teamSvc := &teamtest.FakeService{}
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil)
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
OrgID: q.OrgID,
|
||||
ID: q.ID,
|
||||
}
|
||||
}).Return(nil)
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil, nil)
|
||||
qResult := &dashboards.Dashboard{}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
guardian.InitLegacyGuardian(sqlmock, dashSvc, teamSvc)
|
||||
}
|
||||
|
||||
@@ -860,10 +834,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDash.HasACL = false
|
||||
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = fakeDash
|
||||
}).Return(nil)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(fakeDash, nil)
|
||||
dashboardService.On("SaveDashboard", mock.Anything, mock.AnythingOfType("*dashboards.SaveDashboardDTO"), mock.AnythingOfType("bool")).Run(func(args mock.Arguments) {
|
||||
cmd := args.Get(1).(*dashboards.SaveDashboardDTO)
|
||||
cmd.Dashboard = &dashboards.Dashboard{
|
||||
@@ -897,10 +868,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDash.HasACL = false
|
||||
|
||||
dashboardService := dashboards.NewFakeDashboardService(t)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = fakeDash
|
||||
}).Return(nil)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(fakeDash, nil)
|
||||
dashboardService.On("SaveDashboard", mock.Anything, mock.AnythingOfType("*dashboards.SaveDashboardDTO"), mock.AnythingOfType("bool")).Run(func(args mock.Arguments) {
|
||||
cmd := args.Get(1).(*dashboards.SaveDashboardDTO)
|
||||
cmd.Dashboard = &dashboards.Dashboard{
|
||||
@@ -937,14 +905,10 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
dataValue, err := simplejson.NewJson([]byte(`{"id": 1, "editable": true, "style": "dark"}`))
|
||||
require.NoError(t, err)
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{ID: 1, Data: dataValue}
|
||||
}).Return(nil)
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{{OrgID: testOrgID, DashboardID: 1, UserID: testUserID, Permission: models.PERMISSION_EDIT}}
|
||||
}).Return(nil)
|
||||
qResult := &dashboards.Dashboard{ID: 1, Data: dataValue}
|
||||
dashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
qResult2 := []*dashboards.DashboardACLInfoDTO{{OrgID: testOrgID, DashboardID: 1, UserID: testUserID, Permission: models.PERMISSION_EDIT}}
|
||||
dashboardService.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult2, nil)
|
||||
guardian.InitLegacyGuardian(mockSQLStore, dashboardService, teamService)
|
||||
|
||||
loggedInUserScenarioWithRole(t, "When calling GET on", "GET", "/api/dashboards/uid/dash", "/api/dashboards/uid/:uid", org.RoleEditor, func(sc *scenarioContext) {
|
||||
|
||||
@@ -241,17 +241,10 @@ func createFolderScenario(t *testing.T, desc string, url string, routePattern st
|
||||
aclMockResp := []*dashboards.DashboardACLInfoDTO{}
|
||||
teamSvc := &teamtest.FakeService{}
|
||||
dashSvc := &dashboards.FakeDashboardService{}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = aclMockResp
|
||||
}).Return(nil)
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult1 := aclMockResp
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult1, nil)
|
||||
qResult := &dashboards.Dashboard{}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
store := dbtest.NewFakeDB()
|
||||
guardian.InitLegacyGuardian(store, dashSvc, teamSvc)
|
||||
hs := HTTPServer{
|
||||
|
||||
@@ -19,11 +19,12 @@ func (hs *HTTPServer) populateDashboardsByID(ctx context.Context, dashboardByIDs
|
||||
|
||||
if len(dashboardByIDs) > 0 {
|
||||
dashboardQuery := dashboards.GetDashboardsQuery{DashboardIDs: dashboardByIDs}
|
||||
if err := hs.DashboardService.GetDashboards(ctx, &dashboardQuery); err != nil {
|
||||
dashboardQueryResult, err := hs.DashboardService.GetDashboards(ctx, &dashboardQuery)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
for _, item := range dashboardQuery.Result {
|
||||
for _, item := range dashboardQueryResult {
|
||||
result = append(result, dtos.PlaylistDashboard{
|
||||
Id: item.ID,
|
||||
Slug: item.Slug,
|
||||
|
||||
@@ -35,11 +35,11 @@ func (hs *HTTPServer) SetHomeDashboard(c *models.ReqContext) response.Response {
|
||||
if query.UID == "" {
|
||||
dashboardID = 0 // clear the value
|
||||
} else {
|
||||
err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
return response.Error(404, "Dashboard not found", err)
|
||||
}
|
||||
dashboardID = query.Result.ID
|
||||
dashboardID = queryResult.ID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,9 +77,9 @@ func (hs *HTTPServer) getPreferencesFor(ctx context.Context, orgID, userID, team
|
||||
// when homedashboardID is 0, that means it is the default home dashboard, no UID would be returned in the response
|
||||
if preference.HomeDashboardID != 0 {
|
||||
query := dashboards.GetDashboardQuery{ID: preference.HomeDashboardID, OrgID: orgID}
|
||||
err = hs.DashboardService.GetDashboard(ctx, &query)
|
||||
queryResult, err := hs.DashboardService.GetDashboard(ctx, &query)
|
||||
if err == nil {
|
||||
dashboardUID = query.Result.UID
|
||||
dashboardUID = queryResult.UID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,11 +136,11 @@ func (hs *HTTPServer) updatePreferencesFor(ctx context.Context, orgID, userID, t
|
||||
// clear the value
|
||||
dashboardID = 0
|
||||
} else {
|
||||
err := hs.DashboardService.GetDashboard(ctx, &query)
|
||||
queryResult, err := hs.DashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
return response.Error(404, "Dashboard not found", err)
|
||||
}
|
||||
dashboardID = query.Result.ID
|
||||
dashboardID = queryResult.ID
|
||||
}
|
||||
}
|
||||
dtoCmd.HomeDashboardID = dashboardID
|
||||
@@ -196,11 +196,11 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
|
||||
defaultDash := int64(0)
|
||||
dashboardID = &defaultDash
|
||||
} else {
|
||||
err := hs.DashboardService.GetDashboard(ctx, &query)
|
||||
queryResult, err := hs.DashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
return response.Error(404, "Dashboard not found", err)
|
||||
}
|
||||
dashboardID = &query.Result.ID
|
||||
dashboardID = &queryResult.ID
|
||||
}
|
||||
}
|
||||
dtoCmd.HomeDashboardID = dashboardID
|
||||
|
||||
@@ -39,10 +39,8 @@ func TestAPIEndpoint_GetCurrentOrgPreferences_LegacyAccessControl(t *testing.T)
|
||||
cfg := setting.NewCfg()
|
||||
cfg.RBACEnabled = false
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{UID: "home", ID: 1}
|
||||
}).Return(nil)
|
||||
qResult := &dashboards.Dashboard{UID: "home", ID: 1}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
|
||||
prefService := preftest.NewPreferenceServiceFake()
|
||||
prefService.ExpectedPreference = &pref.Preference{HomeDashboardID: 1, Theme: "dark"}
|
||||
@@ -80,10 +78,8 @@ func TestAPIEndpoint_GetCurrentOrgPreferences_AccessControl(t *testing.T) {
|
||||
prefService.ExpectedPreference = &pref.Preference{HomeDashboardID: 1, Theme: "dark"}
|
||||
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{UID: "home", ID: 1}
|
||||
}).Return(nil)
|
||||
qResult := &dashboards.Dashboard{UID: "home", ID: 1}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
|
||||
server := SetupAPITestServer(t, func(hs *HTTPServer) {
|
||||
hs.Cfg = setting.NewCfg()
|
||||
@@ -196,10 +192,8 @@ func TestAPIEndpoint_PatchUserPreferences(t *testing.T) {
|
||||
cfg.RBACEnabled = false
|
||||
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{UID: "home", ID: 1}
|
||||
}).Return(nil)
|
||||
qResult := &dashboards.Dashboard{UID: "home", ID: 1}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
|
||||
server := SetupAPITestServer(t, func(hs *HTTPServer) {
|
||||
hs.Cfg = cfg
|
||||
|
||||
@@ -27,11 +27,11 @@ func (hs *HTTPServer) GetStars(c *models.ReqContext) response.Response {
|
||||
ID: dashboardId,
|
||||
OrgID: c.OrgID,
|
||||
}
|
||||
err := hs.DashboardService.GetDashboard(c.Req.Context(), query)
|
||||
queryResult, err := hs.DashboardService.GetDashboard(c.Req.Context(), query)
|
||||
|
||||
// Grafana admin users may have starred dashboards in multiple orgs. This will avoid returning errors when the dashboard is in another org
|
||||
if err == nil {
|
||||
uids = append(uids, query.Result.UID)
|
||||
uids = append(uids, queryResult.UID)
|
||||
}
|
||||
}
|
||||
return response.JSON(200, uids)
|
||||
|
||||
@@ -120,10 +120,11 @@ func ProvideDashboardPermissions(
|
||||
) (*DashboardPermissionsService, error) {
|
||||
getDashboard := func(ctx context.Context, orgID int64, resourceID string) (*dashboards.Dashboard, error) {
|
||||
query := &dashboards.GetDashboardQuery{UID: resourceID, OrgID: orgID}
|
||||
if _, err := dashboardStore.GetDashboard(ctx, query); err != nil {
|
||||
queryResult, err := dashboardStore.GetDashboard(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return query.Result, nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
options := resourcepermissions.Options{
|
||||
@@ -148,10 +149,11 @@ func ProvideDashboardPermissions(
|
||||
}
|
||||
if dashboard.FolderID > 0 {
|
||||
query := &dashboards.GetDashboardQuery{ID: dashboard.FolderID, OrgID: orgID}
|
||||
if _, err := dashboardStore.GetDashboard(ctx, query); err != nil {
|
||||
queryResult, err := dashboardStore.GetDashboard(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []string{dashboards.ScopeFoldersProvider.GetResourceScopeUID(query.Result.UID)}, nil
|
||||
return []string{dashboards.ScopeFoldersProvider.GetResourceScopeUID(queryResult.UID)}, nil
|
||||
}
|
||||
return []string{}, nil
|
||||
},
|
||||
@@ -202,11 +204,12 @@ func ProvideFolderPermissions(
|
||||
ResourceAttribute: "uid",
|
||||
ResourceValidator: func(ctx context.Context, orgID int64, resourceID string) error {
|
||||
query := &dashboards.GetDashboardQuery{UID: resourceID, OrgID: orgID}
|
||||
if _, err := dashboardStore.GetDashboard(ctx, query); err != nil {
|
||||
queryResult, err := dashboardStore.GetDashboard(ctx, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !query.Result.IsFolder {
|
||||
if !queryResult.IsFolder {
|
||||
return errors.New("not found")
|
||||
}
|
||||
|
||||
|
||||
@@ -123,11 +123,12 @@ func (c *EvalContext) GetDashboardUID() (*dashboards.DashboardRef, error) {
|
||||
}
|
||||
|
||||
uidQuery := &dashboards.GetDashboardRefByIDQuery{ID: c.Rule.DashboardID}
|
||||
if err := c.dashboardService.GetDashboardUIDByID(c.Ctx, uidQuery); err != nil {
|
||||
uidQueryResult, err := c.dashboardService.GetDashboardUIDByID(c.Ctx, uidQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.dashboardRef = uidQuery.Result
|
||||
c.dashboardRef = uidQueryResult
|
||||
return c.dashboardRef, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -30,18 +30,20 @@ func NewPermissionChecker(sqlStore db.DB, features featuremgmt.FeatureToggles,
|
||||
|
||||
func (c *PermissionChecker) getDashboardByUid(ctx context.Context, orgID int64, uid string) (*dashboards.Dashboard, error) {
|
||||
query := dashboards.GetDashboardQuery{UID: uid, OrgID: orgID}
|
||||
if err := c.dashboardService.GetDashboard(ctx, &query); err != nil {
|
||||
queryResult, err := c.dashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return query.Result, nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
func (c *PermissionChecker) getDashboardById(ctx context.Context, orgID int64, id int64) (*dashboards.Dashboard, error) {
|
||||
query := dashboards.GetDashboardQuery{ID: id, OrgID: orgID}
|
||||
if err := c.dashboardService.GetDashboard(ctx, &query); err != nil {
|
||||
queryResult, err := c.dashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return query.Result, nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
func (c *PermissionChecker) CheckReadPermissions(ctx context.Context, orgId int64, signedInUser *user.SignedInUser, objectType string, objectID string) (bool, error) {
|
||||
|
||||
@@ -16,11 +16,11 @@ type DashboardService interface {
|
||||
BuildSaveDashboardCommand(ctx context.Context, dto *SaveDashboardDTO, shouldValidateAlerts bool, validateProvisionedDashboard bool) (*SaveDashboardCommand, error)
|
||||
DeleteDashboard(ctx context.Context, dashboardId int64, orgId int64) error
|
||||
FindDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error)
|
||||
GetDashboard(ctx context.Context, query *GetDashboardQuery) error
|
||||
GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) error
|
||||
GetDashboards(ctx context.Context, query *GetDashboardsQuery) error
|
||||
GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error
|
||||
GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) error
|
||||
GetDashboard(ctx context.Context, query *GetDashboardQuery) (*Dashboard, error)
|
||||
GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) ([]*DashboardACLInfoDTO, error)
|
||||
GetDashboards(ctx context.Context, query *GetDashboardsQuery) ([]*Dashboard, error)
|
||||
GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) ([]*DashboardTagCloudItem, error)
|
||||
GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) (*DashboardRef, error)
|
||||
HasAdminPermissionInDashboardsOrFolders(ctx context.Context, query *folder.HasAdminPermissionInDashboardsOrFoldersQuery) (bool, error)
|
||||
HasEditPermissionInFolders(ctx context.Context, query *folder.HasEditPermissionInFoldersQuery) (bool, error)
|
||||
ImportDashboard(ctx context.Context, dto *SaveDashboardDTO) (*Dashboard, error)
|
||||
@@ -34,7 +34,7 @@ type DashboardService interface {
|
||||
|
||||
// PluginService is a service for operating on plugin dashboards.
|
||||
type PluginService interface {
|
||||
GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) error
|
||||
GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) ([]*Dashboard, error)
|
||||
}
|
||||
|
||||
// DashboardProvisioningService is a service for operating on provisioned dashboards.
|
||||
@@ -59,12 +59,12 @@ type Store interface {
|
||||
DeleteOrphanedProvisionedDashboards(ctx context.Context, cmd *DeleteOrphanedProvisionedDashboardsCommand) error
|
||||
FindDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) ([]DashboardSearchProjection, error)
|
||||
GetDashboard(ctx context.Context, query *GetDashboardQuery) (*Dashboard, error)
|
||||
GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) error
|
||||
GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) error
|
||||
GetDashboards(ctx context.Context, query *GetDashboardsQuery) error
|
||||
GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) ([]*DashboardACLInfoDTO, error)
|
||||
GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) (*DashboardRef, error)
|
||||
GetDashboards(ctx context.Context, query *GetDashboardsQuery) ([]*Dashboard, error)
|
||||
// GetDashboardsByPluginID retrieves dashboards identified by plugin.
|
||||
GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) error
|
||||
GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error
|
||||
GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) ([]*Dashboard, error)
|
||||
GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) ([]*DashboardTagCloudItem, error)
|
||||
GetProvisionedDashboardData(ctx context.Context, name string) ([]*DashboardProvisioning, error)
|
||||
GetProvisionedDataByDashboardID(ctx context.Context, dashboardID int64) (*DashboardProvisioning, error)
|
||||
GetProvisionedDataByDashboardUID(ctx context.Context, orgID int64, dashboardUID string) (*DashboardProvisioning, error)
|
||||
|
||||
@@ -112,73 +112,118 @@ func (_m *FakeDashboardService) FindDashboards(ctx context.Context, query *model
|
||||
}
|
||||
|
||||
// GetDashboard provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardService) GetDashboard(ctx context.Context, query *GetDashboardQuery) error {
|
||||
func (_m *FakeDashboardService) GetDashboard(ctx context.Context, query *GetDashboardQuery) (*Dashboard, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardQuery) error); ok {
|
||||
var r0 *Dashboard
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardQuery) *Dashboard); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*Dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboardACLInfoList provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardService) GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) error {
|
||||
func (_m *FakeDashboardService) GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) ([]*DashboardACLInfoDTO, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardACLInfoListQuery) error); ok {
|
||||
var r0 []*DashboardACLInfoDTO
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardACLInfoListQuery) []*DashboardACLInfoDTO); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*DashboardACLInfoDTO)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardACLInfoListQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboardTags provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardService) GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error {
|
||||
func (_m *FakeDashboardService) GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) ([]*DashboardTagCloudItem, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardTagsQuery) error); ok {
|
||||
var r0 []*DashboardTagCloudItem
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardTagsQuery) []*DashboardTagCloudItem); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*DashboardTagCloudItem)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardTagsQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboardUIDByID provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardService) GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) error {
|
||||
func (_m *FakeDashboardService) GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) (*DashboardRef, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardRefByIDQuery) error); ok {
|
||||
var r0 *DashboardRef
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardRefByIDQuery) *DashboardRef); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*DashboardRef)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardRefByIDQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboards provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardService) GetDashboards(ctx context.Context, query *GetDashboardsQuery) error {
|
||||
func (_m *FakeDashboardService) GetDashboards(ctx context.Context, query *GetDashboardsQuery) ([]*Dashboard, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardsQuery) error); ok {
|
||||
var r0 []*Dashboard
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardsQuery) []*Dashboard); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*Dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardsQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// HasAdminPermissionInDashboardsOrFolders provides a mock function with given fields: ctx, query
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
// 1) Permissions for the dashboard
|
||||
// 2) permissions for its parent folder
|
||||
// 3) if no specific permissions have been set for the dashboard or its parent folder then get the default permissions
|
||||
func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *dashboards.GetDashboardACLInfoListQuery) error {
|
||||
func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *dashboards.GetDashboardACLInfoListQuery) ([]*dashboards.DashboardACLInfoDTO, error) {
|
||||
queryResult := make([]*dashboards.DashboardACLInfoDTO, 0)
|
||||
outerErr := d.store.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
query.Result = make([]*dashboards.DashboardACLInfoDTO, 0)
|
||||
falseStr := d.store.GetDialect().BooleanStr(false)
|
||||
|
||||
if query.DashboardID == 0 {
|
||||
@@ -41,7 +41,7 @@ func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *das
|
||||
falseStr + ` AS inherited
|
||||
FROM dashboard_acl as da
|
||||
WHERE da.dashboard_id = -1`
|
||||
return dbSession.SQL(sql).Find(&query.Result)
|
||||
return dbSession.SQL(sql).Find(&queryResult)
|
||||
}
|
||||
|
||||
rawSQL := `
|
||||
@@ -83,18 +83,18 @@ func (d *DashboardStore) GetDashboardACLInfoList(ctx context.Context, query *das
|
||||
ORDER BY da.id ASC
|
||||
`
|
||||
|
||||
return dbSession.SQL(rawSQL, query.OrgID, query.DashboardID).Find(&query.Result)
|
||||
return dbSession.SQL(rawSQL, query.OrgID, query.DashboardID).Find(&queryResult)
|
||||
})
|
||||
|
||||
if outerErr != nil {
|
||||
return outerErr
|
||||
return nil, outerErr
|
||||
}
|
||||
|
||||
for _, p := range query.Result {
|
||||
for _, p := range queryResult {
|
||||
p.PermissionName = p.Permission.String()
|
||||
}
|
||||
|
||||
return nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
// HasEditPermissionInFolders validates that an user have access to a certain folder
|
||||
|
||||
@@ -54,34 +54,34 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
setup(t)
|
||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
||||
|
||||
err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
require.Equal(t, 2, len(queryResult))
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.False(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.False(t, query.Result[1].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, queryResult[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *queryResult[0].Role)
|
||||
require.False(t, queryResult[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, queryResult[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *queryResult[1].Role)
|
||||
require.False(t, queryResult[1].Inherited)
|
||||
})
|
||||
|
||||
t.Run("Dashboard acl should include acl for parent folder", func(t *testing.T) {
|
||||
setup(t)
|
||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: 1}
|
||||
|
||||
err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
require.Equal(t, 2, len(queryResult))
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.True(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.True(t, query.Result[1].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, queryResult[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *queryResult[0].Role)
|
||||
require.True(t, queryResult[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, queryResult[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *queryResult[1].Role)
|
||||
require.True(t, queryResult[1].Inherited)
|
||||
})
|
||||
|
||||
t.Run("Folder with removed default permissions returns no acl items", func(t *testing.T) {
|
||||
@@ -90,10 +90,10 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: 1}
|
||||
err = dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 0, len(query.Result))
|
||||
require.Equal(t, 0, len(queryResult))
|
||||
})
|
||||
|
||||
t.Run("Given a dashboard folder and a user", func(t *testing.T) {
|
||||
@@ -110,11 +110,11 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
t.Run("When reading dashboard acl should include acl for parent folder", func(t *testing.T) {
|
||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: childDash.ID, OrgID: 1}
|
||||
|
||||
err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 1, len(query.Result))
|
||||
require.Equal(t, savedFolder.ID, query.Result[0].DashboardID)
|
||||
require.Equal(t, 1, len(queryResult))
|
||||
require.Equal(t, savedFolder.ID, queryResult[0].DashboardID)
|
||||
})
|
||||
|
||||
t.Run("Given child dashboard permission", func(t *testing.T) {
|
||||
@@ -129,14 +129,14 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
t.Run("When reading dashboard acl should include acl for parent folder and child", func(t *testing.T) {
|
||||
query := dashboards.GetDashboardACLInfoListQuery{OrgID: 1, DashboardID: childDash.ID}
|
||||
|
||||
err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
require.Equal(t, savedFolder.ID, query.Result[0].DashboardID)
|
||||
require.True(t, query.Result[0].Inherited)
|
||||
require.Equal(t, childDash.ID, query.Result[1].DashboardID)
|
||||
require.False(t, query.Result[1].Inherited)
|
||||
require.Equal(t, 2, len(queryResult))
|
||||
require.Equal(t, savedFolder.ID, queryResult[0].DashboardID)
|
||||
require.True(t, queryResult[0].Inherited)
|
||||
require.Equal(t, childDash.ID, queryResult[1].DashboardID)
|
||||
require.False(t, queryResult[1].Inherited)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -153,19 +153,19 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
|
||||
query := dashboards.GetDashboardACLInfoListQuery{OrgID: 1, DashboardID: childDash.ID}
|
||||
|
||||
err = dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, 3, len(query.Result))
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.True(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.True(t, query.Result[1].Inherited)
|
||||
require.Equal(t, childDash.ID, query.Result[2].DashboardID)
|
||||
require.False(t, query.Result[2].Inherited)
|
||||
require.Equal(t, 3, len(queryResult))
|
||||
require.Equal(t, defaultPermissionsId, queryResult[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *queryResult[0].Role)
|
||||
require.True(t, queryResult[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, queryResult[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *queryResult[1].Role)
|
||||
require.True(t, queryResult[1].Inherited)
|
||||
require.Equal(t, childDash.ID, queryResult[2].DashboardID)
|
||||
require.False(t, queryResult[2].Inherited)
|
||||
})
|
||||
|
||||
t.Run("Add and delete dashboard permission", func(t *testing.T) {
|
||||
@@ -179,23 +179,23 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
q1 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
||||
err = dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
||||
q1Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, savedFolder.ID, q1.Result[0].DashboardID)
|
||||
require.Equal(t, models.PERMISSION_EDIT, q1.Result[0].Permission)
|
||||
require.Equal(t, "Edit", q1.Result[0].PermissionName)
|
||||
require.Equal(t, currentUser.ID, q1.Result[0].UserID)
|
||||
require.Equal(t, currentUser.Login, q1.Result[0].UserLogin)
|
||||
require.Equal(t, currentUser.Email, q1.Result[0].UserEmail)
|
||||
require.Equal(t, savedFolder.ID, q1Result[0].DashboardID)
|
||||
require.Equal(t, models.PERMISSION_EDIT, q1Result[0].Permission)
|
||||
require.Equal(t, "Edit", q1Result[0].PermissionName)
|
||||
require.Equal(t, currentUser.ID, q1Result[0].UserID)
|
||||
require.Equal(t, currentUser.Login, q1Result[0].UserLogin)
|
||||
require.Equal(t, currentUser.Email, q1Result[0].UserEmail)
|
||||
|
||||
err = updateDashboardACL(t, dashboardStore, savedFolder.ID)
|
||||
require.Nil(t, err)
|
||||
|
||||
q3 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
||||
err = dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
||||
q3Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 0, len(q3.Result))
|
||||
require.Equal(t, 0, len(q3Result))
|
||||
})
|
||||
|
||||
t.Run("Should be able to add a user permission for a team", func(t *testing.T) {
|
||||
@@ -213,11 +213,11 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
q1 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
||||
err = dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
||||
q1Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q1)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, savedFolder.ID, q1.Result[0].DashboardID)
|
||||
require.Equal(t, models.PERMISSION_EDIT, q1.Result[0].Permission)
|
||||
require.Equal(t, team1.ID, q1.Result[0].TeamID)
|
||||
require.Equal(t, savedFolder.ID, q1Result[0].DashboardID)
|
||||
require.Equal(t, models.PERMISSION_EDIT, q1Result[0].Permission)
|
||||
require.Equal(t, team1.ID, q1Result[0].TeamID)
|
||||
})
|
||||
|
||||
t.Run("Should be able to update an existing permission for a team", func(t *testing.T) {
|
||||
@@ -234,12 +234,12 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
q3 := &dashboards.GetDashboardACLInfoListQuery{DashboardID: savedFolder.ID, OrgID: 1}
|
||||
err = dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
||||
q3Result, err := dashboardStore.GetDashboardACLInfoList(context.Background(), q3)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(q3.Result))
|
||||
require.Equal(t, savedFolder.ID, q3.Result[0].DashboardID)
|
||||
require.Equal(t, models.PERMISSION_ADMIN, q3.Result[0].Permission)
|
||||
require.Equal(t, team1.ID, q3.Result[0].TeamID)
|
||||
require.Equal(t, 1, len(q3Result))
|
||||
require.Equal(t, savedFolder.ID, q3Result[0].DashboardID)
|
||||
require.Equal(t, models.PERMISSION_ADMIN, q3Result[0].Permission)
|
||||
require.Equal(t, team1.ID, q3Result[0].TeamID)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -250,17 +250,17 @@ func TestIntegrationDashboardACLDataAccess(t *testing.T) {
|
||||
|
||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: rootFolderId, OrgID: 1}
|
||||
|
||||
err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardACLInfoList(context.Background(), &query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 2, len(query.Result))
|
||||
require.Equal(t, 2, len(queryResult))
|
||||
defaultPermissionsId := int64(-1)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *query.Result[0].Role)
|
||||
require.False(t, query.Result[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, query.Result[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *query.Result[1].Role)
|
||||
require.False(t, query.Result[1].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, queryResult[0].DashboardID)
|
||||
require.Equal(t, org.RoleViewer, *queryResult[0].Role)
|
||||
require.False(t, queryResult[0].Inherited)
|
||||
require.Equal(t, defaultPermissionsId, queryResult[1].DashboardID)
|
||||
require.Equal(t, org.RoleEditor, *queryResult[1].Role)
|
||||
require.False(t, queryResult[1].Inherited)
|
||||
})
|
||||
|
||||
t.Run("Delete acl by user", func(t *testing.T) {
|
||||
|
||||
@@ -206,26 +206,37 @@ func (d *DashboardStore) GetProvisionedDashboardData(ctx context.Context, name s
|
||||
}
|
||||
|
||||
func (d *DashboardStore) SaveProvisionedDashboard(ctx context.Context, cmd dashboards.SaveDashboardCommand, provisioning *dashboards.DashboardProvisioning) (*dashboards.Dashboard, error) {
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
if err := saveDashboard(sess, &cmd, d.emitEntityEvent()); err != nil {
|
||||
var result *dashboards.Dashboard
|
||||
var err error
|
||||
err = d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
result, err = saveDashboard(sess, &cmd, d.emitEntityEvent())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if provisioning.Updated == 0 {
|
||||
provisioning.Updated = cmd.Result.Updated.Unix()
|
||||
provisioning.Updated = result.Updated.Unix()
|
||||
}
|
||||
|
||||
return saveProvisionedData(sess, provisioning, cmd.Result)
|
||||
return saveProvisionedData(sess, provisioning, result)
|
||||
})
|
||||
|
||||
return cmd.Result, err
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (d *DashboardStore) SaveDashboard(ctx context.Context, cmd dashboards.SaveDashboardCommand) (*dashboards.Dashboard, error) {
|
||||
err := d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
return saveDashboard(sess, &cmd, d.emitEntityEvent())
|
||||
var result *dashboards.Dashboard
|
||||
var err error
|
||||
err = d.store.WithTransactionalDbSession(ctx, func(sess *db.Session) error {
|
||||
result, err = saveDashboard(sess, &cmd, d.emitEntityEvent())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return cmd.Result, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (d *DashboardStore) UpdateDashboardACL(ctx context.Context, dashboardID int64, items []*dashboards.DashboardACL) error {
|
||||
@@ -476,7 +487,7 @@ func getExistingDashboardByTitleAndFolder(sess *db.Session, dash *dashboards.Das
|
||||
return isParentFolderChanged, nil
|
||||
}
|
||||
|
||||
func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitEntityEvent bool) error {
|
||||
func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitEntityEvent bool) (*dashboards.Dashboard, error) {
|
||||
dash := cmd.GetDashboardModel()
|
||||
|
||||
userId := cmd.UserID
|
||||
@@ -489,10 +500,10 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
var existing dashboards.Dashboard
|
||||
dashWithIdExists, err := sess.Where("id=? AND org_id=?", dash.ID, dash.OrgID).Get(&existing)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
if !dashWithIdExists {
|
||||
return dashboards.ErrDashboardNotFound
|
||||
return nil, dashboards.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
// check for is someone else has written in between
|
||||
@@ -500,20 +511,20 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
if cmd.Overwrite {
|
||||
dash.SetVersion(existing.Version)
|
||||
} else {
|
||||
return dashboards.ErrDashboardVersionMismatch
|
||||
return nil, dashboards.ErrDashboardVersionMismatch
|
||||
}
|
||||
}
|
||||
|
||||
// do not allow plugin dashboard updates without overwrite flag
|
||||
if existing.PluginID != "" && !cmd.Overwrite {
|
||||
return dashboards.UpdatePluginDashboardError{PluginId: existing.PluginID}
|
||||
return nil, dashboards.UpdatePluginDashboardError{PluginId: existing.PluginID}
|
||||
}
|
||||
}
|
||||
|
||||
if dash.UID == "" {
|
||||
uid, err := generateNewDashboardUid(sess, dash.OrgID)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
dash.SetUID(uid)
|
||||
}
|
||||
@@ -545,11 +556,11 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if affectedRows == 0 {
|
||||
return dashboards.ErrDashboardNotFound
|
||||
return nil, dashboards.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
dashVersion := &dashver.DashboardVersion{
|
||||
@@ -565,14 +576,14 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
|
||||
// insert version entry
|
||||
if affectedRows, err = sess.Insert(dashVersion); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
} else if affectedRows == 0 {
|
||||
return dashboards.ErrDashboardNotFound
|
||||
return nil, dashboards.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
// delete existing tags
|
||||
if _, err = sess.Exec("DELETE FROM dashboard_tag WHERE dashboard_id=?", dash.ID); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// insert new tags
|
||||
@@ -580,20 +591,18 @@ func saveDashboard(sess *db.Session, cmd *dashboards.SaveDashboardCommand, emitE
|
||||
if len(tags) > 0 {
|
||||
for _, tag := range tags {
|
||||
if _, err := sess.Insert(DashboardTag{DashboardId: dash.ID, Term: tag}); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cmd.Result = dash
|
||||
|
||||
if emitEntityEvent {
|
||||
_, err := sess.Insert(createEntityEvent(dash, store.EntityEventTypeUpdate))
|
||||
if err != nil {
|
||||
return err
|
||||
return dash, err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return dash, nil
|
||||
}
|
||||
|
||||
func generateNewDashboardUid(sess *db.Session, orgId int64) (string, error) {
|
||||
@@ -750,15 +759,18 @@ func (d *DashboardStore) deleteAlertByIdInternal(alertId int64, reason string, s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
var dashboards = make([]*dashboards.Dashboard, 0)
|
||||
func (d *DashboardStore) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) ([]*dashboards.Dashboard, error) {
|
||||
var dashboards = make([]*dashboards.Dashboard, 0)
|
||||
err := d.store.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
whereExpr := "org_id=? AND plugin_id=? AND is_folder=" + d.store.GetDialect().BooleanStr(false)
|
||||
|
||||
err := dbSession.Where(whereExpr, query.OrgID, query.PluginID).Find(&dashboards)
|
||||
query.Result = dashboards
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dashboards, nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) DeleteDashboard(ctx context.Context, cmd *dashboards.DeleteDashboardCommand) error {
|
||||
@@ -924,6 +936,7 @@ func (d *DashboardStore) deleteAlertDefinition(dashboardId int64, sess *db.Sessi
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboard(ctx context.Context, query *dashboards.GetDashboardQuery) (*dashboards.Dashboard, error) {
|
||||
var queryResult *dashboards.Dashboard
|
||||
err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
if query.ID == 0 && len(query.Slug) == 0 && len(query.UID) == 0 {
|
||||
return dashboards.ErrDashboardIdentifierNotSet
|
||||
@@ -940,35 +953,37 @@ func (d *DashboardStore) GetDashboard(ctx context.Context, query *dashboards.Get
|
||||
|
||||
dashboard.SetID(dashboard.ID)
|
||||
dashboard.SetUID(dashboard.UID)
|
||||
query.Result = &dashboard
|
||||
queryResult = &dashboard
|
||||
return nil
|
||||
})
|
||||
|
||||
return query.Result, err
|
||||
return queryResult, err
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboardUIDByID(ctx context.Context, query *dashboards.GetDashboardRefByIDQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
func (d *DashboardStore) GetDashboardUIDByID(ctx context.Context, query *dashboards.GetDashboardRefByIDQuery) (*dashboards.DashboardRef, error) {
|
||||
us := &dashboards.DashboardRef{}
|
||||
err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
var rawSQL = `SELECT uid, slug from dashboard WHERE Id=?`
|
||||
us := &dashboards.DashboardRef{}
|
||||
exists, err := sess.SQL(rawSQL, query.ID).Get(us)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
return dashboards.ErrDashboardNotFound
|
||||
}
|
||||
query.Result = us
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return us, nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboards(ctx context.Context, query *dashboards.GetDashboardsQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
func (d *DashboardStore) GetDashboards(ctx context.Context, query *dashboards.GetDashboardsQuery) ([]*dashboards.Dashboard, error) {
|
||||
var dashboards = make([]*dashboards.Dashboard, 0)
|
||||
err := d.store.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
if len(query.DashboardIDs) == 0 && len(query.DashboardUIDs) == 0 {
|
||||
return star.ErrCommandValidationFailed
|
||||
}
|
||||
|
||||
var dashboards = make([]*dashboards.Dashboard, 0)
|
||||
var session *xorm.Session
|
||||
if len(query.DashboardIDs) > 0 {
|
||||
session = sess.In("id", query.DashboardIDs)
|
||||
@@ -980,9 +995,12 @@ func (d *DashboardStore) GetDashboards(ctx context.Context, query *dashboards.Ge
|
||||
}
|
||||
|
||||
err := session.Find(&dashboards)
|
||||
query.Result = dashboards
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dashboards, nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) FindDashboards(ctx context.Context, query *models.FindPersistedDashboardsQuery) ([]dashboards.DashboardSearchProjection, error) {
|
||||
@@ -1067,8 +1085,9 @@ func (d *DashboardStore) FindDashboards(ctx context.Context, query *models.FindP
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (d *DashboardStore) GetDashboardTags(ctx context.Context, query *dashboards.GetDashboardTagsQuery) error {
|
||||
return d.store.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
func (d *DashboardStore) GetDashboardTags(ctx context.Context, query *dashboards.GetDashboardTagsQuery) ([]*dashboards.DashboardTagCloudItem, error) {
|
||||
queryResult := make([]*dashboards.DashboardTagCloudItem, 0)
|
||||
err := d.store.WithDbSession(ctx, func(dbSession *db.Session) error {
|
||||
sql := `SELECT
|
||||
COUNT(*) as count,
|
||||
term
|
||||
@@ -1078,11 +1097,14 @@ func (d *DashboardStore) GetDashboardTags(ctx context.Context, query *dashboards
|
||||
GROUP BY term
|
||||
ORDER BY term`
|
||||
|
||||
query.Result = make([]*dashboards.DashboardTagCloudItem, 0)
|
||||
sess := dbSession.SQL(sql, query.OrgID)
|
||||
err := sess.Find(&query.Result)
|
||||
err := sess.Find(&queryResult)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
// CountDashboardsInFolder returns a count of all dashboards associated with the
|
||||
|
||||
@@ -81,19 +81,19 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
query := &dashboards.GetDashboardsQuery{DashboardIDs: []int64{anotherDash.ID}}
|
||||
err = dashboardStore.GetDashboards(context.Background(), query)
|
||||
queryResult, err := dashboardStore.GetDashboards(context.Background(), query)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, query.Result)
|
||||
require.NotNil(t, queryResult)
|
||||
|
||||
deleteCmd := &dashboards.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: []string{"default"}}
|
||||
require.Nil(t, dashboardStore.DeleteOrphanedProvisionedDashboards(context.Background(), deleteCmd))
|
||||
|
||||
query = &dashboards.GetDashboardsQuery{DashboardIDs: []int64{dash.ID, anotherDash.ID}}
|
||||
err = dashboardStore.GetDashboards(context.Background(), query)
|
||||
queryResult, err = dashboardStore.GetDashboards(context.Background(), query)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Equal(t, 1, len(query.Result))
|
||||
require.Equal(t, dashId, query.Result[0].ID)
|
||||
require.Equal(t, 1, len(queryResult))
|
||||
require.Equal(t, dashId, queryResult[0].ID)
|
||||
})
|
||||
|
||||
t.Run("Can query for provisioned dashboards", func(t *testing.T) {
|
||||
|
||||
@@ -80,14 +80,14 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
OrgID: 1,
|
||||
}
|
||||
|
||||
_, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, query.Result.Title, "test dash 23")
|
||||
require.Equal(t, query.Result.Slug, "test-dash-23")
|
||||
require.Equal(t, query.Result.ID, savedDash.ID)
|
||||
require.Equal(t, query.Result.UID, savedDash.UID)
|
||||
require.False(t, query.Result.IsFolder)
|
||||
require.Equal(t, queryResult.Title, "test dash 23")
|
||||
require.Equal(t, queryResult.Slug, "test-dash-23")
|
||||
require.Equal(t, queryResult.ID, savedDash.ID)
|
||||
require.Equal(t, queryResult.UID, savedDash.UID)
|
||||
require.False(t, queryResult.IsFolder)
|
||||
})
|
||||
|
||||
t.Run("Should be able to get dashboard by slug", func(t *testing.T) {
|
||||
@@ -97,14 +97,14 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
OrgID: 1,
|
||||
}
|
||||
|
||||
_, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, query.Result.Title, "test dash 23")
|
||||
require.Equal(t, query.Result.Slug, "test-dash-23")
|
||||
require.Equal(t, query.Result.ID, savedDash.ID)
|
||||
require.Equal(t, query.Result.UID, savedDash.UID)
|
||||
require.False(t, query.Result.IsFolder)
|
||||
require.Equal(t, queryResult.Title, "test dash 23")
|
||||
require.Equal(t, queryResult.Slug, "test-dash-23")
|
||||
require.Equal(t, queryResult.ID, savedDash.ID)
|
||||
require.Equal(t, queryResult.UID, savedDash.UID)
|
||||
require.False(t, queryResult.IsFolder)
|
||||
})
|
||||
|
||||
t.Run("Should be able to get dashboard by uid", func(t *testing.T) {
|
||||
@@ -114,22 +114,22 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
OrgID: 1,
|
||||
}
|
||||
|
||||
_, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, query.Result.Title, "test dash 23")
|
||||
require.Equal(t, query.Result.Slug, "test-dash-23")
|
||||
require.Equal(t, query.Result.ID, savedDash.ID)
|
||||
require.Equal(t, query.Result.UID, savedDash.UID)
|
||||
require.False(t, query.Result.IsFolder)
|
||||
require.Equal(t, queryResult.Title, "test dash 23")
|
||||
require.Equal(t, queryResult.Slug, "test-dash-23")
|
||||
require.Equal(t, queryResult.ID, savedDash.ID)
|
||||
require.Equal(t, queryResult.UID, savedDash.UID)
|
||||
require.False(t, queryResult.IsFolder)
|
||||
})
|
||||
|
||||
t.Run("Should be able to get a dashboard UID by ID", func(t *testing.T) {
|
||||
setup()
|
||||
query := dashboards.GetDashboardRefByIDQuery{ID: savedDash.ID}
|
||||
err := dashboardStore.GetDashboardUIDByID(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardUIDByID(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, query.Result.UID, savedDash.UID)
|
||||
require.Equal(t, queryResult.UID, savedDash.UID)
|
||||
})
|
||||
|
||||
t.Run("Shouldn't be able to get a dashboard with just an OrgID", func(t *testing.T) {
|
||||
@@ -145,14 +145,14 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
t.Run("Should be able to get dashboards by IDs & UIDs", func(t *testing.T) {
|
||||
setup()
|
||||
query := dashboards.GetDashboardsQuery{DashboardIDs: []int64{savedDash.ID, savedDash2.ID}}
|
||||
err := dashboardStore.GetDashboards(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboards(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(query.Result), 2)
|
||||
assert.Equal(t, len(queryResult), 2)
|
||||
|
||||
query = dashboards.GetDashboardsQuery{DashboardUIDs: []string{savedDash.UID, savedDash2.UID}}
|
||||
err = dashboardStore.GetDashboards(context.Background(), &query)
|
||||
queryResult, err = dashboardStore.GetDashboards(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(query.Result), 2)
|
||||
assert.Equal(t, len(queryResult), 2)
|
||||
})
|
||||
|
||||
t.Run("Should be able to delete dashboard", func(t *testing.T) {
|
||||
@@ -220,13 +220,13 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
OrgID: 1,
|
||||
}
|
||||
|
||||
_, err = dashboardStore.GetDashboard(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboard(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, query.Result.FolderID, int64(0))
|
||||
require.Equal(t, query.Result.CreatedBy, savedDash.CreatedBy)
|
||||
require.WithinDuration(t, query.Result.Created, savedDash.Created, 3*time.Second)
|
||||
require.Equal(t, query.Result.UpdatedBy, int64(100))
|
||||
require.False(t, query.Result.Updated.IsZero())
|
||||
require.Equal(t, queryResult.FolderID, int64(0))
|
||||
require.Equal(t, queryResult.CreatedBy, savedDash.CreatedBy)
|
||||
require.WithinDuration(t, queryResult.Created, savedDash.Created, 3*time.Second)
|
||||
require.Equal(t, queryResult.UpdatedBy, int64(100))
|
||||
require.False(t, queryResult.Updated.IsZero())
|
||||
})
|
||||
|
||||
t.Run("Should be able to delete empty folder", func(t *testing.T) {
|
||||
@@ -308,9 +308,9 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
query := dashboards.GetDashboardsQuery{
|
||||
DashboardIDs: []int64{savedFolder.ID, savedDash.ID},
|
||||
}
|
||||
err = dashboardStore.GetDashboards(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboards(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(query.Result), 0)
|
||||
require.Equal(t, len(queryResult), 0)
|
||||
|
||||
pubdashConfig, err = publicDashboardStore.FindByAccessToken(context.Background(), "an-access-token")
|
||||
require.Nil(t, err)
|
||||
@@ -382,10 +382,10 @@ func TestIntegrationDashboardDataAccess(t *testing.T) {
|
||||
setup()
|
||||
query := dashboards.GetDashboardTagsQuery{OrgID: 1}
|
||||
|
||||
err := dashboardStore.GetDashboardTags(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardTags(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, len(query.Result), 2)
|
||||
require.Equal(t, len(queryResult), 2)
|
||||
})
|
||||
|
||||
t.Run("Should be able to find dashboard folder", func(t *testing.T) {
|
||||
@@ -603,9 +603,9 @@ func TestIntegrationDashboardDataAccessGivenPluginWithImportedDashboards(t *test
|
||||
OrgID: 1,
|
||||
}
|
||||
|
||||
err = dashboardStore.GetDashboardsByPluginID(context.Background(), &query)
|
||||
queryResult, err := dashboardStore.GetDashboardsByPluginID(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(query.Result), 2)
|
||||
require.Equal(t, len(queryResult), 2)
|
||||
}
|
||||
|
||||
func TestIntegrationDashboard_SortingOptions(t *testing.T) {
|
||||
|
||||
@@ -198,8 +198,6 @@ type SaveDashboardCommand struct {
|
||||
IsFolder bool `json:"isFolder"`
|
||||
|
||||
UpdatedAt time.Time
|
||||
|
||||
Result *Dashboard `json:"-"`
|
||||
}
|
||||
|
||||
type ValidateDashboardCommand struct {
|
||||
@@ -209,7 +207,6 @@ type ValidateDashboardCommand struct {
|
||||
type TrimDashboardCommand struct {
|
||||
Dashboard *simplejson.Json `json:"dashboard" binding:"Required"`
|
||||
Meta *simplejson.Json `json:"meta"`
|
||||
Result *Dashboard `json:"-"`
|
||||
}
|
||||
|
||||
type DashboardProvisioning struct {
|
||||
@@ -240,8 +237,6 @@ type GetDashboardQuery struct {
|
||||
ID int64 // optional if slug is set
|
||||
UID string // optional if slug is set
|
||||
OrgID int64
|
||||
|
||||
Result *Dashboard
|
||||
}
|
||||
|
||||
type DashboardTagCloudItem struct {
|
||||
@@ -250,33 +245,18 @@ type DashboardTagCloudItem struct {
|
||||
}
|
||||
|
||||
type GetDashboardTagsQuery struct {
|
||||
OrgID int64
|
||||
Result []*DashboardTagCloudItem
|
||||
OrgID int64
|
||||
}
|
||||
|
||||
type GetDashboardsQuery struct {
|
||||
DashboardIDs []int64
|
||||
DashboardUIDs []string
|
||||
OrgID int64
|
||||
Result []*Dashboard
|
||||
}
|
||||
|
||||
type GetDashboardsByPluginIDQuery struct {
|
||||
OrgID int64
|
||||
PluginID string
|
||||
Result []*Dashboard
|
||||
}
|
||||
|
||||
type GetDashboardSlugByIdQuery struct {
|
||||
ID int64
|
||||
Result string
|
||||
}
|
||||
|
||||
type GetDashboardsBySlugQuery struct {
|
||||
OrgID int64
|
||||
Slug string
|
||||
|
||||
Result []*Dashboard
|
||||
}
|
||||
|
||||
type DashboardRef struct {
|
||||
@@ -285,8 +265,7 @@ type DashboardRef struct {
|
||||
}
|
||||
|
||||
type GetDashboardRefByIDQuery struct {
|
||||
ID int64
|
||||
Result *DashboardRef
|
||||
ID int64
|
||||
}
|
||||
|
||||
type SaveDashboardDTO struct {
|
||||
@@ -418,5 +397,4 @@ func (dto *DashboardACLInfoDTO) IsDuplicateOf(other *DashboardACLInfoDTO) bool {
|
||||
type GetDashboardACLInfoListQuery struct {
|
||||
DashboardID int64
|
||||
OrgID int64
|
||||
Result []*DashboardACLInfoDTO
|
||||
}
|
||||
|
||||
@@ -483,7 +483,7 @@ func (dr *DashboardServiceImpl) UnprovisionDashboard(ctx context.Context, dashbo
|
||||
return dr.dashboardStore.UnprovisionDashboard(ctx, dashboardId)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) error {
|
||||
func (dr *DashboardServiceImpl) GetDashboardsByPluginID(ctx context.Context, query *dashboards.GetDashboardsByPluginIDQuery) ([]*dashboards.Dashboard, error) {
|
||||
return dr.dashboardStore.GetDashboardsByPluginID(ctx, query)
|
||||
}
|
||||
|
||||
@@ -522,16 +522,15 @@ func (dr *DashboardServiceImpl) setDefaultPermissions(ctx context.Context, dto *
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboard(ctx context.Context, query *dashboards.GetDashboardQuery) error {
|
||||
_, err := dr.dashboardStore.GetDashboard(ctx, query)
|
||||
return err
|
||||
func (dr *DashboardServiceImpl) GetDashboard(ctx context.Context, query *dashboards.GetDashboardQuery) (*dashboards.Dashboard, error) {
|
||||
return dr.dashboardStore.GetDashboard(ctx, query)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardUIDByID(ctx context.Context, query *dashboards.GetDashboardRefByIDQuery) error {
|
||||
func (dr *DashboardServiceImpl) GetDashboardUIDByID(ctx context.Context, query *dashboards.GetDashboardRefByIDQuery) (*dashboards.DashboardRef, error) {
|
||||
return dr.dashboardStore.GetDashboardUIDByID(ctx, query)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboards(ctx context.Context, query *dashboards.GetDashboardsQuery) error {
|
||||
func (dr *DashboardServiceImpl) GetDashboards(ctx context.Context, query *dashboards.GetDashboardsQuery) ([]*dashboards.Dashboard, error) {
|
||||
return dr.dashboardStore.GetDashboards(ctx, query)
|
||||
}
|
||||
|
||||
@@ -599,7 +598,7 @@ func makeQueryResult(query *models.FindPersistedDashboardsQuery, res []dashboard
|
||||
}
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardACLInfoList(ctx context.Context, query *dashboards.GetDashboardACLInfoListQuery) error {
|
||||
func (dr *DashboardServiceImpl) GetDashboardACLInfoList(ctx context.Context, query *dashboards.GetDashboardACLInfoListQuery) ([]*dashboards.DashboardACLInfoDTO, error) {
|
||||
return dr.dashboardStore.GetDashboardACLInfoList(ctx, query)
|
||||
}
|
||||
|
||||
@@ -611,7 +610,7 @@ func (dr *DashboardServiceImpl) HasEditPermissionInFolders(ctx context.Context,
|
||||
return dr.dashboardStore.HasEditPermissionInFolders(ctx, query)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardTags(ctx context.Context, query *dashboards.GetDashboardTagsQuery) error {
|
||||
func (dr *DashboardServiceImpl) GetDashboardTags(ctx context.Context, query *dashboards.GetDashboardTagsQuery) ([]*dashboards.DashboardTagCloudItem, error) {
|
||||
return dr.dashboardStore.GetDashboardTags(ctx, query)
|
||||
}
|
||||
|
||||
|
||||
@@ -260,22 +260,22 @@ func TestDashboardService(t *testing.T) {
|
||||
|
||||
t.Run("When org user is deleted", func(t *testing.T) {
|
||||
fakeStore := dashboards.FakeDashboardStore{}
|
||||
fakeStore.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil)
|
||||
fakeStore.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil, nil)
|
||||
t.Run("Should remove dependent permissions for deleted org user", func(t *testing.T) {
|
||||
permQuery := &dashboards.GetDashboardACLInfoListQuery{DashboardID: 1, OrgID: 1, Result: nil}
|
||||
permQuery := &dashboards.GetDashboardACLInfoListQuery{DashboardID: 1, OrgID: 1}
|
||||
|
||||
err := fakeStore.GetDashboardACLInfoList(context.Background(), permQuery)
|
||||
permQueryResult, err := fakeStore.GetDashboardACLInfoList(context.Background(), permQuery)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, len(permQuery.Result), 0)
|
||||
require.Equal(t, len(permQueryResult), 0)
|
||||
})
|
||||
|
||||
t.Run("Should not remove dashboard permissions for same user in another org", func(t *testing.T) {
|
||||
fakeStore := dashboards.FakeDashboardStore{}
|
||||
fakeStore.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil)
|
||||
fakeStore.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(nil, nil)
|
||||
permQuery := &dashboards.GetDashboardACLInfoListQuery{DashboardID: 2, OrgID: 3}
|
||||
|
||||
err := fakeStore.GetDashboardACLInfoList(context.Background(), permQuery)
|
||||
_, err := fakeStore.GetDashboardACLInfoList(context.Background(), permQuery)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -153,73 +153,118 @@ func (_m *FakeDashboardStore) GetDashboard(ctx context.Context, query *GetDashbo
|
||||
}
|
||||
|
||||
// GetDashboardACLInfoList provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardStore) GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) error {
|
||||
func (_m *FakeDashboardStore) GetDashboardACLInfoList(ctx context.Context, query *GetDashboardACLInfoListQuery) ([]*DashboardACLInfoDTO, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardACLInfoListQuery) error); ok {
|
||||
var r0 []*DashboardACLInfoDTO
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardACLInfoListQuery) []*DashboardACLInfoDTO); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*DashboardACLInfoDTO)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardACLInfoListQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboardTags provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardStore) GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) error {
|
||||
func (_m *FakeDashboardStore) GetDashboardTags(ctx context.Context, query *GetDashboardTagsQuery) ([]*DashboardTagCloudItem, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardTagsQuery) error); ok {
|
||||
var r0 []*DashboardTagCloudItem
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardTagsQuery) []*DashboardTagCloudItem); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*DashboardTagCloudItem)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardTagsQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboardUIDByID provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardStore) GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) error {
|
||||
func (_m *FakeDashboardStore) GetDashboardUIDByID(ctx context.Context, query *GetDashboardRefByIDQuery) (*DashboardRef, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardRefByIDQuery) error); ok {
|
||||
var r0 *DashboardRef
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardRefByIDQuery) *DashboardRef); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*DashboardRef)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardRefByIDQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboards provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardStore) GetDashboards(ctx context.Context, query *GetDashboardsQuery) error {
|
||||
func (_m *FakeDashboardStore) GetDashboards(ctx context.Context, query *GetDashboardsQuery) ([]*Dashboard, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardsQuery) error); ok {
|
||||
var r0 []*Dashboard
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardsQuery) []*Dashboard); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*Dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardsQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboardsByPluginID provides a mock function with given fields: ctx, query
|
||||
func (_m *FakeDashboardStore) GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) error {
|
||||
func (_m *FakeDashboardStore) GetDashboardsByPluginID(ctx context.Context, query *GetDashboardsByPluginIDQuery) ([]*Dashboard, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardsByPluginIDQuery) error); ok {
|
||||
var r0 []*Dashboard
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *GetDashboardsByPluginIDQuery) []*Dashboard); ok {
|
||||
r0 = rf(ctx, query)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*Dashboard)
|
||||
}
|
||||
}
|
||||
|
||||
return r0
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *GetDashboardsByPluginIDQuery) error); ok {
|
||||
r1 = rf(ctx, query)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetProvisionedDashboardData provides a mock function with given fields: ctx, name
|
||||
|
||||
@@ -408,12 +408,12 @@ func (s *Service) legacyUpdate(ctx context.Context, cmd *folder.UpdateFolderComm
|
||||
logger := s.log.FromContext(ctx)
|
||||
|
||||
query := dashboards.GetDashboardQuery{OrgID: cmd.OrgID, UID: cmd.UID}
|
||||
_, err := s.dashboardStore.GetDashboard(ctx, &query)
|
||||
queryResult, err := s.dashboardStore.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
return nil, toFolderError(err)
|
||||
}
|
||||
|
||||
dashFolder := query.Result
|
||||
dashFolder := queryResult
|
||||
currentTitle := dashFolder.Title
|
||||
|
||||
if !dashFolder.IsFolder {
|
||||
|
||||
@@ -126,11 +126,9 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
|
||||
title := "Folder-TEST"
|
||||
t.Run("When updating folder should return access denied error", func(t *testing.T) {
|
||||
dashStore.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
folder := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
folder.Result = dashboards.NewDashboard("dashboard-test")
|
||||
folder.Result.IsFolder = true
|
||||
}).Return(&dashboards.Dashboard{}, nil)
|
||||
folderResult := dashboards.NewDashboard("dashboard-test")
|
||||
folderResult.IsFolder = true
|
||||
dashStore.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(folderResult, nil)
|
||||
_, err := service.Update(context.Background(), &folder.UpdateFolderCommand{
|
||||
UID: folderUID,
|
||||
OrgID: orgID,
|
||||
|
||||
@@ -37,13 +37,14 @@ func NewAccessControlDashboardGuardian(
|
||||
OrgID: user.OrgID,
|
||||
}
|
||||
|
||||
if err := dashboardService.GetDashboard(ctx, q); err != nil {
|
||||
qResult, err := dashboardService.GetDashboard(ctx, q)
|
||||
if err != nil {
|
||||
if errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return nil, ErrGuardianDashboardNotFound.Errorf("failed to get dashboard by UID: %w", err)
|
||||
}
|
||||
return nil, ErrGuardianGetDashboardFailure.Errorf("failed to get dashboard by UID: %w", err)
|
||||
}
|
||||
dashboard = q.Result
|
||||
dashboard = qResult
|
||||
}
|
||||
|
||||
return &AccessControlDashboardGuardian{
|
||||
@@ -74,13 +75,14 @@ func NewAccessControlDashboardGuardianByUID(
|
||||
OrgID: user.OrgID,
|
||||
}
|
||||
|
||||
if err := dashboardService.GetDashboard(ctx, q); err != nil {
|
||||
qResult, err := dashboardService.GetDashboard(ctx, q)
|
||||
if err != nil {
|
||||
if errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return nil, ErrGuardianDashboardNotFound.Errorf("failed to get dashboard by UID: %w", err)
|
||||
}
|
||||
return nil, ErrGuardianGetDashboardFailure.Errorf("failed to get dashboard by UID: %w", err)
|
||||
}
|
||||
dashboard = q.Result
|
||||
dashboard = qResult
|
||||
}
|
||||
|
||||
return &AccessControlDashboardGuardian{
|
||||
@@ -337,8 +339,9 @@ func (a *AccessControlDashboardGuardian) loadParentFolder(folderID int64) (*dash
|
||||
return &dashboards.Dashboard{UID: accesscontrol.GeneralFolderUID}, nil
|
||||
}
|
||||
folderQuery := &dashboards.GetDashboardQuery{ID: folderID, OrgID: a.user.OrgID}
|
||||
if err := a.dashboardService.GetDashboard(a.ctx, folderQuery); err != nil {
|
||||
folderQueryResult, err := a.dashboardService.GetDashboard(a.ctx, folderQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return folderQuery.Result, nil
|
||||
return folderQueryResult, nil
|
||||
}
|
||||
|
||||
@@ -616,30 +616,31 @@ func setupAccessControlGuardianTest(t *testing.T, uid string, permissions []acce
|
||||
require.NoError(t, err)
|
||||
if dashboardSvc == nil {
|
||||
fakeDashboardService := dashboards.NewFakeDashboardService(t)
|
||||
qResult := &dashboards.Dashboard{}
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
qResult = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
OrgID: q.OrgID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(qResult, nil)
|
||||
dashboardSvc = fakeDashboardService
|
||||
}
|
||||
|
||||
g, err := NewAccessControlDashboardGuardian(context.Background(), dash.ID, &user.SignedInUser{OrgID: 1}, store, ac, folderPermissions, dashboardPermissions, dashboardSvc)
|
||||
require.NoError(t, err)
|
||||
g.dashboard = dash
|
||||
return g, dash
|
||||
}
|
||||
|
||||
func testDashSvc(t *testing.T) dashboards.DashboardService {
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
var d *dashboards.Dashboard
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
d := dashboards.NewDashboard("mocked")
|
||||
d.ID = 1
|
||||
d.UID = "1"
|
||||
q.Result = d
|
||||
}).Return(nil)
|
||||
}).Return(d, nil)
|
||||
return dashSvc
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func newDashboardGuardian(ctx context.Context, dashId int64, orgId int64, user *
|
||||
OrgID: orgId,
|
||||
}
|
||||
|
||||
if err := dashSvc.GetDashboard(ctx, q); err != nil {
|
||||
if _, err := dashSvc.GetDashboard(ctx, q); err != nil {
|
||||
if errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return nil, ErrGuardianDashboardNotFound.Errorf("failed to get dashboard by UID: %w", err)
|
||||
}
|
||||
@@ -110,13 +110,14 @@ func newDashboardGuardianByUID(ctx context.Context, dashUID string, orgId int64,
|
||||
OrgID: orgId,
|
||||
}
|
||||
|
||||
if err := dashSvc.GetDashboard(ctx, q); err != nil {
|
||||
qResult, err := dashSvc.GetDashboard(ctx, q)
|
||||
if err != nil {
|
||||
if errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return nil, ErrGuardianDashboardNotFound.Errorf("failed to get dashboard by UID: %w", err)
|
||||
}
|
||||
return nil, ErrGuardianGetDashboardFailure.Errorf("failed to get dashboard by UID: %w", err)
|
||||
}
|
||||
dashID = q.Result.ID
|
||||
dashID = qResult.ID
|
||||
}
|
||||
|
||||
return &dashboardGuardianImpl{
|
||||
@@ -306,10 +307,11 @@ func (g *dashboardGuardianImpl) GetACL() ([]*dashboards.DashboardACLInfoDTO, err
|
||||
}
|
||||
|
||||
query := dashboards.GetDashboardACLInfoListQuery{DashboardID: g.dashId, OrgID: g.orgId}
|
||||
if err := g.dashboardService.GetDashboardACLInfoList(g.ctx, &query); err != nil {
|
||||
queryResult, err := g.dashboardService.GetDashboardACLInfoList(g.ctx, &query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
g.acl = query.Result
|
||||
g.acl = queryResult
|
||||
return g.acl, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -690,22 +690,21 @@ func TestGuardianGetHiddenACL(t *testing.T) {
|
||||
t.Run("Get hidden ACL tests", func(t *testing.T) {
|
||||
store := dbtest.NewFakeDB()
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{Inherited: false, UserID: 1, UserLogin: "user1", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: false, UserID: 2, UserLogin: "user2", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: true, UserID: 3, UserLogin: "user3", Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{Inherited: false, UserID: 1, UserLogin: "user1", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: false, UserID: 2, UserLogin: "user2", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: true, UserID: 3, UserLogin: "user3", Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
var qResultDash *dashboards.Dashboard
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
qResultDash = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
OrgID: q.OrgID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(qResultDash, nil)
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
cfg.HiddenUsers = map[string]struct{}{"user2": {}}
|
||||
@@ -734,13 +733,9 @@ func TestGuardianGetHiddenACL(t *testing.T) {
|
||||
IsGrafanaAdmin: true,
|
||||
}
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
qResult := &dashboards.Dashboard{}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(qResult, nil)
|
||||
g, err := newDashboardGuardian(context.Background(), dashboardID, orgID, user, store, dashSvc, &teamtest.FakeService{})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -756,27 +751,26 @@ func TestGuardianGetACLWithoutDuplicates(t *testing.T) {
|
||||
t.Run("Get hidden ACL tests", func(t *testing.T) {
|
||||
store := dbtest.NewFakeDB()
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = []*dashboards.DashboardACLInfoDTO{
|
||||
{Inherited: true, UserID: 3, UserLogin: "user3", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: false, UserID: 3, UserLogin: "user3", Permission: models.PERMISSION_VIEW},
|
||||
{Inherited: false, UserID: 2, UserLogin: "user2", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: true, UserID: 4, UserLogin: "user4", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: false, UserID: 4, UserLogin: "user4", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: false, UserID: 5, UserLogin: "user5", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: true, UserID: 6, UserLogin: "user6", Permission: models.PERMISSION_VIEW},
|
||||
{Inherited: false, UserID: 6, UserLogin: "user6", Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
}).Return(nil)
|
||||
qResult := []*dashboards.DashboardACLInfoDTO{
|
||||
{Inherited: true, UserID: 3, UserLogin: "user3", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: false, UserID: 3, UserLogin: "user3", Permission: models.PERMISSION_VIEW},
|
||||
{Inherited: false, UserID: 2, UserLogin: "user2", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: true, UserID: 4, UserLogin: "user4", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: false, UserID: 4, UserLogin: "user4", Permission: models.PERMISSION_ADMIN},
|
||||
{Inherited: false, UserID: 5, UserLogin: "user5", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: true, UserID: 6, UserLogin: "user6", Permission: models.PERMISSION_VIEW},
|
||||
{Inherited: false, UserID: 6, UserLogin: "user6", Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
qResultDash := &dashboards.Dashboard{}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
qResultDash = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
OrgID: q.OrgID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(qResultDash, nil)
|
||||
|
||||
t.Run("Should get acl without duplicates", func(t *testing.T) {
|
||||
user := &user.SignedInUser{
|
||||
|
||||
@@ -47,13 +47,14 @@ func orgRoleScenario(desc string, t *testing.T, role org.RoleType, fn scenarioFu
|
||||
store := dbtest.NewFakeDB()
|
||||
|
||||
fakeDashboardService := dashboards.NewFakeDashboardService(t)
|
||||
var qResult *dashboards.Dashboard
|
||||
fakeDashboardService.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
qResult = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(qResult, nil)
|
||||
guard, err := newDashboardGuardian(context.Background(), dashboardID, orgID, user, store, fakeDashboardService, &teamtest.FakeService{})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -78,13 +79,14 @@ func apiKeyScenario(desc string, t *testing.T, role org.RoleType, fn scenarioFun
|
||||
}
|
||||
store := dbtest.NewFakeDB()
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
var qResult *dashboards.Dashboard
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
qResult = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(qResult, nil)
|
||||
guard, err := newDashboardGuardian(context.Background(), dashboardID, orgID, user, store, dashSvc, &teamtest.FakeService{})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -114,18 +116,17 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext,
|
||||
teamSvc := &teamtest.FakeService{ExpectedTeamsByUser: teams}
|
||||
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardACLInfoListQuery)
|
||||
q.Result = permissions
|
||||
}).Return(nil)
|
||||
qResult := permissions
|
||||
dashSvc.On("GetDashboardACLInfoList", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardACLInfoListQuery")).Return(qResult, nil)
|
||||
qResultDash := &dashboards.Dashboard{}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
qResultDash = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
OrgID: q.OrgID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(qResultDash, nil)
|
||||
|
||||
sc.permissionScenario = desc
|
||||
g, err := newDashboardGuardian(context.Background(), dashboardID, sc.givenUser.OrgID, sc.givenUser, store, dashSvc, teamSvc)
|
||||
|
||||
@@ -766,13 +766,14 @@ func scenarioWithLibraryPanel(t *testing.T, desc string, fn func(t *testing.T, s
|
||||
store := dbtest.NewFakeDB()
|
||||
|
||||
dashSvc := dashboards.NewFakeDashboardService(t)
|
||||
var result *dashboards.Dashboard
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{
|
||||
result = &dashboards.Dashboard{
|
||||
ID: q.ID,
|
||||
UID: q.UID,
|
||||
}
|
||||
}).Return(nil)
|
||||
}).Return(result, nil)
|
||||
guardian.InitLegacyGuardian(store, dashSvc, &teamtest.FakeService{})
|
||||
t.Helper()
|
||||
|
||||
|
||||
@@ -67,12 +67,13 @@ func (h *DashboardHandler) OnSubscribe(ctx context.Context, user *user.SignedInU
|
||||
// make sure can view this dashboard
|
||||
if len(parts) == 2 && parts[0] == "uid" {
|
||||
query := dashboards.GetDashboardQuery{UID: parts[1], OrgID: user.OrgID}
|
||||
if err := h.DashboardService.GetDashboard(ctx, &query); err != nil {
|
||||
queryResult, err := h.DashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
logger.Error("Error getting dashboard", "query", query, "error", err)
|
||||
return model.SubscribeReply{}, backend.SubscribeStreamStatusNotFound, nil
|
||||
}
|
||||
|
||||
dash := query.Result
|
||||
dash := queryResult
|
||||
guard, err := guardian.NewByDashboard(ctx, dash, user.OrgID, user)
|
||||
if err != nil {
|
||||
return model.SubscribeReply{}, backend.SubscribeStreamStatusPermissionDenied, err
|
||||
@@ -117,12 +118,13 @@ func (h *DashboardHandler) OnPublish(ctx context.Context, user *user.SignedInUse
|
||||
return model.PublishReply{}, backend.PublishStreamStatusNotFound, fmt.Errorf("ignore???")
|
||||
}
|
||||
query := dashboards.GetDashboardQuery{UID: parts[1], OrgID: user.OrgID}
|
||||
if err := h.DashboardService.GetDashboard(ctx, &query); err != nil {
|
||||
queryResult, err := h.DashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
logger.Error("Unknown dashboard", "query", query)
|
||||
return model.PublishReply{}, backend.PublishStreamStatusNotFound, nil
|
||||
}
|
||||
|
||||
guard, err := guardian.NewByDashboard(ctx, query.Result, user.OrgID, user)
|
||||
guard, err := guardian.NewByDashboard(ctx, queryResult, user.OrgID, user)
|
||||
if err != nil {
|
||||
logger.Error("Failed to create guardian", "err", err)
|
||||
return model.PublishReply{}, backend.PublishStreamStatusNotFound, fmt.Errorf("internal error")
|
||||
|
||||
@@ -335,9 +335,9 @@ func (s *ServiceImpl) buildStarredItemsNavLinks(c *models.ReqContext) ([]*navtre
|
||||
ID: dashboardId,
|
||||
OrgID: c.OrgID,
|
||||
}
|
||||
err := s.dashboardService.GetDashboard(c.Req.Context(), query)
|
||||
queryResult, err := s.dashboardService.GetDashboard(c.Req.Context(), query)
|
||||
if err == nil {
|
||||
starredDashboards = append(starredDashboards, query.Result)
|
||||
starredDashboards = append(starredDashboards, queryResult)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,16 +54,16 @@ func (r *dashboardResolver) getID(ctx context.Context, orgID int64, uid string)
|
||||
UID: uid,
|
||||
OrgID: orgID,
|
||||
}
|
||||
err := r.dashboards.GetDashboard(ctx, query)
|
||||
queryResult, err := r.dashboards.GetDashboard(ctx, query)
|
||||
// We also cache lookups where we don't find anything.
|
||||
if err != nil && errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
result = err
|
||||
} else if err != nil {
|
||||
return 0, err
|
||||
} else if query.Result == nil {
|
||||
} else if queryResult == nil {
|
||||
result = dashboards.ErrDashboardNotFound
|
||||
} else {
|
||||
result = query.Result.ID
|
||||
result = queryResult.ID
|
||||
}
|
||||
|
||||
// By setting the cache inside the singleflighted routine, we avoid any accidental re-queries that could get initiated after the query completes.
|
||||
|
||||
@@ -14,9 +14,8 @@ func TestDashboardResolver(t *testing.T) {
|
||||
t.Run("fetches dashboards from dashboard service", func(t *testing.T) {
|
||||
dbs := &dashboards.FakeDashboardService{}
|
||||
exp := int64(14)
|
||||
dbs.On("GetDashboard", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
|
||||
args.Get(1).(*dashboards.GetDashboardQuery).Result = &dashboards.Dashboard{ID: exp}
|
||||
}).Return(nil)
|
||||
result := &dashboards.Dashboard{ID: exp}
|
||||
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(result, nil)
|
||||
sut := createDashboardResolverSut(dbs)
|
||||
|
||||
id, err := sut.getID(context.Background(), 1, "dashboard-uid")
|
||||
@@ -27,9 +26,7 @@ func TestDashboardResolver(t *testing.T) {
|
||||
|
||||
t.Run("fetches dashboardNotFound if underlying dashboard does not exist", func(t *testing.T) {
|
||||
dbs := &dashboards.FakeDashboardService{}
|
||||
dbs.On("GetDashboard", mock.Anything, mock.Anything).Run(func(args mock.Arguments) {
|
||||
args.Get(1).(*dashboards.GetDashboardQuery).Result = nil
|
||||
}).Return(dashboards.ErrDashboardNotFound)
|
||||
dbs.On("GetDashboard", mock.Anything, mock.Anything).Return(nil, dashboards.ErrDashboardNotFound)
|
||||
sut := createDashboardResolverSut(dbs)
|
||||
|
||||
_, err := sut.getID(context.Background(), 1, "not-exist")
|
||||
|
||||
@@ -143,11 +143,12 @@ func (du *DashboardUpdater) handlePluginStateChanged(ctx context.Context, event
|
||||
du.syncPluginDashboards(ctx, p, event.OrgId)
|
||||
} else {
|
||||
query := dashboards.GetDashboardsByPluginIDQuery{PluginID: event.PluginId, OrgID: event.OrgId}
|
||||
if err := du.dashboardPluginService.GetDashboardsByPluginID(ctx, &query); err != nil {
|
||||
queryResult, err := du.dashboardPluginService.GetDashboardsByPluginID(ctx, &query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, dash := range query.Result {
|
||||
for _, dash := range queryResult {
|
||||
du.logger.Info("Deleting plugin dashboard", "pluginId", event.PluginId, "dashboard", dash.Slug)
|
||||
if err := du.dashboardService.DeleteDashboard(ctx, dash.ID, dash.OrgID); err != nil {
|
||||
return err
|
||||
|
||||
@@ -42,7 +42,8 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
|
||||
// load current dashboards
|
||||
query := dashboards.GetDashboardsByPluginIDQuery{OrgID: req.OrgID, PluginID: req.PluginID}
|
||||
if err := s.dashboardPluginService.GetDashboardsByPluginID(ctx, &query); err != nil {
|
||||
queryResult, err := s.dashboardPluginService.GetDashboardsByPluginID(ctx, &query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
res.Revision = dashboard.Data.Get("revision").MustInt64(1)
|
||||
|
||||
// find existing dashboard
|
||||
for _, existingDash := range query.Result {
|
||||
for _, existingDash := range queryResult {
|
||||
if existingDash.Slug == dashboard.Slug {
|
||||
res.UID = existingDash.UID
|
||||
res.DashboardId = existingDash.ID
|
||||
@@ -84,7 +85,7 @@ func (s Service) ListPluginDashboards(ctx context.Context, req *plugindashboards
|
||||
}
|
||||
|
||||
// find deleted dashboards
|
||||
for _, dash := range query.Result {
|
||||
for _, dash := range queryResult {
|
||||
if _, exists := existingMatches[dash.ID]; !exists {
|
||||
result = append(result, &plugindashboards.PluginDashboard{
|
||||
UID: dash.UID,
|
||||
|
||||
@@ -207,11 +207,11 @@ type dashboardPluginServiceMock struct {
|
||||
args []*dashmodels.GetDashboardsByPluginIDQuery
|
||||
}
|
||||
|
||||
func (d *dashboardPluginServiceMock) GetDashboardsByPluginID(ctx context.Context, query *dashmodels.GetDashboardsByPluginIDQuery) error {
|
||||
query.Result = []*dashmodels.Dashboard{}
|
||||
func (d *dashboardPluginServiceMock) GetDashboardsByPluginID(ctx context.Context, query *dashmodels.GetDashboardsByPluginIDQuery) ([]*dashmodels.Dashboard, error) {
|
||||
queryResult := []*dashmodels.Dashboard{}
|
||||
|
||||
if dashboards, exists := d.pluginDashboards[query.PluginID]; exists {
|
||||
query.Result = dashboards
|
||||
queryResult = dashboards
|
||||
}
|
||||
|
||||
if d.args == nil {
|
||||
@@ -220,5 +220,5 @@ func (d *dashboardPluginServiceMock) GetDashboardsByPluginID(ctx context.Context
|
||||
|
||||
d.args = append(d.args, query)
|
||||
|
||||
return nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func (prov *defaultAlertRuleProvisioner) getOrCreateFolderUID(
|
||||
Slug: slugify.Slugify(folderName),
|
||||
OrgID: orgID,
|
||||
}
|
||||
err := prov.dashboardService.GetDashboard(ctx, cmd)
|
||||
cmdResult, err := prov.dashboardService.GetDashboard(ctx, cmd)
|
||||
if err != nil && !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return "", err
|
||||
}
|
||||
@@ -123,9 +123,9 @@ func (prov *defaultAlertRuleProvisioner) getOrCreateFolderUID(
|
||||
return dbDash.UID, nil
|
||||
}
|
||||
|
||||
if !cmd.Result.IsFolder {
|
||||
if !cmdResult.IsFolder {
|
||||
return "", fmt.Errorf("got invalid response. expected folder, found dashboard")
|
||||
}
|
||||
|
||||
return cmd.Result.UID, nil
|
||||
return cmdResult.UID, nil
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ func (fr *FileReader) getOrCreateFolderID(ctx context.Context, cfg *config, serv
|
||||
}
|
||||
|
||||
cmd := &dashboards.GetDashboardQuery{Slug: slugify.Slugify(folderName), OrgID: cfg.OrgID}
|
||||
err := fr.dashboardStore.GetDashboard(ctx, cmd)
|
||||
result, err := fr.dashboardStore.GetDashboard(ctx, cmd)
|
||||
|
||||
if err != nil && !errors.Is(err, dashboards.ErrDashboardNotFound) {
|
||||
return 0, err
|
||||
@@ -326,11 +326,11 @@ func (fr *FileReader) getOrCreateFolderID(ctx context.Context, cfg *config, serv
|
||||
return dbDash.ID, nil
|
||||
}
|
||||
|
||||
if !cmd.Result.IsFolder {
|
||||
if !result.IsFolder {
|
||||
return 0, fmt.Errorf("got invalid response. expected folder, found dashboard")
|
||||
}
|
||||
|
||||
return cmd.Result.ID, nil
|
||||
return result.ID, nil
|
||||
}
|
||||
|
||||
func resolveSymlink(fileinfo os.FileInfo, path string) (os.FileInfo, error) {
|
||||
|
||||
@@ -512,6 +512,6 @@ func (ffi FakeFileInfo) Sys() interface{} {
|
||||
|
||||
type fakeDashboardStore struct{}
|
||||
|
||||
func (fds *fakeDashboardStore) GetDashboard(_ context.Context, _ *dashboards.GetDashboardQuery) error {
|
||||
return dashboards.ErrDashboardNotFound
|
||||
func (fds *fakeDashboardStore) GetDashboard(_ context.Context, _ *dashboards.GetDashboardQuery) (*dashboards.Dashboard, error) {
|
||||
return nil, dashboards.ErrDashboardNotFound
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
type DashboardStore interface {
|
||||
GetDashboard(context.Context, *dashboards.GetDashboardQuery) error
|
||||
GetDashboard(context.Context, *dashboards.GetDashboardQuery) (*dashboards.Dashboard, error)
|
||||
}
|
||||
|
||||
func CheckOrgExists(ctx context.Context, orgService org.Service, orgID int64) error {
|
||||
|
||||
@@ -86,7 +86,8 @@ func (s *HeadlessScreenshotService) Take(ctx context.Context, opts ScreenshotOpt
|
||||
defer func() { s.duration.Observe(time.Since(start).Seconds()) }()
|
||||
|
||||
q := dashboards.GetDashboardQuery{UID: opts.DashboardUID}
|
||||
if err := s.ds.GetDashboard(ctx, &q); err != nil {
|
||||
qResult, err := s.ds.GetDashboard(ctx, &q)
|
||||
if err != nil {
|
||||
s.instrumentError(err)
|
||||
return nil, err
|
||||
}
|
||||
@@ -94,9 +95,9 @@ func (s *HeadlessScreenshotService) Take(ctx context.Context, opts ScreenshotOpt
|
||||
opts = opts.SetDefaults()
|
||||
|
||||
u := url.URL{}
|
||||
u.Path = path.Join("d-solo", q.Result.UID, q.Result.Slug)
|
||||
u.Path = path.Join("d-solo", qResult.UID, qResult.Slug)
|
||||
p := u.Query()
|
||||
p.Add("orgId", strconv.FormatInt(q.Result.OrgID, 10))
|
||||
p.Add("orgId", strconv.FormatInt(qResult.OrgID, 10))
|
||||
p.Add("panelId", strconv.FormatInt(opts.PanelID, 10))
|
||||
p.Add("from", opts.From)
|
||||
p.Add("to", opts.To)
|
||||
@@ -104,7 +105,7 @@ func (s *HeadlessScreenshotService) Take(ctx context.Context, opts ScreenshotOpt
|
||||
|
||||
renderOpts := rendering.Opts{
|
||||
AuthOpts: rendering.AuthOpts{
|
||||
OrgID: q.Result.OrgID,
|
||||
OrgID: qResult.OrgID,
|
||||
OrgRole: org.RoleAdmin,
|
||||
},
|
||||
ErrorOpts: rendering.ErrorOpts{
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestHeadlessScreenshotService(t *testing.T) {
|
||||
s := NewHeadlessScreenshotService(&d, r, prometheus.NewRegistry())
|
||||
|
||||
// a non-existent dashboard should return error
|
||||
d.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(dashboards.ErrDashboardNotFound).Once()
|
||||
d.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(nil, dashboards.ErrDashboardNotFound).Once()
|
||||
ctx := context.Background()
|
||||
opts := ScreenshotOptions{}
|
||||
screenshot, err := s.Take(ctx, opts)
|
||||
@@ -34,10 +34,8 @@ func TestHeadlessScreenshotService(t *testing.T) {
|
||||
assert.Nil(t, screenshot)
|
||||
|
||||
// should take a screenshot
|
||||
d.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Run(func(args mock.Arguments) {
|
||||
q := args.Get(1).(*dashboards.GetDashboardQuery)
|
||||
q.Result = &dashboards.Dashboard{ID: 1, UID: "foo", Slug: "bar", OrgID: 2}
|
||||
}).Return(nil)
|
||||
qResult := &dashboards.Dashboard{ID: 1, UID: "foo", Slug: "bar", OrgID: 2}
|
||||
d.On("GetDashboard", mock.Anything, mock.AnythingOfType("*dashboards.GetDashboardQuery")).Return(qResult, nil)
|
||||
|
||||
renderOpts := rendering.Opts{
|
||||
AuthOpts: rendering.AuthOpts{
|
||||
|
||||
@@ -312,10 +312,10 @@ func TestIntegrationTeamCommandsAndQueries(t *testing.T) {
|
||||
require.Equal(t, err, team.ErrTeamNotFound)
|
||||
|
||||
permQuery := &dashboards.GetDashboardACLInfoListQuery{DashboardID: 1, OrgID: testOrgID}
|
||||
err = getDashboardACLInfoList(sqlStore, permQuery)
|
||||
permQueryResult, err := getDashboardACLInfoList(sqlStore, permQuery)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, len(permQuery.Result), 0)
|
||||
require.Equal(t, len(permQueryResult), 0)
|
||||
})
|
||||
|
||||
t.Run("Should be able to return if user is admin of teams or not", func(t *testing.T) {
|
||||
@@ -654,9 +654,9 @@ func updateDashboardACL(t *testing.T, sqlStore *sqlstore.SQLStore, dashboardID i
|
||||
// This function was copied from pkg/services/dashboards/database to circumvent
|
||||
// import cycles. When this org-related code is refactored into a service the
|
||||
// tests can the real GetDashboardACLInfoList functions
|
||||
func getDashboardACLInfoList(s *sqlstore.SQLStore, query *dashboards.GetDashboardACLInfoListQuery) error {
|
||||
func getDashboardACLInfoList(s *sqlstore.SQLStore, query *dashboards.GetDashboardACLInfoListQuery) ([]*dashboards.DashboardACLInfoDTO, error) {
|
||||
queryResult := make([]*dashboards.DashboardACLInfoDTO, 0)
|
||||
outerErr := s.WithDbSession(context.Background(), func(dbSession *db.Session) error {
|
||||
query.Result = make([]*dashboards.DashboardACLInfoDTO, 0)
|
||||
falseStr := s.GetDialect().BooleanStr(false)
|
||||
|
||||
if query.DashboardID == 0 {
|
||||
@@ -680,7 +680,7 @@ func getDashboardACLInfoList(s *sqlstore.SQLStore, query *dashboards.GetDashboar
|
||||
falseStr + ` AS inherited
|
||||
FROM dashboard_acl as da
|
||||
WHERE da.dashboard_id = -1`
|
||||
return dbSession.SQL(sql).Find(&query.Result)
|
||||
return dbSession.SQL(sql).Find(&queryResult)
|
||||
}
|
||||
|
||||
rawSQL := `
|
||||
@@ -722,16 +722,16 @@ func getDashboardACLInfoList(s *sqlstore.SQLStore, query *dashboards.GetDashboar
|
||||
ORDER BY da.id ASC
|
||||
`
|
||||
|
||||
return dbSession.SQL(rawSQL, query.OrgID, query.DashboardID).Find(&query.Result)
|
||||
return dbSession.SQL(rawSQL, query.OrgID, query.DashboardID).Find(&queryResult)
|
||||
})
|
||||
|
||||
if outerErr != nil {
|
||||
return outerErr
|
||||
return nil, outerErr
|
||||
}
|
||||
|
||||
for _, p := range query.Result {
|
||||
for _, p := range queryResult {
|
||||
p.PermissionName = p.Permission.String()
|
||||
}
|
||||
|
||||
return nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
@@ -432,10 +432,10 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
permQuery := &dashboards.GetDashboardACLInfoListQuery{DashboardID: 1, OrgID: users[0].OrgID}
|
||||
err = userStore.getDashboardACLInfoList(permQuery)
|
||||
permQueryResult, err := userStore.getDashboardACLInfoList(permQuery)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, permQuery.Result, 0)
|
||||
require.Len(t, permQueryResult, 0)
|
||||
|
||||
// A user is an org member and has been assigned permissions
|
||||
// Re-init DB
|
||||
@@ -488,10 +488,10 @@ func TestIntegrationUserDataAccess(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
|
||||
permQuery = &dashboards.GetDashboardACLInfoListQuery{DashboardID: 1, OrgID: users[0].OrgID}
|
||||
err = userStore.getDashboardACLInfoList(permQuery)
|
||||
permQueryResult, err = userStore.getDashboardACLInfoList(permQuery)
|
||||
require.Nil(t, err)
|
||||
|
||||
require.Len(t, permQuery.Result, 0)
|
||||
require.Len(t, permQueryResult, 0)
|
||||
})
|
||||
|
||||
t.Run("Testing DB - return list of users that the SignedInUser has permission to read", func(t *testing.T) {
|
||||
@@ -855,9 +855,9 @@ func updateDashboardACL(t *testing.T, sqlStore db.DB, dashboardID int64, items .
|
||||
// This function was copied from pkg/services/dashboards/database to circumvent
|
||||
// import cycles. When this org-related code is refactored into a service the
|
||||
// tests can the real GetDashboardACLInfoList functions
|
||||
func (ss *sqlStore) getDashboardACLInfoList(query *dashboards.GetDashboardACLInfoListQuery) error {
|
||||
func (ss *sqlStore) getDashboardACLInfoList(query *dashboards.GetDashboardACLInfoListQuery) ([]*dashboards.DashboardACLInfoDTO, error) {
|
||||
queryResult := make([]*dashboards.DashboardACLInfoDTO, 0)
|
||||
outerErr := ss.db.WithDbSession(context.Background(), func(dbSession *db.Session) error {
|
||||
query.Result = make([]*dashboards.DashboardACLInfoDTO, 0)
|
||||
falseStr := ss.dialect.BooleanStr(false)
|
||||
|
||||
if query.DashboardID == 0 {
|
||||
@@ -881,7 +881,7 @@ func (ss *sqlStore) getDashboardACLInfoList(query *dashboards.GetDashboardACLInf
|
||||
falseStr + ` AS inherited
|
||||
FROM dashboard_acl as da
|
||||
WHERE da.dashboard_id = -1`
|
||||
return dbSession.SQL(sql).Find(&query.Result)
|
||||
return dbSession.SQL(sql).Find(&queryResult)
|
||||
}
|
||||
|
||||
rawSQL := `
|
||||
@@ -923,18 +923,18 @@ func (ss *sqlStore) getDashboardACLInfoList(query *dashboards.GetDashboardACLInf
|
||||
ORDER BY da.id ASC
|
||||
`
|
||||
|
||||
return dbSession.SQL(rawSQL, query.OrgID, query.DashboardID).Find(&query.Result)
|
||||
return dbSession.SQL(rawSQL, query.OrgID, query.DashboardID).Find(&queryResult)
|
||||
})
|
||||
|
||||
if outerErr != nil {
|
||||
return outerErr
|
||||
return nil, outerErr
|
||||
}
|
||||
|
||||
for _, p := range query.Result {
|
||||
for _, p := range queryResult {
|
||||
p.PermissionName = p.Permission.String()
|
||||
}
|
||||
|
||||
return nil
|
||||
return queryResult, nil
|
||||
}
|
||||
|
||||
func createOrgAndUserSvc(t *testing.T, store db.DB, cfg *setting.Cfg) (org.Service, user.Service) {
|
||||
|
||||
Reference in New Issue
Block a user