Chore: Remove bus from index (#44851)

This commit is contained in:
Kat Yang 2022-02-03 12:22:21 -05:00 committed by GitHub
parent 7f2d3055d8
commit 9b3cb4a306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 10 deletions

View File

@ -7,7 +7,6 @@ import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/api/navlinks"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/plugins"
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
@ -540,7 +539,7 @@ func (hs *HTTPServer) buildAdminNavLinks(c *models.ReqContext) []*dtos.NavLink {
func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewData, error) {
hasEditPermissionInFoldersQuery := models.HasEditPermissionInFoldersQuery{SignedInUser: c.SignedInUser}
if err := bus.Dispatch(c.Req.Context(), &hasEditPermissionInFoldersQuery); err != nil {
if err := hs.SQLStore.HasEditPermissionInFolders(c.Req.Context(), &hasEditPermissionInFoldersQuery); err != nil {
return nil, err
}
hasEditPerm := hasEditPermissionInFoldersQuery.Result
@ -553,7 +552,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
settings["dateFormats"] = hs.Cfg.DateFormats
prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
if err := bus.Dispatch(c.Req.Context(), &prefsQuery); err != nil {
if err := hs.SQLStore.GetPreferencesWithDefaults(c.Req.Context(), &prefsQuery); err != nil {
return nil, err
}
prefs := prefsQuery.Result

View File

@ -33,7 +33,6 @@ func init() {
bus.AddHandler("sql", GetDashboardsByPluginId)
bus.AddHandler("sql", GetDashboardPermissionsForUser)
bus.AddHandler("sql", GetDashboardsBySlug)
bus.AddHandler("sql", HasEditPermissionInFolders)
bus.AddHandler("sql", HasAdminPermissionInFolders)
prometheus.MustRegister(shadowSearchCounter)
@ -44,6 +43,7 @@ func (ss *SQLStore) addDashboardQueryAndCommandHandlers() {
bus.AddHandler("sql", ss.SearchDashboards)
bus.AddHandler("sql", ss.DeleteDashboard)
bus.AddHandler("sql", ss.GetDashboards)
bus.AddHandler("sql", ss.HasEditPermissionInFolders)
}
var generateNewUid func() string = util.GenerateShortUID
@ -800,7 +800,7 @@ func (ss *SQLStore) ValidateDashboardBeforeSave(dashboard *models.Dashboard, ove
}
// HasEditPermissionInFolders validates that an user have access to a certain folder
func HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error {
func (ss *SQLStore) HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error {
return withDbSession(ctx, x, func(dbSession *DBSession) error {
if query.SignedInUser.HasRole(models.ROLE_EDITOR) {
query.Result = true

View File

@ -327,7 +327,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
query := &models.HasEditPermissionInFoldersQuery{
SignedInUser: &models.SignedInUser{UserId: adminUser.Id, OrgId: 1, OrgRole: models.ROLE_ADMIN},
}
err := HasEditPermissionInFolders(context.Background(), query)
err := sqlStore.HasEditPermissionInFolders(context.Background(), query)
require.NoError(t, err)
require.True(t, query.Result)
})
@ -393,7 +393,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
query := &models.HasEditPermissionInFoldersQuery{
SignedInUser: &models.SignedInUser{UserId: editorUser.Id, OrgId: 1, OrgRole: models.ROLE_EDITOR},
}
err := HasEditPermissionInFolders(context.Background(), query)
err := sqlStore.HasEditPermissionInFolders(context.Background(), query)
require.NoError(t, err)
require.True(t, query.Result)
})
@ -461,7 +461,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
query := &models.HasEditPermissionInFoldersQuery{
SignedInUser: &models.SignedInUser{UserId: viewerUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER},
}
err := HasEditPermissionInFolders(context.Background(), query)
err := sqlStore.HasEditPermissionInFolders(context.Background(), query)
require.NoError(t, err)
require.False(t, query.Result)
})
@ -485,7 +485,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
query := &models.HasEditPermissionInFoldersQuery{
SignedInUser: &models.SignedInUser{UserId: viewerUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER},
}
err := HasEditPermissionInFolders(context.Background(), query)
err := sqlStore.HasEditPermissionInFolders(context.Background(), query)
require.NoError(t, err)
require.True(t, query.Result)
})
@ -501,7 +501,7 @@ func TestDashboardFolderDataAccess(t *testing.T) {
query := &models.HasEditPermissionInFoldersQuery{
SignedInUser: &models.SignedInUser{UserId: viewerUser.Id, OrgId: 1, OrgRole: models.ROLE_VIEWER},
}
err := HasEditPermissionInFolders(context.Background(), query)
err := sqlStore.HasEditPermissionInFolders(context.Background(), query)
require.NoError(t, err)
require.True(t, query.Result)
})

View File

@ -34,6 +34,10 @@ func (m SQLStoreMock) GetDashboardSnapshot(query *models.GetDashboardSnapshotQue
return m.ExpectedError
}
func (m SQLStoreMock) HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error {
return m.ExpectedError
}
func (m SQLStoreMock) SearchDashboardSnapshots(query *models.GetDashboardSnapshotsQuery) error {
return m.ExpectedError
}

View File

@ -12,6 +12,7 @@ type Store interface {
CreateDashboardSnapshot(ctx context.Context, cmd *models.CreateDashboardSnapshotCommand) error
DeleteDashboardSnapshot(ctx context.Context, cmd *models.DeleteDashboardSnapshotCommand) error
GetDashboardSnapshot(query *models.GetDashboardSnapshotQuery) error
HasEditPermissionInFolders(ctx context.Context, query *models.HasEditPermissionInFoldersQuery) error
SearchDashboardSnapshots(query *models.GetDashboardSnapshotsQuery) error
GetOrgByName(name string) (*models.Org, error)
CreateOrgWithMember(name string, userID int64) (models.Org, error)