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{
|
||||
|
||||
Reference in New Issue
Block a user