|
|
|
@ -11,7 +11,6 @@ import ( |
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson" |
|
|
|
|
"github.com/grafana/grafana/pkg/models" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/search" |
|
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -37,7 +36,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("and no acls are set", func(t *testing.T) { |
|
|
|
|
t.Run("should return all dashboards", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, |
|
|
|
|
OrgId: 1, |
|
|
|
|
DashboardIds: []int64{folder.Id, dashInRoot.Id}, |
|
|
|
@ -61,7 +60,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
t.Run("should not return folder", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, |
|
|
|
|
OrgId: 1, DashboardIds: []int64{folder.Id, dashInRoot.Id}, |
|
|
|
|
} |
|
|
|
@ -79,7 +78,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
t.Run("should be able to access folder", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, |
|
|
|
|
OrgId: 1, |
|
|
|
|
DashboardIds: []int64{folder.Id, dashInRoot.Id}, |
|
|
|
@ -94,7 +93,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("when the user is an admin", func(t *testing.T) { |
|
|
|
|
t.Run("should be able to access folder", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{ |
|
|
|
|
UserId: currentUser.Id, |
|
|
|
|
OrgId: 1, |
|
|
|
@ -122,7 +121,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
t.Run("should not return folder or child", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, OrgId: 1, DashboardIds: []int64{folder.Id, childDash.Id, dashInRoot.Id}, |
|
|
|
|
} |
|
|
|
|
err := sqlStore.SearchDashboards(context.Background(), query) |
|
|
|
@ -138,7 +137,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
t.Run("should be able to search for child dashboard but not folder", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, OrgId: 1, DashboardIds: []int64{folder.Id, childDash.Id, dashInRoot.Id}} |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, OrgId: 1, DashboardIds: []int64{folder.Id, childDash.Id, dashInRoot.Id}} |
|
|
|
|
err := sqlStore.SearchDashboards(context.Background(), query) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Equal(t, len(query.Result), 2) |
|
|
|
@ -149,7 +148,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("when the user is an admin", func(t *testing.T) { |
|
|
|
|
t.Run("should be able to search for child dash and folder", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{ |
|
|
|
|
UserId: currentUser.Id, |
|
|
|
|
OrgId: 1, |
|
|
|
@ -190,7 +189,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
setup2() |
|
|
|
|
t.Run("and one folder is expanded, the other collapsed", func(t *testing.T) { |
|
|
|
|
t.Run("should return dashboards in root and expanded folder", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
FolderIds: []int64{ |
|
|
|
|
rootFolderId, folder1.Id}, SignedInUser: &models.SignedInUser{UserId: currentUser.Id, |
|
|
|
|
OrgId: 1, OrgRole: models.ROLE_VIEWER, |
|
|
|
@ -218,7 +217,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
moveDashboard(t, dashboardStore, 1, childDash2.Data, folder1.Id) |
|
|
|
|
|
|
|
|
|
t.Run("should not return folder with acl or its children", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, |
|
|
|
|
OrgId: 1, |
|
|
|
|
DashboardIds: []int64{folder1.Id, childDash1.Id, childDash2.Id, dashInRoot.Id}, |
|
|
|
@ -234,7 +233,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
moveDashboard(t, dashboardStore, 1, childDash1.Data, folder2.Id) |
|
|
|
|
|
|
|
|
|
t.Run("should return folder without acl and its children", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, |
|
|
|
|
OrgId: 1, |
|
|
|
|
DashboardIds: []int64{folder2.Id, childDash1.Id, childDash2.Id, dashInRoot.Id}, |
|
|
|
@ -258,7 +257,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
moveDashboard(t, dashboardStore, 1, childDash1.Data, folder2.Id) |
|
|
|
|
|
|
|
|
|
t.Run("should return folder without acl but not the dashboard with acl", func(t *testing.T) { |
|
|
|
|
query := &search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := &models.FindPersistedDashboardsQuery{ |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: currentUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER}, |
|
|
|
|
OrgId: 1, |
|
|
|
|
DashboardIds: []int64{folder2.Id, childDash1.Id, childDash2.Id, dashInRoot.Id}, |
|
|
|
@ -295,7 +294,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
setup3() |
|
|
|
|
t.Run("Admin users", func(t *testing.T) { |
|
|
|
|
t.Run("Should have write access to all dashboard folders in their org", func(t *testing.T) { |
|
|
|
|
query := search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := models.FindPersistedDashboardsQuery{ |
|
|
|
|
OrgId: 1, |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: adminUser.Id, OrgRole: models.ROLE_ADMIN, OrgId: 1}, |
|
|
|
|
Permission: models.PERMISSION_VIEW, |
|
|
|
@ -348,7 +347,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
t.Run("Editor users", func(t *testing.T) { |
|
|
|
|
query := search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := models.FindPersistedDashboardsQuery{ |
|
|
|
|
OrgId: 1, |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: editorUser.Id, OrgRole: models.ROLE_EDITOR, OrgId: 1}, |
|
|
|
|
Permission: models.PERMISSION_EDIT, |
|
|
|
@ -414,7 +413,7 @@ func TestDashboardFolderDataAccess(t *testing.T) { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
t.Run("Viewer users", func(t *testing.T) { |
|
|
|
|
query := search.FindPersistedDashboardsQuery{ |
|
|
|
|
query := models.FindPersistedDashboardsQuery{ |
|
|
|
|
OrgId: 1, |
|
|
|
|
SignedInUser: &models.SignedInUser{UserId: viewerUser.Id, OrgRole: models.ROLE_VIEWER, OrgId: 1}, |
|
|
|
|
Permission: models.PERMISSION_EDIT, |
|
|
|
|