diff --git a/pkg/services/dashboards/dashboard.go b/pkg/services/dashboards/dashboard.go index 425a3b43c2f..86ab91ec4fc 100644 --- a/pkg/services/dashboards/dashboard.go +++ b/pkg/services/dashboards/dashboard.go @@ -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 diff --git a/pkg/services/dashboards/dashboard_service_mock.go b/pkg/services/dashboards/dashboard_service_mock.go index ac9bbbb0bb6..ed23902a915 100644 --- a/pkg/services/dashboards/dashboard_service_mock.go +++ b/pkg/services/dashboards/dashboard_service_mock.go @@ -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) diff --git a/pkg/services/dashboards/service/dashboard_service.go b/pkg/services/dashboards/service/dashboard_service.go index 17177c0f8b9..7de0c917e3b 100644 --- a/pkg/services/dashboards/service/dashboard_service.go +++ b/pkg/services/dashboards/service/dashboard_service.go @@ -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() diff --git a/pkg/services/dashboards/service/dashboard_service_test.go b/pkg/services/dashboards/service/dashboard_service_test.go index cab7f23ff66..0ce90a88fd5 100644 --- a/pkg/services/dashboards/service/dashboard_service_test.go +++ b/pkg/services/dashboards/service/dashboard_service_test.go @@ -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) diff --git a/pkg/services/folder/folderimpl/folder_test.go b/pkg/services/folder/folderimpl/folder_test.go index 03512d54116..959591db9da 100644 --- a/pkg/services/folder/folderimpl/folder_test.go +++ b/pkg/services/folder/folderimpl/folder_test.go @@ -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))