dashboards: remove unused function from dashboard service (#103104)
remove unused function from dashboard service
This commit is contained in:
@@ -30,7 +30,6 @@ type DashboardService interface {
|
||||
SaveDashboard(ctx context.Context, dto *SaveDashboardDTO, allowUiUpdate bool) (*Dashboard, error)
|
||||
SearchDashboards(ctx context.Context, query *FindPersistedDashboardsQuery) (model.HitList, error)
|
||||
CountInFolders(ctx context.Context, orgID int64, folderUIDs []string, user identity.Requester) (int64, error)
|
||||
GetDashboardsSharedWithUser(ctx context.Context, user identity.Requester) ([]*DashboardRef, error)
|
||||
GetAllDashboards(ctx context.Context) ([]*Dashboard, error)
|
||||
GetAllDashboardsByOrgId(ctx context.Context, orgID int64) ([]*Dashboard, error)
|
||||
SoftDeleteDashboard(ctx context.Context, orgID int64, dashboardUid string) error
|
||||
|
||||
@@ -376,36 +376,6 @@ func (_m *FakeDashboardService) GetDashboards(ctx context.Context, query *GetDas
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetDashboardsSharedWithUser provides a mock function with given fields: ctx, user
|
||||
func (_m *FakeDashboardService) GetDashboardsSharedWithUser(ctx context.Context, user identity.Requester) ([]*DashboardRef, error) {
|
||||
ret := _m.Called(ctx, user)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetDashboardsSharedWithUser")
|
||||
}
|
||||
|
||||
var r0 []*DashboardRef
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, identity.Requester) ([]*DashboardRef, error)); ok {
|
||||
return rf(ctx, user)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, identity.Requester) []*DashboardRef); ok {
|
||||
r0 = rf(ctx, user)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*DashboardRef)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, identity.Requester) error); ok {
|
||||
r1 = rf(ctx, user)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetSoftDeletedDashboard provides a mock function with given fields: ctx, orgID, uid
|
||||
func (_m *FakeDashboardService) GetSoftDeletedDashboard(ctx context.Context, orgID int64, uid string) (*Dashboard, error) {
|
||||
ret := _m.Called(ctx, orgID, uid)
|
||||
|
||||
@@ -1395,10 +1395,6 @@ func (dr *DashboardServiceImpl) GetDashboards(ctx context.Context, query *dashbo
|
||||
return dr.dashboardStore.GetDashboards(ctx, query)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) GetDashboardsSharedWithUser(ctx context.Context, user identity.Requester) ([]*dashboards.DashboardRef, error) {
|
||||
return dr.getDashboardsSharedWithUser(ctx, user)
|
||||
}
|
||||
|
||||
func (dr *DashboardServiceImpl) getDashboardsSharedWithUser(ctx context.Context, user identity.Requester) ([]*dashboards.DashboardRef, error) {
|
||||
ctx, span := tracer.Start(ctx, "dashboards.service.getDashboardsSharedWithUser")
|
||||
defer span.End()
|
||||
|
||||
@@ -2084,119 +2084,6 @@ func TestGetDashboardTags(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetDashboardsSharedWithUser(t *testing.T) {
|
||||
fakeStore := dashboards.FakeDashboardStore{}
|
||||
defer fakeStore.AssertExpectations(t)
|
||||
service := &DashboardServiceImpl{
|
||||
cfg: setting.NewCfg(),
|
||||
dashboardStore: &fakeStore,
|
||||
folderService: &foldertest.FakeService{},
|
||||
}
|
||||
|
||||
user := &user.SignedInUser{
|
||||
OrgID: 1,
|
||||
Permissions: map[int64]map[string][]string{
|
||||
1: {
|
||||
dashboards.ActionDashboardsRead: {
|
||||
dashboards.ScopeDashboardsPrefix + "dashboard1",
|
||||
dashboards.ScopeDashboardsPrefix + "dashboard2",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expectedDashboards := []*dashboards.Dashboard{
|
||||
{
|
||||
UID: "dashboard1",
|
||||
Slug: "dashboard-1",
|
||||
FolderUID: "folder1",
|
||||
},
|
||||
{
|
||||
UID: "dashboard2",
|
||||
Slug: "dashboard-2",
|
||||
FolderUID: "folder2",
|
||||
},
|
||||
}
|
||||
|
||||
expectedFolderRefs := []*dashboards.DashboardRef{
|
||||
{
|
||||
UID: "dashboard1",
|
||||
Slug: "dashboard-1",
|
||||
FolderUID: "folder1",
|
||||
},
|
||||
{
|
||||
UID: "dashboard2",
|
||||
Slug: "dashboard-2",
|
||||
FolderUID: "folder2",
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("Should fallback to dashboard store if Kubernetes feature flags are not enabled", func(t *testing.T) {
|
||||
service.features = featuremgmt.WithFeatures()
|
||||
fakeStore.On("GetDashboards", mock.Anything, &dashboards.GetDashboardsQuery{
|
||||
DashboardUIDs: []string{"dashboard1", "dashboard2"},
|
||||
OrgID: 1,
|
||||
}).Return(expectedDashboards, nil).Once()
|
||||
|
||||
result, err := service.GetDashboardsSharedWithUser(context.Background(), user)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedFolderRefs, result)
|
||||
fakeStore.AssertExpectations(t)
|
||||
})
|
||||
|
||||
t.Run("Should use Kubernetes client if feature flags are enabled", func(t *testing.T) {
|
||||
ctx, k8sCliMock := setupK8sDashboardTests(service)
|
||||
service.features = featuremgmt.WithFeatures(featuremgmt.FlagKubernetesClientDashboardsFolders)
|
||||
|
||||
k8sCliMock.On("GetNamespace", mock.Anything, mock.Anything).Return("default")
|
||||
k8sCliMock.On("Search", mock.Anything, int64(1), mock.MatchedBy(func(req *resource.ResourceSearchRequest) bool {
|
||||
return req.Options.Fields[0].Key == "name" &&
|
||||
slices.Equal(req.Options.Fields[0].Values, []string{"dashboard1", "dashboard2"})
|
||||
})).Return(&resource.ResourceSearchResponse{
|
||||
Results: &resource.ResourceTable{
|
||||
Columns: []*resource.ResourceTableColumnDefinition{
|
||||
{
|
||||
Name: "title",
|
||||
Type: resource.ResourceTableColumnDefinition_STRING,
|
||||
},
|
||||
{
|
||||
Name: "folder",
|
||||
Type: resource.ResourceTableColumnDefinition_STRING,
|
||||
},
|
||||
},
|
||||
Rows: []*resource.ResourceTableRow{
|
||||
{
|
||||
Key: &resource.ResourceKey{
|
||||
Name: "dashboard1",
|
||||
Resource: "dashboard",
|
||||
},
|
||||
Cells: [][]byte{
|
||||
[]byte("Dashboard 1"),
|
||||
[]byte("folder1"),
|
||||
},
|
||||
},
|
||||
{
|
||||
Key: &resource.ResourceKey{
|
||||
Name: "dashboard2",
|
||||
Resource: "dashboard",
|
||||
},
|
||||
Cells: [][]byte{
|
||||
[]byte("Dashboard 2"),
|
||||
[]byte("folder2"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
TotalHits: 2,
|
||||
}, nil)
|
||||
|
||||
result, err := service.GetDashboardsSharedWithUser(ctx, user)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedFolderRefs, result)
|
||||
k8sCliMock.AssertExpectations(t)
|
||||
})
|
||||
}
|
||||
|
||||
func TestQuotaCount(t *testing.T) {
|
||||
fakeStore := dashboards.FakeDashboardStore{}
|
||||
defer fakeStore.AssertExpectations(t)
|
||||
|
||||
@@ -1611,17 +1611,6 @@ func TestIntegrationNestedFolderSharedWithMe(t *testing.T) {
|
||||
require.Contains(t, sharedFoldersUIDs, ancestorFoldersWithoutPermissions[1].UID)
|
||||
require.NotContains(t, sharedFoldersUIDs, ancestorFoldersWithPermissions[1].UID)
|
||||
|
||||
sharedDashboards, err := dashboardService.GetDashboardsSharedWithUser(context.Background(), &signedInUser)
|
||||
sharedDashboardsUIDs := make([]string, 0)
|
||||
for _, d := range sharedDashboards {
|
||||
sharedDashboardsUIDs = append(sharedDashboardsUIDs, d.UID)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Len(t, sharedDashboards, 1)
|
||||
require.Contains(t, sharedDashboardsUIDs, dash1.UID)
|
||||
require.NotContains(t, sharedDashboardsUIDs, dash2.UID)
|
||||
|
||||
t.Cleanup(func() {
|
||||
//guardian.New = origNewGuardian
|
||||
toDelete := make([]string, 0, len(ancestorFoldersWithPermissions)+len(ancestorFoldersWithoutPermissions))
|
||||
|
||||
Reference in New Issue
Block a user