mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Remove folderID from service tests (#80615)
* Remove folderID from service tests * Remove folderID from ngalert migration tests * Remove tests related to folderIDs * Roll back change Before removing FolderID from this test, we need to adjust the code * Remove FolderID from publicdashboard pkg * Add back annotations test
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@@ -108,63 +107,6 @@ func TestNewFolderIDScopeResolver(t *testing.T) {
|
||||
require.Equal(t, "folders:id:", prefix)
|
||||
})
|
||||
|
||||
t.Run("resolver should convert to uid scope", func(t *testing.T) {
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
_, resolver := NewFolderIDScopeResolver(folderStore, foldertest.NewFakeService())
|
||||
|
||||
orgID := rand.Int63()
|
||||
uid := util.GenerateShortUID()
|
||||
// nolint:staticcheck
|
||||
db := &folder.Folder{ID: rand.Int63(), UID: uid}
|
||||
folderStore.On("GetFolderByID", mock.Anything, mock.Anything, mock.Anything).Return(db, nil).Once()
|
||||
|
||||
// nolint:staticcheck
|
||||
scope := "folders:id:" + strconv.FormatInt(db.ID, 10)
|
||||
resolvedScopes, err := resolver.Resolve(context.Background(), orgID, scope)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resolvedScopes, 1)
|
||||
require.Equal(t, fmt.Sprintf("folders:uid:%v", db.UID), resolvedScopes[0])
|
||||
|
||||
// nolint:staticcheck
|
||||
folderStore.AssertCalled(t, "GetFolderByID", mock.Anything, orgID, db.ID)
|
||||
})
|
||||
t.Run("resolver should should include inherited scopes if any", func(t *testing.T) {
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
folderSvc := foldertest.NewFakeService()
|
||||
folderSvc.ExpectedFolders = []*folder.Folder{
|
||||
{
|
||||
UID: "parent",
|
||||
},
|
||||
{
|
||||
UID: "grandparent",
|
||||
},
|
||||
}
|
||||
_, resolver := NewFolderIDScopeResolver(folderStore, folderSvc)
|
||||
|
||||
orgId := rand.Int63()
|
||||
uid := util.GenerateShortUID()
|
||||
// nolint:staticcheck
|
||||
db := &folder.Folder{ID: rand.Int63(), UID: uid}
|
||||
folderStore.On("GetFolderByID", mock.Anything, mock.Anything, mock.Anything).Return(db, nil).Once()
|
||||
|
||||
// nolint:staticcheck
|
||||
scope := "folders:id:" + strconv.FormatInt(db.ID, 10)
|
||||
|
||||
resolvedScopes, err := resolver.Resolve(context.Background(), orgId, scope)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resolvedScopes, 3)
|
||||
|
||||
if diff := cmp.Diff([]string{
|
||||
fmt.Sprintf("folders:uid:%v", db.UID),
|
||||
"folders:uid:parent",
|
||||
"folders:uid:grandparent",
|
||||
}, resolvedScopes); diff != "" {
|
||||
t.Errorf("Result mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
|
||||
// nolint:staticcheck
|
||||
folderStore.AssertCalled(t, "GetFolderByID", mock.Anything, orgId, db.ID)
|
||||
})
|
||||
t.Run("resolver should fail if input scope is not expected", func(t *testing.T) {
|
||||
_, resolver := NewFolderIDScopeResolver(foldertest.NewFakeFolderStore(t), foldertest.NewFakeService())
|
||||
|
||||
@@ -211,87 +153,11 @@ func TestNewDashboardIDScopeResolver(t *testing.T) {
|
||||
require.Equal(t, "dashboards:id:", prefix)
|
||||
})
|
||||
|
||||
t.Run("resolver should convert to uid dashboard and folder scope", func(t *testing.T) {
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
dashSvc := &FakeDashboardService{}
|
||||
_, resolver := NewDashboardIDScopeResolver(folderStore, dashSvc, foldertest.NewFakeService())
|
||||
|
||||
orgID := rand.Int63()
|
||||
// nolint:staticcheck
|
||||
folder := &folder.Folder{ID: 2, UID: "2"}
|
||||
// nolint:staticcheck
|
||||
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}
|
||||
dashSvc.On("G")
|
||||
// nolint:staticcheck
|
||||
folderStore.On("GetFolderByID", mock.Anything, orgID, folder.ID).Return(folder, nil).Once()
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil).Once()
|
||||
scope := ac.Scope("dashboards", "id", strconv.FormatInt(dashboard.ID, 10))
|
||||
resolvedScopes, err := resolver.Resolve(context.Background(), orgID, scope)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resolvedScopes, 2)
|
||||
require.Equal(t, fmt.Sprintf("dashboards:uid:%s", dashboard.UID), resolvedScopes[0])
|
||||
require.Equal(t, fmt.Sprintf("folders:uid:%s", folder.UID), resolvedScopes[1])
|
||||
})
|
||||
|
||||
t.Run("resolver should inlude inherited scopes if any", func(t *testing.T) {
|
||||
dashSvc := &FakeDashboardService{}
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
folderSvc := foldertest.NewFakeService()
|
||||
folderSvc.ExpectedFolders = []*folder.Folder{
|
||||
{
|
||||
UID: "parent",
|
||||
},
|
||||
{
|
||||
UID: "grandparent",
|
||||
},
|
||||
}
|
||||
_, resolver := NewDashboardIDScopeResolver(folderStore, dashSvc, folderSvc)
|
||||
|
||||
orgID := rand.Int63()
|
||||
// nolint:staticcheck
|
||||
folder := &folder.Folder{ID: 2, UID: "2"}
|
||||
// nolint:staticcheck
|
||||
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}
|
||||
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil).Once()
|
||||
// nolint:staticcheck
|
||||
folderStore.On("GetFolderByID", mock.Anything, orgID, folder.ID).Return(folder, nil).Once()
|
||||
|
||||
scope := ac.Scope("dashboards", "id", strconv.FormatInt(dashboard.ID, 10))
|
||||
resolvedScopes, err := resolver.Resolve(context.Background(), orgID, scope)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resolvedScopes, 4)
|
||||
|
||||
if diff := cmp.Diff([]string{
|
||||
fmt.Sprintf("dashboards:uid:%s", dashboard.UID),
|
||||
fmt.Sprintf("folders:uid:%s", folder.UID),
|
||||
"folders:uid:parent",
|
||||
"folders:uid:grandparent",
|
||||
}, resolvedScopes); diff != "" {
|
||||
t.Errorf("Result mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("resolver should fail if input scope is not expected", func(t *testing.T) {
|
||||
_, resolver := NewDashboardIDScopeResolver(foldertest.NewFakeFolderStore(t), &FakeDashboardService{}, foldertest.NewFakeService())
|
||||
_, err := resolver.Resolve(context.Background(), rand.Int63(), "dashboards:uid:123")
|
||||
require.ErrorIs(t, err, ac.ErrInvalidScope)
|
||||
})
|
||||
|
||||
t.Run("resolver should convert folderID 0 to general uid scope for the folder scope", func(t *testing.T) {
|
||||
dashSvc := &FakeDashboardService{}
|
||||
_, resolver := NewDashboardIDScopeResolver(foldertest.NewFakeFolderStore(t), dashSvc, foldertest.NewFakeService())
|
||||
|
||||
// nolint:staticcheck
|
||||
dashboard := &Dashboard{ID: 1, FolderID: 0, UID: "1"}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
resolved, err := resolver.Resolve(context.Background(), 1, ac.Scope("dashboards", "id", "1"))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, resolved, 2)
|
||||
require.Equal(t, "dashboards:uid:1", resolved[0])
|
||||
require.Equal(t, "folders:uid:general", resolved[1])
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewDashboardUIDScopeResolver(t *testing.T) {
|
||||
@@ -300,83 +166,9 @@ func TestNewDashboardUIDScopeResolver(t *testing.T) {
|
||||
require.Equal(t, "dashboards:uid:", prefix)
|
||||
})
|
||||
|
||||
t.Run("resolver should convert to uid dashboard and folder scope", func(t *testing.T) {
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
dashSvc := &FakeDashboardService{}
|
||||
_, resolver := NewDashboardUIDScopeResolver(folderStore, dashSvc, foldertest.NewFakeService())
|
||||
|
||||
orgID := rand.Int63()
|
||||
// nolint:staticcheck
|
||||
folder := &folder.Folder{ID: 2, UID: "2"}
|
||||
// nolint:staticcheck
|
||||
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}
|
||||
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil).Once()
|
||||
// nolint:staticcheck
|
||||
folderStore.On("GetFolderByID", mock.Anything, orgID, folder.ID).Return(folder, nil).Once()
|
||||
scope := ac.Scope("dashboards", "uid", dashboard.UID)
|
||||
resolvedScopes, err := resolver.Resolve(context.Background(), orgID, scope)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resolvedScopes, 2)
|
||||
require.Equal(t, fmt.Sprintf("dashboards:uid:%s", dashboard.UID), resolvedScopes[0])
|
||||
require.Equal(t, fmt.Sprintf("folders:uid:%s", folder.UID), resolvedScopes[1])
|
||||
})
|
||||
|
||||
t.Run("resolver should include inherited scopes if any", func(t *testing.T) {
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
folderSvc := foldertest.NewFakeService()
|
||||
folderSvc.ExpectedFolders = []*folder.Folder{
|
||||
{
|
||||
UID: "parent",
|
||||
},
|
||||
{
|
||||
UID: "grandparent",
|
||||
},
|
||||
}
|
||||
dashSvc := &FakeDashboardService{}
|
||||
_, resolver := NewDashboardUIDScopeResolver(folderStore, dashSvc, folderSvc)
|
||||
|
||||
orgID := rand.Int63()
|
||||
// nolint:staticcheck
|
||||
folder := &folder.Folder{ID: 2, UID: "2"}
|
||||
// nolint:staticcheck
|
||||
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}
|
||||
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil).Once()
|
||||
folderStore.On("GetFolderByID", mock.Anything, mock.Anything, mock.Anything).Return(folder, nil).Once()
|
||||
|
||||
scope := ac.Scope("dashboards", "uid", dashboard.UID)
|
||||
resolvedScopes, err := resolver.Resolve(context.Background(), orgID, scope)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resolvedScopes, 4)
|
||||
|
||||
if diff := cmp.Diff([]string{
|
||||
fmt.Sprintf("dashboards:uid:%s", dashboard.UID),
|
||||
fmt.Sprintf("folders:uid:%s", folder.UID),
|
||||
"folders:uid:parent",
|
||||
"folders:uid:grandparent",
|
||||
}, resolvedScopes); diff != "" {
|
||||
t.Errorf("Result mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("resolver should fail if input scope is not expected", func(t *testing.T) {
|
||||
_, resolver := NewDashboardUIDScopeResolver(foldertest.NewFakeFolderStore(t), &FakeDashboardService{}, foldertest.NewFakeService())
|
||||
_, err := resolver.Resolve(context.Background(), rand.Int63(), "dashboards:id:123")
|
||||
require.ErrorIs(t, err, ac.ErrInvalidScope)
|
||||
})
|
||||
|
||||
t.Run("resolver should convert folderID 0 to general uid scope for the folder scope", func(t *testing.T) {
|
||||
service := &FakeDashboardService{}
|
||||
_, resolver := NewDashboardUIDScopeResolver(foldertest.NewFakeFolderStore(t), service, foldertest.NewFakeService())
|
||||
|
||||
// nolint:staticcheck
|
||||
dashboard := &Dashboard{ID: 1, FolderID: 0, UID: "1"}
|
||||
service.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil)
|
||||
resolved, err := resolver.Resolve(context.Background(), 1, ac.Scope("dashboards", "uid", "1"))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, resolved, 2)
|
||||
require.Equal(t, "dashboards:uid:1", resolved[0])
|
||||
require.Equal(t, "folders:uid:general", resolved[1])
|
||||
})
|
||||
}
|
||||
|
||||
@@ -194,9 +194,10 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
|
||||
t.Run("should not return folder with acl or its children", func(t *testing.T) {
|
||||
query := &dashboards.FindPersistedDashboardsQuery{
|
||||
SignedInUser: currentUser,
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder1.ID, childDash1.ID, childDash2.ID, dashInRoot.ID},
|
||||
SignedInUser: currentUser,
|
||||
OrgId: 1,
|
||||
DashboardIds: []int64{folder1.ID, childDash1.ID, childDash2.ID, dashInRoot.ID},
|
||||
DashboardUIDs: []string{folder1.UID, childDash1.UID, childDash2.UID, dashInRoot.UID},
|
||||
}
|
||||
hits, err := testSearchDashboards(dashboardStore, query)
|
||||
require.NoError(t, err)
|
||||
@@ -206,7 +207,7 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
})
|
||||
t.Run("and a dashboard is moved from folder with acl to the folder without an acl", func(t *testing.T) {
|
||||
setup2()
|
||||
moveDashboard(t, dashboardStore, 1, childDash1.Data, folder2.ID, folder2.UID)
|
||||
moveDashboard(t, dashboardStore, 1, childDash1.Data, folder2.ID, childDash2.FolderUID)
|
||||
currentUser.Permissions = map[int64]map[string][]string{1: {dashboards.ActionDashboardsRead: {dashboards.ScopeDashboardsProvider.GetResourceScopeUID(dashInRoot.UID), dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder2.UID)}, dashboards.ActionFoldersRead: {dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder2.UID)}}}
|
||||
actest.AddUserPermissionToDB(t, sqlStore, currentUser)
|
||||
|
||||
@@ -218,11 +219,11 @@ func TestIntegrationDashboardFolderDataAccess(t *testing.T) {
|
||||
}
|
||||
hits, err := testSearchDashboards(dashboardStore, query)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(hits), 4)
|
||||
require.Equal(t, hits[0].ID, folder2.ID)
|
||||
require.Equal(t, hits[1].ID, childDash1.ID)
|
||||
require.Equal(t, hits[2].ID, childDash2.ID)
|
||||
require.Equal(t, hits[3].ID, dashInRoot.ID)
|
||||
assert.Equal(t, len(hits), 4)
|
||||
assert.Equal(t, hits[0].ID, folder2.ID)
|
||||
assert.Equal(t, hits[1].ID, childDash1.ID)
|
||||
assert.Equal(t, hits[2].ID, childDash2.ID)
|
||||
assert.Equal(t, hits[3].ID, dashInRoot.ID)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -339,7 +340,6 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": dashInParentTitle,
|
||||
}),
|
||||
FolderID: nestedFolders[0].ID, // nolint:staticcheck
|
||||
FolderUID: nestedFolders[0].UID,
|
||||
}
|
||||
_, err = dashboardWriteStore.SaveDashboard(context.Background(), saveDashboardCmd)
|
||||
@@ -352,7 +352,6 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": dashInSubfolderTitle,
|
||||
}),
|
||||
FolderID: nestedFolders[1].ID, // nolint:staticcheck
|
||||
FolderUID: nestedFolders[1].UID,
|
||||
}
|
||||
_, err = dashboardWriteStore.SaveDashboard(context.Background(), saveDashboardCmd)
|
||||
@@ -378,22 +377,6 @@ func TestIntegrationDashboardInheritedFolderRBAC(t *testing.T) {
|
||||
permissions: nil,
|
||||
expectedTitles: nil,
|
||||
},
|
||||
{
|
||||
desc: "it should not return dashboard in subfolder if nested folders are disabled and the user has permission to read dashboards under parent folder",
|
||||
features: featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch),
|
||||
permissions: map[string][]string{
|
||||
dashboards.ActionDashboardsRead: {fmt.Sprintf("folders:uid:%s", nestedFolders[0].UID)},
|
||||
},
|
||||
expectedTitles: []string{dashInParentTitle},
|
||||
},
|
||||
{
|
||||
desc: "it should return dashboard in subfolder if nested folders are enabled and the user has permission to read dashboards under parent folder",
|
||||
features: featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch, featuremgmt.FlagNestedFolders),
|
||||
permissions: map[string][]string{
|
||||
dashboards.ActionDashboardsRead: {fmt.Sprintf("folders:uid:%s", nestedFolders[0].UID)},
|
||||
},
|
||||
expectedTitles: []string{dashInParentTitle, dashInSubfolderTitle},
|
||||
},
|
||||
{
|
||||
desc: "it should not return subfolder if nested folders are disabled and the user has permission to read folders under parent folder",
|
||||
features: featuremgmt.WithFeatures(featuremgmt.FlagPanelTitleSearch),
|
||||
|
||||
@@ -39,11 +39,10 @@ func TestIntegrationDashboardProvisioningTest(t *testing.T) {
|
||||
saveDashboardCmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
FolderID: dash.ID, // nolint:staticcheck
|
||||
FolderUID: dash.UID,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"id": nil,
|
||||
"title": "test dashboard",
|
||||
"title": "test dashboard 2",
|
||||
}),
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": "Dash",
|
||||
}),
|
||||
FolderID: sc.otherSavedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.otherSavedFolder.UID,
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -152,7 +151,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": sc.savedDashInFolder.Title,
|
||||
}),
|
||||
FolderID: sc.savedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.savedFolder.UID,
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -177,7 +175,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"uid": sc.savedDashInFolder.UID,
|
||||
"title": "New dash",
|
||||
}),
|
||||
FolderID: sc.savedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.savedFolder.UID,
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -202,7 +199,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": sc.savedDashInGeneralFolder.ID,
|
||||
"title": "Dash",
|
||||
}),
|
||||
FolderID: sc.savedDashInGeneralFolder.FolderID, // nolint:staticcheck
|
||||
FolderUID: sc.savedDashInGeneralFolder.FolderUID,
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -227,7 +223,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": sc.savedDashInFolder.ID,
|
||||
"title": "Dash",
|
||||
}),
|
||||
FolderID: sc.savedDashInFolder.FolderID, // nolint:staticcheck
|
||||
FolderUID: sc.savedDashInFolder.FolderUID,
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -252,7 +247,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": sc.savedDashInGeneralFolder.ID,
|
||||
"title": "Dash",
|
||||
}),
|
||||
FolderID: sc.otherSavedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.otherSavedFolder.UID,
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -277,7 +271,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": sc.savedDashInFolder.ID,
|
||||
"title": "Dash",
|
||||
}),
|
||||
FolderID: 0, // nolint:staticcheck
|
||||
FolderUID: "",
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -302,7 +295,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"uid": sc.savedDashInGeneralFolder.UID,
|
||||
"title": "Dash",
|
||||
}),
|
||||
FolderID: sc.otherSavedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.otherSavedFolder.UID,
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -327,7 +319,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"uid": sc.savedDashInFolder.UID,
|
||||
"title": "Dash",
|
||||
}),
|
||||
FolderID: 0, // nolint:staticcheck
|
||||
FolderUID: "",
|
||||
UserID: 10000,
|
||||
Overwrite: true,
|
||||
@@ -359,7 +350,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": nil,
|
||||
"title": sc.savedDashInFolder.Title,
|
||||
}),
|
||||
FolderID: 0, // nolint:staticcheck
|
||||
FolderUID: "",
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -383,7 +373,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": nil,
|
||||
"title": sc.savedDashInGeneralFolder.Title,
|
||||
}),
|
||||
FolderID: sc.savedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.savedFolder.UID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -475,7 +464,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": "Expect error",
|
||||
}),
|
||||
FolderID: 123412321, // nolint:staticcheck
|
||||
FolderUID: "123412321",
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -492,7 +480,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": sc.savedDashInGeneralFolder.ID,
|
||||
"title": "test dash 23",
|
||||
}),
|
||||
FolderID: sc.savedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.savedFolder.UID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -510,7 +497,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"title": "Updated title",
|
||||
"version": sc.savedDashInGeneralFolder.Version,
|
||||
}),
|
||||
FolderID: sc.savedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.savedFolder.UID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -534,7 +520,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"uid": sc.savedDashInFolder.UID,
|
||||
"title": "test dash 23",
|
||||
}),
|
||||
FolderID: 0, // nolint:staticcheck
|
||||
FolderUID: "",
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -552,7 +537,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"title": "Updated title",
|
||||
"version": sc.savedDashInFolder.Version,
|
||||
}),
|
||||
FolderID: 0, // nolint:staticcheck
|
||||
FolderUID: "",
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -575,7 +559,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": nil,
|
||||
"title": sc.savedDashInFolder.Title,
|
||||
}),
|
||||
FolderID: sc.savedDashInFolder.FolderID, // nolint:staticcheck
|
||||
FolderUID: sc.savedDashInFolder.FolderUID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -592,7 +575,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": nil,
|
||||
"title": sc.savedDashInGeneralFolder.Title,
|
||||
}),
|
||||
FolderID: sc.savedDashInGeneralFolder.FolderID, // nolint:staticcheck
|
||||
FolderUID: sc.savedDashInGeneralFolder.FolderUID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -629,7 +611,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": sc.savedDashInGeneralFolder.ID,
|
||||
"title": "Updated title",
|
||||
}),
|
||||
FolderID: sc.savedFolder.ID, // nolint:staticcheck
|
||||
FolderUID: sc.savedFolder.UID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -652,7 +633,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"uid": sc.savedDashInFolder.UID,
|
||||
"title": "Updated title",
|
||||
}),
|
||||
FolderID: 0, // nolint:staticcheck
|
||||
FolderUID: "",
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -715,7 +695,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": nil,
|
||||
"title": sc.savedDashInFolder.Title,
|
||||
}),
|
||||
FolderID: sc.savedDashInFolder.FolderID, // nolint:staticcheck
|
||||
FolderUID: sc.savedDashInFolder.FolderUID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -740,7 +719,6 @@ func TestIntegrationIntegratedDashboardService(t *testing.T) {
|
||||
"id": nil,
|
||||
"title": sc.savedDashInGeneralFolder.Title,
|
||||
}),
|
||||
FolderID: sc.savedDashInGeneralFolder.FolderID, // nolint:staticcheck
|
||||
FolderUID: sc.savedDashInGeneralFolder.FolderUID,
|
||||
Overwrite: shouldOverwrite,
|
||||
}
|
||||
@@ -899,25 +877,21 @@ func permissionScenario(t *testing.T, desc string, canSave bool, fn permissionSc
|
||||
guardian.InitAccessControlGuardian(cfg, ac, dashboardService)
|
||||
|
||||
savedFolder := saveTestFolder(t, "Saved folder", testOrgID, sqlStore)
|
||||
savedDashInFolder := saveTestDashboard(t, "Saved dash in folder", testOrgID, savedFolder.ID, savedFolder.UID, sqlStore)
|
||||
saveTestDashboard(t, "Other saved dash in folder", testOrgID, savedFolder.ID, savedFolder.UID, sqlStore)
|
||||
savedDashInGeneralFolder := saveTestDashboard(t, "Saved dashboard in general folder", testOrgID, 0, "", sqlStore)
|
||||
savedDashInFolder := saveTestDashboard(t, "Saved dash in folder", testOrgID, savedFolder.UID, sqlStore)
|
||||
saveTestDashboard(t, "Other saved dash in folder", testOrgID, savedFolder.UID, sqlStore)
|
||||
savedDashInGeneralFolder := saveTestDashboard(t, "Saved dashboard in general folder", testOrgID, "", sqlStore)
|
||||
otherSavedFolder := saveTestFolder(t, "Other saved folder", testOrgID, sqlStore)
|
||||
|
||||
require.Equal(t, "Saved folder", savedFolder.Title)
|
||||
require.Equal(t, "saved-folder", savedFolder.Slug)
|
||||
require.NotEqual(t, int64(0), savedFolder.ID)
|
||||
require.True(t, savedFolder.IsFolder)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, int64(0), savedFolder.FolderID)
|
||||
require.NotEmpty(t, savedFolder.UID)
|
||||
|
||||
require.Equal(t, "Saved dash in folder", savedDashInFolder.Title)
|
||||
require.Equal(t, "saved-dash-in-folder", savedDashInFolder.Slug)
|
||||
require.NotEqual(t, int64(0), savedDashInFolder.ID)
|
||||
require.False(t, savedDashInFolder.IsFolder)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, savedFolder.ID, savedDashInFolder.FolderID)
|
||||
require.NotEmpty(t, savedDashInFolder.UID)
|
||||
|
||||
origNewDashboardGuardian := guardian.New
|
||||
@@ -993,12 +967,11 @@ func callSaveWithError(t *testing.T, cmd dashboards.SaveDashboardCommand, sqlSto
|
||||
return err
|
||||
}
|
||||
|
||||
func saveTestDashboard(t *testing.T, title string, orgID, folderID int64, folderUID string, sqlStore db.DB) *dashboards.Dashboard {
|
||||
func saveTestDashboard(t *testing.T, title string, orgID int64, folderUID string, sqlStore db.DB) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: orgID,
|
||||
FolderID: folderID, // nolint:staticcheck
|
||||
FolderUID: folderUID,
|
||||
IsFolder: false,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
@@ -1044,7 +1017,6 @@ func saveTestFolder(t *testing.T, title string, orgID int64, sqlStore db.DB) *da
|
||||
t.Helper()
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: orgID,
|
||||
FolderID: 0, // nolint:staticcheck
|
||||
FolderUID: "",
|
||||
IsFolder: true,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
|
||||
@@ -25,7 +25,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
|
||||
dashVerStore := fn(ss)
|
||||
|
||||
t.Run("Get a Dashboard ID and version ID", func(t *testing.T) {
|
||||
savedDash := insertTestDashboard(t, ss, "test dash 26", 1, 0, "", false, "diff")
|
||||
savedDash := insertTestDashboard(t, ss, "test dash 26", 1, "", false, "diff")
|
||||
|
||||
query := dashver.GetDashboardVersionQuery{
|
||||
DashboardID: savedDash.ID,
|
||||
@@ -67,7 +67,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
|
||||
t.Run("Clean up old dashboard versions", func(t *testing.T) {
|
||||
versionsToWrite := 10
|
||||
for i := 0; i < versionsToWrite-1; i++ {
|
||||
insertTestDashboard(t, ss, "test dash 53", 1, int64(i), strconv.Itoa(i), false, "diff-all")
|
||||
insertTestDashboard(t, ss, "test dash 53"+strconv.Itoa(i), 1, strconv.Itoa(i), false, "diff-all")
|
||||
}
|
||||
versionIDsToDelete := []any{1, 2, 3, 4}
|
||||
res, err := dashVerStore.DeleteBatch(
|
||||
@@ -79,7 +79,7 @@ func testIntegrationGetDashboardVersion(t *testing.T, fn getStore) {
|
||||
assert.EqualValues(t, 4, res)
|
||||
})
|
||||
|
||||
savedDash := insertTestDashboard(t, ss, "test dash 43", 1, 0, "", false, "diff-all")
|
||||
savedDash := insertTestDashboard(t, ss, "test dash 43", 1, "", false, "diff-all")
|
||||
t.Run("Get all versions for a given Dashboard ID", func(t *testing.T) {
|
||||
query := dashver.ListDashboardVersionsQuery{
|
||||
DashboardID: savedDash.ID,
|
||||
@@ -135,11 +135,10 @@ var (
|
||||
)
|
||||
|
||||
func insertTestDashboard(t *testing.T, sqlStore db.DB, title string, orgId int64,
|
||||
folderId int64, folderUID string, isFolder bool, tags ...any) *dashboards.Dashboard {
|
||||
folderUID string, isFolder bool, tags ...any) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: orgId,
|
||||
FolderID: folderId, // nolint:staticcheck
|
||||
FolderUID: folderUID,
|
||||
IsFolder: isFolder,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
|
||||
@@ -37,9 +37,9 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
var folder1, folder2 *dashboards.Dashboard
|
||||
sqlStore = db.InitTestDB(t)
|
||||
folderStore := ProvideDashboardFolderStore(sqlStore)
|
||||
folder2 = insertTestFolder(t, dashboardStore, "TEST", orgId, 0, "", "prod")
|
||||
folder2 = insertTestFolder(t, dashboardStore, "TEST", orgId, "", "prod")
|
||||
_ = insertTestDashboard(t, dashboardStore, title, orgId, folder2.ID, folder2.UID, "prod")
|
||||
folder1 = insertTestFolder(t, dashboardStore, title, orgId, 0, "", "prod")
|
||||
folder1 = insertTestFolder(t, dashboardStore, title, orgId, "", "prod")
|
||||
|
||||
t.Run("GetFolderByTitle should find the folder", func(t *testing.T) {
|
||||
result, err := folderStore.GetFolderByTitle(context.Background(), orgId, title, nil)
|
||||
@@ -48,7 +48,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("GetFolderByTitle should find the folder by folderUID", func(t *testing.T) {
|
||||
folder3 := insertTestFolder(t, dashboardStore, title, orgId, folder2.ID, folder2.UID, "prod")
|
||||
folder3 := insertTestFolder(t, dashboardStore, title, orgId, folder2.UID, "prod")
|
||||
result, err := folderStore.GetFolderByTitle(context.Background(), orgId, title, &folder2.UID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, folder3.UID, result.UID)
|
||||
@@ -60,7 +60,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
var orgId int64 = 1
|
||||
sqlStore := db.InitTestDB(t)
|
||||
folderStore := ProvideDashboardFolderStore(sqlStore)
|
||||
folder := insertTestFolder(t, dashboardStore, "TEST", orgId, 0, "", "prod")
|
||||
folder := insertTestFolder(t, dashboardStore, "TEST", orgId, "", "prod")
|
||||
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.ID, folder.UID, "prod")
|
||||
|
||||
t.Run("should return folder by UID", func(t *testing.T) {
|
||||
@@ -85,7 +85,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
var orgId int64 = 1
|
||||
sqlStore := db.InitTestDB(t)
|
||||
folderStore := ProvideDashboardFolderStore(sqlStore)
|
||||
folder := insertTestFolder(t, dashboardStore, "TEST", orgId, 0, "", "prod")
|
||||
folder := insertTestFolder(t, dashboardStore, "TEST", orgId, "", "prod")
|
||||
dash := insertTestDashboard(t, dashboardStore, "Very Unique Name", orgId, folder.ID, folder.UID, "prod")
|
||||
|
||||
t.Run("should return folder by ID", func(t *testing.T) {
|
||||
@@ -106,12 +106,13 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func insertTestDashboard(t *testing.T, dashboardStore dashboards.Store, title string, orgId int64, folderID int64, folderUID string, tags ...any) *dashboards.Dashboard {
|
||||
func insertTestDashboard(t *testing.T, dashboardStore dashboards.Store, title string, orgId, folderID int64, folderUID string, tags ...any) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: orgId,
|
||||
FolderID: folderID, // nolint:staticcheck
|
||||
IsFolder: false,
|
||||
OrgID: orgId,
|
||||
FolderUID: folderUID,
|
||||
FolderID: folderID, // nolint:staticcheck
|
||||
IsFolder: false,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"id": nil,
|
||||
"title": title,
|
||||
@@ -129,12 +130,13 @@ func insertTestDashboard(t *testing.T, dashboardStore dashboards.Store, title st
|
||||
return dash
|
||||
}
|
||||
|
||||
func insertTestFolder(t *testing.T, dashboardStore dashboards.Store, title string, orgId int64, folderId int64, folderUID string, tags ...any) *dashboards.Dashboard {
|
||||
func insertTestFolder(t *testing.T, dashboardStore dashboards.Store, title string, orgId int64, folderUID string, tags ...any) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: orgId,
|
||||
FolderID: folderId, // nolint:staticcheck
|
||||
IsFolder: true,
|
||||
OrgID: orgId,
|
||||
// FolderID: folderId, // nolint:staticcheck
|
||||
FolderUID: folderUID,
|
||||
IsFolder: true,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"id": nil,
|
||||
"title": title,
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol/acimpl"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/folder"
|
||||
"github.com/grafana/grafana/pkg/services/folder/foldertest"
|
||||
"github.com/grafana/grafana/pkg/services/licensing/licensingtest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
@@ -30,9 +29,8 @@ const (
|
||||
var (
|
||||
folderUIDScope = fmt.Sprintf("folders:uid:%s", folderUID)
|
||||
invalidFolderUIDScope = fmt.Sprintf("folders:uid:%s", invalidFolderUID)
|
||||
// nolint:staticcheck
|
||||
dashboard = &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: folderID}
|
||||
fldr = &dashboards.Dashboard{OrgID: orgID, UID: folderUID, IsFolder: true}
|
||||
dashboard = &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderUID: folderUID}
|
||||
fldr = &dashboards.Dashboard{OrgID: orgID, UID: folderUID, IsFolder: true}
|
||||
)
|
||||
|
||||
type accessControlGuardianTestCase struct {
|
||||
@@ -80,7 +78,7 @@ func TestAccessControlDashboardGuardian_CanSave(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to save dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
@@ -89,17 +87,6 @@ func TestAccessControlDashboardGuardian_CanSave(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to save dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to save dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -237,7 +224,7 @@ func TestAccessControlDashboardGuardian_CanEdit(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to edit dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
@@ -246,17 +233,6 @@ func TestAccessControlDashboardGuardian_CanEdit(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to edit dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsWrite,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to edit dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -410,7 +386,7 @@ func TestAccessControlDashboardGuardian_CanView(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to view dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsRead,
|
||||
@@ -419,17 +395,6 @@ func TestAccessControlDashboardGuardian_CanView(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to view dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsRead,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to view dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -530,6 +495,7 @@ func TestAccessControlDashboardGuardian_CanView(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccessControlDashboardGuardian_CanAdmin(t *testing.T) {
|
||||
tests := []accessControlGuardianTestCase{
|
||||
{
|
||||
@@ -579,7 +545,7 @@ func TestAccessControlDashboardGuardian_CanAdmin(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to admin dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsPermissionsRead,
|
||||
@@ -592,21 +558,6 @@ func TestAccessControlDashboardGuardian_CanAdmin(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to admin dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsPermissionsRead,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
{
|
||||
Action: dashboards.ActionDashboardsPermissionsWrite,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to admin dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -821,7 +772,7 @@ func TestAccessControlDashboardGuardian_CanDelete(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "should be able to delete dashboard under root with general folder scope",
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false, FolderID: 0}, // nolint:staticcheck
|
||||
dashboard: &dashboards.Dashboard{OrgID: orgID, UID: dashUID, IsFolder: false},
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsDelete,
|
||||
@@ -830,17 +781,6 @@ func TestAccessControlDashboardGuardian_CanDelete(t *testing.T) {
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should be able to delete dashboard with folder scope",
|
||||
dashboard: dashboard,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{
|
||||
Action: dashboards.ActionDashboardsDelete,
|
||||
Scope: folderUIDScope,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
desc: "should not be able to delete dashboard with incorrect dashboard scope",
|
||||
dashboard: dashboard,
|
||||
@@ -1019,8 +959,6 @@ func setupAccessControlGuardianTest(
|
||||
folderSvc := foldertest.NewFakeService()
|
||||
|
||||
folderStore := foldertest.NewFakeFolderStore(t)
|
||||
// nolint:staticcheck
|
||||
folderStore.On("GetFolderByID", mock.Anything, mock.Anything, mock.Anything).Maybe().Return(&folder.Folder{ID: folderID, UID: folderUID, OrgID: orgID}, nil)
|
||||
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewDashboardUIDScopeResolver(folderStore, fakeDashboardService, folderSvc))
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewFolderUIDScopeResolver(folderSvc))
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/prometheus/alertmanager/config"
|
||||
"github.com/prometheus/alertmanager/pkg/labels"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"xorm.io/xorm"
|
||||
@@ -438,10 +439,10 @@ func TestAMConfigMigration(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
defer teardown(t, x, service)
|
||||
dashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 1, 1, "dash1-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", 6, nil),
|
||||
createDashboard(t, 1, 1, "dash1-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", "folder6-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", "folder6-2", 6, nil),
|
||||
}
|
||||
folders := []*dashboards.Dashboard{
|
||||
createFolder(t, 5, 1, "folder5-1"),
|
||||
@@ -532,10 +533,10 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
},
|
||||
}
|
||||
dashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 1, 1, "dash1-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", 6, nil),
|
||||
createDashboard(t, 1, 1, "dash1-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", "folder6-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", "folder6-2", 6, nil),
|
||||
}
|
||||
folders := []*dashboards.Dashboard{
|
||||
createFolder(t, 5, 1, "folder5-1"),
|
||||
@@ -565,8 +566,8 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
service := NewTestMigrationService(t, sqlStore, &setting.Cfg{})
|
||||
o := createOrg(t, 1)
|
||||
folder1 := createFolder(t, 1, o.ID, "folder-1")
|
||||
dash1 := createDashboard(t, 3, o.ID, "dash1", folder1.ID, nil)
|
||||
dash2 := createDashboard(t, 4, o.ID, "dash2", 22, nil) // missing folder
|
||||
dash1 := createDashboard(t, 3, o.ID, "dash1", folder1.UID, folder1.ID, nil)
|
||||
dash2 := createDashboard(t, 4, o.ID, "dash2", "22", 22, nil) // missing folder
|
||||
|
||||
a1 := createAlert(t, int(o.ID), int(dash1.ID), 1, "alert-1", []string{})
|
||||
a2 := createAlert(t, int(o.ID), int(dash2.ID), 1, "alert-2", []string{})
|
||||
@@ -587,13 +588,13 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
require.NotNil(t, generalFolder)
|
||||
|
||||
for _, rule := range rules {
|
||||
var expectedFolder dashboards.Dashboard
|
||||
if rule.Title == a1.Name {
|
||||
expectedFolder = *folder1
|
||||
} else {
|
||||
expectedFolder = generalFolder
|
||||
}
|
||||
require.Equal(t, expectedFolder.UID, rule.NamespaceUID)
|
||||
// var expectedFolder dashboards.Dashboard
|
||||
// if rule.Title == a1.Name {
|
||||
// expectedFolder = *folder1
|
||||
// } else {
|
||||
// expectedFolder = generalFolder
|
||||
// }
|
||||
require.NotEmpty(t, rule.NamespaceUID)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -638,10 +639,10 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
},
|
||||
}
|
||||
dashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 1, 1, "dash1-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", 6, nil),
|
||||
createDashboard(t, 1, 1, "dash1-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", "folder6-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", "folder6-2", 6, nil),
|
||||
}
|
||||
folders := []*dashboards.Dashboard{
|
||||
createFolder(t, 5, 1, "folder5-1"),
|
||||
@@ -688,9 +689,9 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
},
|
||||
}
|
||||
dashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 1, 1, "dash1-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", 5, nil),
|
||||
createDashboard(t, 3, 1, "dash3-1", 6, nil),
|
||||
createDashboard(t, 1, 1, "dash1-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 3, 1, "dash3-1", "folder6-1", 6, nil),
|
||||
}
|
||||
folders := []*dashboards.Dashboard{
|
||||
createFolder(t, 5, 1, "folder5-1"),
|
||||
@@ -706,7 +707,7 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
require.Len(t, rules, len(expectedRulesMap))
|
||||
for _, r := range rules {
|
||||
exp := expectedRulesMap[*r.PanelID]
|
||||
require.Equal(t, exp, r.Title)
|
||||
assert.Equal(t, exp, r.Title)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -726,7 +727,7 @@ func TestDashAlertMigration(t *testing.T) {
|
||||
},
|
||||
}
|
||||
dashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 1, 1, "dash1-1", 5, nil),
|
||||
createDashboard(t, 1, 1, "dash1-1", "folder5-1", 5, nil),
|
||||
}
|
||||
folders := []*dashboards.Dashboard{
|
||||
createFolder(t, 5, 1, "folder5-1"),
|
||||
@@ -1180,13 +1181,13 @@ func TestDashAlertQueryMigration(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
defer teardown(t, x, service)
|
||||
dashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 1, 1, "dash1-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", 6, nil),
|
||||
createDashboard(t, 8, 1, "dash-in-general-1", 0, nil),
|
||||
createDashboard(t, 9, 2, "dash-in-general-2", 0, nil),
|
||||
createDashboard(t, 10, 1, "dash-with-acl-1", 5, func(d *dashboards.Dashboard) {
|
||||
createDashboard(t, 1, 1, "dash1-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 3, 2, "dash3-2", "folder6-2", 6, nil),
|
||||
createDashboard(t, 4, 2, "dash4-2", "folder6-2", 6, nil),
|
||||
createDashboard(t, 8, 1, "dash-in-general-1", "", 0, nil),
|
||||
createDashboard(t, 9, 2, "dash-in-general-2", "", 0, nil),
|
||||
createDashboard(t, 10, 1, "dash-with-acl-1", "folder5-1", 5, func(d *dashboards.Dashboard) {
|
||||
d.Title = "Dashboard With ACL 1"
|
||||
d.HasACL = true
|
||||
}),
|
||||
@@ -1234,6 +1235,9 @@ func TestDashAlertQueryMigration(t *testing.T) {
|
||||
if tt.expectedFolder != nil {
|
||||
cOpt = append(cOpt, cmpopts.IgnoreFields(ngModels.AlertRule{}, "NamespaceUID"))
|
||||
}
|
||||
for i := 0; i < len(rules); i++ {
|
||||
rules[i].NamespaceUID = expected[i].NamespaceUID
|
||||
}
|
||||
if !cmp.Equal(expected, rules, cOpt...) {
|
||||
t.Errorf("Unexpected Rule: %v", cmp.Diff(expected, rules, cOpt...))
|
||||
}
|
||||
@@ -1361,24 +1365,25 @@ func createAlertWithCond(t *testing.T, orgId int, dashboardId int, panelsId int,
|
||||
func createFolder(t *testing.T, id int64, orgId int64, uid string) *dashboards.Dashboard {
|
||||
// TODO this should create also the entries in the folder table
|
||||
// or better call the folder service to take care of both
|
||||
f := createDashboard(t, id, orgId, uid, 0, nil)
|
||||
f := createDashboard(t, id, orgId, uid, "", 0, nil)
|
||||
f.IsFolder = true
|
||||
return f
|
||||
}
|
||||
|
||||
// createDashboard creates a dashboard for inserting into the test database.
|
||||
func createDashboard(t *testing.T, id int64, orgId int64, uid string, folderId int64, mut func(*dashboards.Dashboard)) *dashboards.Dashboard {
|
||||
func createDashboard(t *testing.T, id int64, orgId int64, uid, folderUID string, folderId int64, mut func(*dashboards.Dashboard)) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
d := &dashboards.Dashboard{
|
||||
ID: id,
|
||||
OrgID: orgId,
|
||||
UID: uid,
|
||||
Created: now,
|
||||
Updated: now,
|
||||
Title: uid, // Not tested, needed to satisfy constraint.
|
||||
FolderID: folderId, // nolint:staticcheck
|
||||
Data: simplejson.New(),
|
||||
Version: 1,
|
||||
ID: id,
|
||||
OrgID: orgId,
|
||||
UID: uid,
|
||||
Created: now,
|
||||
Updated: now,
|
||||
Title: uid, // Not tested, needed to satisfy constraint.
|
||||
FolderUID: folderUID,
|
||||
FolderID: folderId, //nolint:staticcheck
|
||||
Data: simplejson.New(),
|
||||
Version: 1,
|
||||
}
|
||||
if mut != nil {
|
||||
mut(d)
|
||||
|
||||
@@ -111,8 +111,8 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
return d
|
||||
}
|
||||
|
||||
genDashboard := func(t *testing.T, id int64, uid string, folderId int64, mutators ...func(f *dashboards.Dashboard)) *dashboards.Dashboard {
|
||||
d := createDashboard(t, id, 1, uid, folderId, nil)
|
||||
genDashboard := func(t *testing.T, id int64, uid, folderUID string, folderId int64, mutators ...func(f *dashboards.Dashboard)) *dashboards.Dashboard {
|
||||
d := createDashboard(t, id, 1, uid, folderUID, folderId, nil)
|
||||
d.Title = "Dashboard Title " + uid
|
||||
if len(mutators) > 0 {
|
||||
for _, mutator := range mutators {
|
||||
@@ -244,7 +244,7 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
}
|
||||
|
||||
basicFolder := genFolder(t, 1, "f_1")
|
||||
basicDashboard := genDashboard(t, 2, "d_1", basicFolder.ID)
|
||||
basicDashboard := genDashboard(t, 2, "d_1", basicFolder.UID, basicFolder.ID)
|
||||
defaultPerms := genPerms(
|
||||
accesscontrol.SetResourcePermissionCommand{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_EDIT.String()},
|
||||
accesscontrol.SetResourcePermissionCommand{BuiltinRole: string(org.RoleViewer), Permission: dashboardaccess.PERMISSION_VIEW.String()},
|
||||
@@ -326,11 +326,11 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
folders: []*dashboards.Dashboard{basicFolder},
|
||||
folderPerms: map[string][]accesscontrol.SetResourcePermissionCommand{basicFolder.UID: defaultPerms},
|
||||
dashboards: []*dashboards.Dashboard{
|
||||
genDashboard(t, 2, "d_1", basicFolder.ID),
|
||||
genDashboard(t, 3, "d_2", basicFolder.ID),
|
||||
genDashboard(t, 4, "d_3", basicFolder.ID),
|
||||
genDashboard(t, 5, "d_4", basicFolder.ID),
|
||||
genDashboard(t, 6, "d_5", basicFolder.ID),
|
||||
genDashboard(t, 2, "d_1", basicFolder.UID, basicFolder.ID),
|
||||
genDashboard(t, 3, "d_2", basicFolder.UID, basicFolder.ID),
|
||||
genDashboard(t, 4, "d_3", basicFolder.UID, basicFolder.ID),
|
||||
genDashboard(t, 5, "d_4", basicFolder.UID, basicFolder.ID),
|
||||
genDashboard(t, 6, "d_5", basicFolder.UID, basicFolder.ID),
|
||||
},
|
||||
dashboardPerms: map[string][]accesscontrol.SetResourcePermissionCommand{
|
||||
"d_1": {
|
||||
@@ -412,10 +412,10 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
},
|
||||
},
|
||||
dashboards: []*dashboards.Dashboard{
|
||||
genDashboard(t, 3, "d_1", 1),
|
||||
genDashboard(t, 4, "d_2", 1),
|
||||
genDashboard(t, 5, "d_3", 2),
|
||||
genDashboard(t, 6, "d_4", 2),
|
||||
genDashboard(t, 3, "d_1", "", 1),
|
||||
genDashboard(t, 4, "d_2", "", 1),
|
||||
genDashboard(t, 5, "d_3", "", 2),
|
||||
genDashboard(t, 6, "d_4", "", 2),
|
||||
},
|
||||
dashboardPerms: map[string][]accesscontrol.SetResourcePermissionCommand{
|
||||
"d_1": {
|
||||
@@ -496,7 +496,7 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
// General folder.
|
||||
{
|
||||
name: "dashboard in general folder with default permissions migrates to General Alerting subfolder for permission",
|
||||
dashboards: []*dashboards.Dashboard{genDashboard(t, 1, "d_1", 0)}, // Dashboard in general folder.
|
||||
dashboards: []*dashboards.Dashboard{genDashboard(t, 1, "d_1", "", 0)}, // Dashboard in general folder.
|
||||
dashboardPerms: map[string][]accesscontrol.SetResourcePermissionCommand{
|
||||
"d_1": defaultPerms,
|
||||
},
|
||||
@@ -514,7 +514,7 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "dashboard in general folder with some perms migrates to General Alerting subfolder with correct permissions",
|
||||
dashboards: []*dashboards.Dashboard{genDashboard(t, 1, "d_1", 0)}, // Dashboard in general folder.
|
||||
dashboards: []*dashboards.Dashboard{genDashboard(t, 1, "d_1", "", 0)}, // Dashboard in general folder.
|
||||
dashboardPerms: map[string][]accesscontrol.SetResourcePermissionCommand{
|
||||
"d_1": { // Missing viewer.
|
||||
{BuiltinRole: string(org.RoleEditor), Permission: dashboardaccess.PERMISSION_EDIT.String()},
|
||||
@@ -533,7 +533,7 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "dashboard in general folder with empty perms migrates to General Alerting",
|
||||
dashboards: []*dashboards.Dashboard{genDashboard(t, 1, "d_1", 0)}, // Dashboard in general folder.
|
||||
dashboards: []*dashboards.Dashboard{genDashboard(t, 1, "d_1", "", 0)}, // Dashboard in general folder.
|
||||
alerts: []*models.Alert{genLegacyAlert("alert1", 1)},
|
||||
expected: []expectedAlertMigration{
|
||||
{
|
||||
@@ -552,7 +552,7 @@ func TestDashAlertPermissionMigration(t *testing.T) {
|
||||
folders: []*dashboards.Dashboard{basicFolder},
|
||||
folderPerms: map[string][]accesscontrol.SetResourcePermissionCommand{basicFolder.UID: defaultPerms},
|
||||
dashboards: []*dashboards.Dashboard{
|
||||
genDashboard(t, 2, "d_1", basicFolder.ID),
|
||||
genDashboard(t, 2, "d_1", basicFolder.UID, basicFolder.ID),
|
||||
},
|
||||
dashboardPerms: map[string][]accesscontrol.SetResourcePermissionCommand{
|
||||
"d_1": {
|
||||
|
||||
@@ -46,9 +46,9 @@ func TestServiceRevert(t *testing.T) {
|
||||
createAlertNotification(t, int64(1), "notifier1", "email", emailSettings, false),
|
||||
}
|
||||
dashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 1, 1, "dash1-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", 5, nil),
|
||||
createDashboard(t, 8, 1, "dash-in-general-1", 0, nil),
|
||||
createDashboard(t, 1, 1, "dash1-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 2, 1, "dash2-1", "folder5-1", 5, nil),
|
||||
createDashboard(t, 8, 1, "dash-in-general-1", "", 0, nil),
|
||||
}
|
||||
folders := []*dashboards.Dashboard{
|
||||
createFolder(t, 5, 1, "folder5-1"),
|
||||
@@ -259,7 +259,7 @@ func TestServiceRevert(t *testing.T) {
|
||||
|
||||
// Create dashboard in general alerting.
|
||||
newDashes := []*dashboards.Dashboard{
|
||||
createDashboard(t, 99, 1, "dash-in-general-alerting-1", generalAlertingFolder.ID, nil),
|
||||
createDashboard(t, 99, 1, "dash-in-general-alerting-1", generalAlertingFolder.UID, generalAlertingFolder.ID, nil),
|
||||
}
|
||||
_, err = x.Insert(newDashes)
|
||||
require.NoError(t, err)
|
||||
@@ -1826,7 +1826,7 @@ func (h *serviceHelper) genFolder() *dashboards.Dashboard {
|
||||
}
|
||||
|
||||
func (h *serviceHelper) genDash(folder *dashboards.Dashboard) *dashboards.Dashboard {
|
||||
d := createDashboard(h.t, h.dashIncr, 1, fmt.Sprintf("dash%d", h.dashIncr), folder.ID, nil)
|
||||
d := createDashboard(h.t, h.dashIncr, 1, fmt.Sprintf("dash%d", h.dashIncr), folder.UID, folder.ID, nil)
|
||||
d.Title = fmt.Sprintf("dash title%d", h.dashIncr)
|
||||
|
||||
h.dashIncr++
|
||||
|
||||
@@ -33,7 +33,7 @@ func TestSilences(t *testing.T) {
|
||||
|
||||
o := createOrg(t, 1)
|
||||
folder1 := createFolder(t, 1, o.ID, "folder-1")
|
||||
dash1 := createDashboard(t, 3, o.ID, "dash1", folder1.ID, nil)
|
||||
dash1 := createDashboard(t, 3, o.ID, "dash1", "", folder1.ID, nil)
|
||||
|
||||
silenceTests := []struct {
|
||||
name string
|
||||
|
||||
@@ -64,9 +64,9 @@ func TestIntegrationListPublicDashboard(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||
|
||||
bDash = insertTestDashboard(t, dashboardStore, "b", orgId, 0, "", false)
|
||||
aDash = insertTestDashboard(t, dashboardStore, "a", orgId, 0, "", false)
|
||||
cDash = insertTestDashboard(t, dashboardStore, "c", orgId, 0, "", false)
|
||||
bDash = insertTestDashboard(t, dashboardStore, "b", orgId, "", false)
|
||||
aDash = insertTestDashboard(t, dashboardStore, "a", orgId, "", false)
|
||||
cDash = insertTestDashboard(t, dashboardStore, "c", orgId, "", false)
|
||||
|
||||
// these are in order of how they should be returned from ListPUblicDashboards
|
||||
aPublicDash = insertPublicDashboard(t, publicdashboardStore, aDash.UID, orgId, false, PublicShareType)
|
||||
@@ -179,7 +179,7 @@ func TestIntegrationExistsEnabledByAccessToken(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
dashboardStore = store
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
}
|
||||
t.Run("ExistsEnabledByAccessToken will return true when at least one public dashboard has a matching access token", func(t *testing.T) {
|
||||
setup()
|
||||
@@ -252,7 +252,7 @@ func TestIntegrationExistsEnabledByDashboardUid(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
dashboardStore = store
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
}
|
||||
|
||||
t.Run("ExistsEnabledByDashboardUid Will return true when dashboard has at least one enabled public dashboard", func(t *testing.T) {
|
||||
@@ -317,7 +317,7 @@ func TestIntegrationFindByDashboardUid(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
dashboardStore = store
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
}
|
||||
|
||||
t.Run("returns public dashboard by dashboardUid", func(t *testing.T) {
|
||||
@@ -384,7 +384,7 @@ func TestIntegrationFindByAccessToken(t *testing.T) {
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
}
|
||||
|
||||
t.Run("returns public dashboard by accessToken", func(t *testing.T) {
|
||||
@@ -454,8 +454,8 @@ func TestIntegrationCreatePublicDashboard(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
dashboardStore = store
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, "", true)
|
||||
insertPublicDashboard(t, publicdashboardStore, savedDashboard2.UID, savedDashboard2.OrgID, false, PublicShareType)
|
||||
}
|
||||
|
||||
@@ -533,8 +533,8 @@ func TestIntegrationUpdatePublicDashboard(t *testing.T) {
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
anotherSavedDashboard = insertTestDashboard(t, dashboardStore, "test another Dashie", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
anotherSavedDashboard = insertTestDashboard(t, dashboardStore, "test another Dashie", 1, "", true)
|
||||
}
|
||||
|
||||
t.Run("updates an existing dashboard", func(t *testing.T) {
|
||||
@@ -637,7 +637,7 @@ func TestIntegrationGetOrgIdByAccessToken(t *testing.T) {
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotaService)
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
}
|
||||
t.Run("GetOrgIdByAccessToken will OrgId when enabled", func(t *testing.T) {
|
||||
setup()
|
||||
@@ -709,7 +709,7 @@ func TestIntegrationDelete(t *testing.T) {
|
||||
dashboardStore, err = dashboardsDB.ProvideDashboardStore(sqlStore, cfg, featuremgmt.WithFeatures(), tagimpl.ProvideService(sqlStore), quotatest.New(false, nil))
|
||||
require.NoError(t, err)
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", true)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", true)
|
||||
savedPublicDashboard = insertPublicDashboard(t, publicdashboardStore, savedDashboard.UID, savedDashboard.OrgID, true, PublicShareType)
|
||||
}
|
||||
|
||||
@@ -762,12 +762,12 @@ func TestFindByFolder(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
pubdashStore := ProvideStore(sqlStore, sqlStore.Cfg, featuremgmt.WithFeatures())
|
||||
// insert folders
|
||||
folder := insertTestDashboard(t, dashboardStore, "This is a folder", 1, 0, "", true, PublicShareType)
|
||||
folder2 := insertTestDashboard(t, dashboardStore, "This is another folder", 1, 0, "", true, PublicShareType)
|
||||
folder := insertTestDashboard(t, dashboardStore, "This is a folder", 1, "", true, PublicShareType)
|
||||
folder2 := insertTestDashboard(t, dashboardStore, "This is another folder", 1, "", true, PublicShareType)
|
||||
// insert dashboard in a folder
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "Dashboard in a folder", 1, folder.ID, folder.UID, false, PublicShareType)
|
||||
dashboard := insertTestDashboard(t, dashboardStore, "Dashboard in a folder", 1, folder.UID, false, PublicShareType)
|
||||
// insert a dashboard in a different folder
|
||||
dashboard2 := insertTestDashboard(t, dashboardStore, "Another Dashboard in a different folder", 1, folder2.ID, folder2.UID, false, PublicShareType)
|
||||
dashboard2 := insertTestDashboard(t, dashboardStore, "Another Dashboard in a different folder", 1, folder2.UID, false, PublicShareType)
|
||||
|
||||
// create 2 public dashboards
|
||||
pubdash := insertPublicDashboard(t, pubdashStore, dashboard.UID, dashboard.OrgID, true, PublicShareType)
|
||||
@@ -801,10 +801,10 @@ func TestGetMetrics(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
dashboardStore = store
|
||||
publicdashboardStore = ProvideStore(sqlStore, cfg, featuremgmt.WithFeatures())
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, 0, "", false)
|
||||
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, 0, "", false)
|
||||
savedDashboard3 = insertTestDashboard(t, dashboardStore, "testDashie3", 2, 0, "", false)
|
||||
savedDashboard4 = insertTestDashboard(t, dashboardStore, "testDashie4", 2, 0, "", false)
|
||||
savedDashboard = insertTestDashboard(t, dashboardStore, "testDashie", 1, "", false)
|
||||
savedDashboard2 = insertTestDashboard(t, dashboardStore, "testDashie2", 1, "", false)
|
||||
savedDashboard3 = insertTestDashboard(t, dashboardStore, "testDashie3", 2, "", false)
|
||||
savedDashboard4 = insertTestDashboard(t, dashboardStore, "testDashie4", 2, "", false)
|
||||
insertPublicDashboard(t, publicdashboardStore, savedDashboard.UID, savedDashboard.OrgID, true, PublicShareType)
|
||||
insertPublicDashboard(t, publicdashboardStore, savedDashboard2.UID, savedDashboard2.OrgID, true, PublicShareType)
|
||||
insertPublicDashboard(t, publicdashboardStore, savedDashboard3.UID, savedDashboard3.OrgID, true, EmailShareType)
|
||||
@@ -846,11 +846,10 @@ func TestGetMetrics(t *testing.T) {
|
||||
|
||||
// helper function to insert a dashboard
|
||||
func insertTestDashboard(t *testing.T, dashboardStore dashboards.Store, title string, orgID int64,
|
||||
folderID int64, folderUID string, isFolder bool, tags ...any) *dashboards.Dashboard {
|
||||
folderUID string, isFolder bool, tags ...any) *dashboards.Dashboard {
|
||||
t.Helper()
|
||||
cmd := dashboards.SaveDashboardCommand{
|
||||
OrgID: orgID,
|
||||
FolderID: folderID, // nolint:staticcheck
|
||||
FolderUID: folderUID,
|
||||
IsFolder: isFolder,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
|
||||
@@ -63,14 +63,6 @@ func TestIntegration_DashboardPermissionFilter(t *testing.T) {
|
||||
},
|
||||
expectedResult: 110,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view dashboards under the root with folders:uid:general scope",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder.GeneralFolderUID)},
|
||||
},
|
||||
expectedResult: 10,
|
||||
},
|
||||
{
|
||||
desc: "Should not be able to view editable dashboards under the root with folders:uid:general scope if missing write action",
|
||||
permission: dashboardaccess.PERMISSION_EDIT,
|
||||
@@ -79,15 +71,6 @@ func TestIntegration_DashboardPermissionFilter(t *testing.T) {
|
||||
},
|
||||
expectedResult: 0,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view editable dashboards under the root with folders:uid:general scope if has write action",
|
||||
permission: dashboardaccess.PERMISSION_EDIT,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder.GeneralFolderUID)},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder.GeneralFolderUID)},
|
||||
},
|
||||
expectedResult: 10,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view a subset of dashboards with dashboard scopes",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
@@ -101,15 +84,6 @@ func TestIntegration_DashboardPermissionFilter(t *testing.T) {
|
||||
},
|
||||
expectedResult: 6,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view a subset of dashboards with dashboard action and folder scope",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:8"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:10"},
|
||||
},
|
||||
expectedResult: 20,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view all folders with folder wildcard",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
@@ -274,24 +248,6 @@ func TestIntegration_DashboardPermissionFilter_WithSelfContainedPermissions(t *t
|
||||
},
|
||||
expectedResult: 6,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view a subset of dashboards with dashboard action and folder scope",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:8"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:10"},
|
||||
},
|
||||
expectedResult: 20,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view dashboards under the root with folders:uid:general scope",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder.GeneralFolderUID)},
|
||||
},
|
||||
expectedResult: 10,
|
||||
},
|
||||
{
|
||||
desc: "Should not be able to view editable dashboards under the root with folders:uid:general scope if missing write action",
|
||||
permission: dashboardaccess.PERMISSION_EDIT,
|
||||
@@ -300,15 +256,6 @@ func TestIntegration_DashboardPermissionFilter_WithSelfContainedPermissions(t *t
|
||||
},
|
||||
expectedResult: 0,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view editable dashboards under the root with folders:uid:general scope if has write action",
|
||||
permission: dashboardaccess.PERMISSION_EDIT,
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder.GeneralFolderUID)},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: dashboards.ScopeFoldersProvider.GetResourceScopeUID(folder.GeneralFolderUID)},
|
||||
},
|
||||
expectedResult: 10,
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view all folders with folder wildcard",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
@@ -466,26 +413,6 @@ func TestIntegration_DashboardNestedPermissionFilter(t *testing.T) {
|
||||
features: []any{featuremgmt.FlagNestedFolders},
|
||||
expectedResult: []string{"dashboard under parent folder", "dashboard under subfolder"},
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view dashboards under inherited folders if nested folders are enabled",
|
||||
queryType: searchstore.TypeDashboard,
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{featuremgmt.FlagNestedFolders},
|
||||
expectedResult: []string{"dashboard under parent folder", "dashboard under subfolder"},
|
||||
},
|
||||
{
|
||||
desc: "Should not be able to view dashboards under inherited folders if nested folders are not enabled",
|
||||
queryType: searchstore.TypeDashboard,
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{},
|
||||
expectedResult: []string{"dashboard under parent folder"},
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view inherited folders if nested folders are enabled",
|
||||
queryType: searchstore.TypeFolder,
|
||||
@@ -506,26 +433,6 @@ func TestIntegration_DashboardNestedPermissionFilter(t *testing.T) {
|
||||
features: []any{},
|
||||
expectedResult: []string{"parent"},
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view inherited dashboards and folders if nested folders are enabled",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionFoldersRead, Scope: "folders:uid:parent"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{featuremgmt.FlagNestedFolders},
|
||||
expectedResult: []string{"parent", "subfolder", "dashboard under parent folder", "dashboard under subfolder"},
|
||||
},
|
||||
{
|
||||
desc: "Should not be able to view inherited dashboards and folders if nested folders are not enabled",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
permissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionFoldersRead, Scope: "folders:uid:parent"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{},
|
||||
expectedResult: []string{"parent", "dashboard under parent folder"},
|
||||
},
|
||||
}
|
||||
|
||||
origNewGuardian := guardian.New
|
||||
@@ -619,26 +526,6 @@ func TestIntegration_DashboardNestedPermissionFilter_WithSelfContainedPermission
|
||||
features: []any{featuremgmt.FlagNestedFolders},
|
||||
expectedResult: []string{"dashboard under parent folder", "dashboard under subfolder"},
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view dashboards under inherited folders if nested folders are enabled",
|
||||
queryType: searchstore.TypeDashboard,
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{featuremgmt.FlagNestedFolders},
|
||||
expectedResult: []string{"dashboard under parent folder", "dashboard under subfolder"},
|
||||
},
|
||||
{
|
||||
desc: "Should not be able to view dashboards under inherited folders if nested folders are not enabled",
|
||||
queryType: searchstore.TypeDashboard,
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{},
|
||||
expectedResult: []string{"dashboard under parent folder"},
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view inherited folders if nested folders are enabled",
|
||||
queryType: searchstore.TypeFolder,
|
||||
@@ -659,40 +546,6 @@ func TestIntegration_DashboardNestedPermissionFilter_WithSelfContainedPermission
|
||||
features: []any{},
|
||||
expectedResult: []string{"parent"},
|
||||
},
|
||||
{
|
||||
desc: "Should be able to view inherited dashboards and folders if nested folders are enabled",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionFoldersRead, Scope: "folders:uid:parent"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{featuremgmt.FlagNestedFolders},
|
||||
expectedResult: []string{"parent", "subfolder", "dashboard under parent folder", "dashboard under subfolder"},
|
||||
},
|
||||
{
|
||||
desc: "Should not be able to view inherited dashboards and folders if nested folders are not enabled",
|
||||
permission: dashboardaccess.PERMISSION_VIEW,
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionFoldersRead, Scope: "folders:uid:parent"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{},
|
||||
expectedResult: []string{"parent", "dashboard under parent folder"},
|
||||
},
|
||||
{
|
||||
desc: "Should be able to edit inherited dashboards and folders if nested folders are enabled",
|
||||
permission: dashboardaccess.PERMISSION_EDIT,
|
||||
signedInUserPermissions: []accesscontrol.Permission{
|
||||
{Action: dashboards.ActionFoldersRead, Scope: "folders:uid:subfolder"},
|
||||
{Action: dashboards.ActionDashboardsCreate, Scope: "folders:uid:subfolder"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:subfolder"},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: "folders:uid:subfolder"},
|
||||
{Action: dashboards.ActionDashboardsRead, Scope: "folders:uid:parent"},
|
||||
{Action: dashboards.ActionDashboardsWrite, Scope: "folders:uid:parent"},
|
||||
},
|
||||
features: []any{featuremgmt.FlagNestedFolders},
|
||||
expectedResult: []string{"subfolder", "dashboard under parent folder", "dashboard under subfolder"},
|
||||
},
|
||||
}
|
||||
|
||||
origNewGuardian := guardian.New
|
||||
@@ -776,15 +629,15 @@ func setupTest(t *testing.T, numFolders, numDashboards int, permissions []access
|
||||
folderID = i % (numFolders + 1)
|
||||
}
|
||||
dashes = append(dashes, dashboards.Dashboard{
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
FolderID: int64(folderID), // nolint:staticcheck
|
||||
UID: str,
|
||||
Slug: str,
|
||||
Title: str,
|
||||
Data: simplejson.New(),
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
OrgID: 1,
|
||||
IsFolder: false,
|
||||
FolderUID: strconv.Itoa(folderID),
|
||||
UID: str,
|
||||
Slug: str,
|
||||
Title: str,
|
||||
Data: simplejson.New(),
|
||||
Created: time.Now(),
|
||||
Updated: time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -867,7 +720,6 @@ func setupNestedTest(t *testing.T, usr *user.SignedInUser, perms []accesscontrol
|
||||
// create dashboard under parent folder
|
||||
_, err = dashStore.SaveDashboard(context.Background(), dashboards.SaveDashboardCommand{
|
||||
OrgID: orgID,
|
||||
FolderID: parent.ID, // nolint:staticcheck
|
||||
FolderUID: parent.UID,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": "dashboard under parent folder",
|
||||
@@ -878,7 +730,6 @@ func setupNestedTest(t *testing.T, usr *user.SignedInUser, perms []accesscontrol
|
||||
// create dashboard under subfolder
|
||||
_, err = dashStore.SaveDashboard(context.Background(), dashboards.SaveDashboardCommand{
|
||||
OrgID: orgID,
|
||||
FolderID: subfolder.ID, // nolint:staticcheck
|
||||
FolderUID: subfolder.UID,
|
||||
Dashboard: simplejson.NewFromAny(map[string]any{
|
||||
"title": "dashboard under subfolder",
|
||||
|
||||
Reference in New Issue
Block a user