mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Rename AddHandlerCtx to AddHandler (#43557)
This commit is contained in:
parent
ec9d6b9ca9
commit
7936c4c522
@ -55,7 +55,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
t.Run("When a server admin attempts to logout himself from all devices", func(t *testing.T) {
|
||||
adminLogoutUserScenario(t, "Should not be allowed when calling POST on",
|
||||
"/api/admin/users/1/logout", "/api/admin/users/:id/logout", func(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
cmd.Result = &models.User{Id: testUserID}
|
||||
return nil
|
||||
})
|
||||
@ -70,7 +70,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
"/api/admin/users/:id/logout", func(sc *scenarioContext) {
|
||||
userID := int64(0)
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
userID = cmd.Id
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
@ -86,7 +86,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminRevokeUserAuthTokenScenario(t, "Should return not found when calling POST on",
|
||||
"/api/admin/users/200/revoke-auth-token", "/api/admin/users/:id/revoke-auth-token", cmd, func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
userID = cmd.Id
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
@ -101,7 +101,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminGetUserAuthTokensScenario(t, "Should return not found when calling GET on",
|
||||
"/api/admin/users/200/auth-tokens", "/api/admin/users/:id/auth-tokens", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
userID = cmd.Id
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
@ -117,11 +117,11 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
"/api/admin/users/42/enable", "/api/admin/users/:id/enable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
isDisabled := false
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
userID = cmd.UserId
|
||||
isDisabled = cmd.IsDisabled
|
||||
return models.ErrUserNotFound
|
||||
@ -143,11 +143,11 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
"/api/admin/users/42/disable", "/api/admin/users/:id/disable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
isDisabled := false
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
userID = cmd.UserId
|
||||
isDisabled = cmd.IsDisabled
|
||||
return models.ErrUserNotFound
|
||||
@ -170,7 +170,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminDisableUserScenario(t, "Should return Could not disable external user error", "disable",
|
||||
"/api/admin/users/42/disable", "/api/admin/users/:id/disable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
userID = cmd.UserId
|
||||
return nil
|
||||
})
|
||||
@ -188,7 +188,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminDisableUserScenario(t, "Should return Could not enable external user error", "enable",
|
||||
"/api/admin/users/42/enable", "/api/admin/users/:id/enable", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetAuthInfoQuery) error {
|
||||
userID = cmd.UserId
|
||||
return nil
|
||||
})
|
||||
@ -208,7 +208,7 @@ func TestAdminAPIEndpoint(t *testing.T) {
|
||||
adminDeleteUserScenario(t, "Should return user not found error", "/api/admin/users/42",
|
||||
"/api/admin/users/:id", func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DeleteUserCommand) error {
|
||||
userID = cmd.UserId
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
editorRole := models.ROLE_EDITOR
|
||||
|
||||
setUp := func(confs ...setUpConf) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAlertByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetAlertByIdQuery) error {
|
||||
query.Result = singleAlert
|
||||
return nil
|
||||
})
|
||||
@ -37,12 +37,12 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
aclMockResp = c.aclMockResp
|
||||
}
|
||||
}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
@ -86,13 +86,13 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
setUp()
|
||||
|
||||
var searchQuery *search.Query
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *search.Query) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *search.Query) error {
|
||||
searchQuery = query
|
||||
return nil
|
||||
})
|
||||
|
||||
var getAlertsQuery *models.GetAlertsQuery
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAlertsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetAlertsQuery) error {
|
||||
getAlertsQuery = query
|
||||
return nil
|
||||
})
|
||||
@ -110,7 +110,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
setUp()
|
||||
|
||||
var searchQuery *search.Query
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *search.Query) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *search.Query) error {
|
||||
searchQuery = query
|
||||
query.Result = search.HitList{
|
||||
&search.Hit{ID: 1},
|
||||
@ -120,7 +120,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
|
||||
var getAlertsQuery *models.GetAlertsQuery
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAlertsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetAlertsQuery) error {
|
||||
getAlertsQuery = query
|
||||
return nil
|
||||
})
|
||||
@ -153,7 +153,7 @@ func TestAlertingAPIEndpoint(t *testing.T) {
|
||||
}
|
||||
|
||||
func callPauseAlert(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.PauseAlertCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.PauseAlertCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -134,12 +134,12 @@ func TestAnnotationsAPIEndpoint(t *testing.T) {
|
||||
}
|
||||
|
||||
setUp := func() {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
|
||||
t.Run("Given dashboard not exists", func(t *testing.T) {
|
||||
setUp := func() {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
return models.ErrDashboardNotFound
|
||||
})
|
||||
}
|
||||
@ -68,7 +68,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
getDashboardQueryResult := models.NewDashboard("Dash")
|
||||
|
||||
setUp := func() {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = getDashboardQueryResult
|
||||
return nil
|
||||
})
|
||||
@ -120,7 +120,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUp := func() {
|
||||
getDashboardQueryResult := models.NewDashboard("Dash")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = getDashboardQueryResult
|
||||
return nil
|
||||
})
|
||||
@ -173,7 +173,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUp := func() {
|
||||
getDashboardQueryResult := models.NewDashboard("Dash")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = getDashboardQueryResult
|
||||
return nil
|
||||
})
|
||||
@ -214,7 +214,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUp := func() {
|
||||
getDashboardQueryResult := models.NewDashboard("Dash")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = getDashboardQueryResult
|
||||
return nil
|
||||
})
|
||||
@ -285,7 +285,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUp := func() {
|
||||
getDashboardQueryResult := models.NewDashboard("Dash")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = getDashboardQueryResult
|
||||
return nil
|
||||
})
|
||||
@ -336,7 +336,7 @@ func TestDashboardPermissionAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUp := func() {
|
||||
getDashboardQueryResult := models.NewDashboard("Dash")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = getDashboardQueryResult
|
||||
return nil
|
||||
})
|
||||
|
@ -45,22 +45,22 @@ func TestDashboardSnapshotAPIEndpoint_singleSnapshot(t *testing.T) {
|
||||
External: true,
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardSnapshotQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardSnapshotQuery) error {
|
||||
query.Result = mockSnapshotResult
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardSnapshotCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DeleteDashboardSnapshotCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
teamResp := []*models.TeamDTO{}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = teamResp
|
||||
return nil
|
||||
})
|
||||
|
@ -42,7 +42,7 @@ func TestGetHomeDashboard(t *testing.T) {
|
||||
Cfg: cfg, Bus: bus.New(),
|
||||
pluginStore: &fakePluginStore{},
|
||||
}
|
||||
hs.Bus.AddHandlerCtx(func(_ context.Context, query *models.GetPreferencesWithDefaultsQuery) error {
|
||||
hs.Bus.AddHandler(func(_ context.Context, query *models.GetPreferencesWithDefaultsQuery) error {
|
||||
query.Result = &models.Preferences{
|
||||
HomeDashboardId: 0,
|
||||
}
|
||||
@ -108,7 +108,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDash.FolderId = 1
|
||||
fakeDash.HasAcl = false
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
dashboards := []*models.Dashboard{fakeDash}
|
||||
query.Result = dashboards
|
||||
return nil
|
||||
@ -116,7 +116,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
state := &testState{}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = fakeDash
|
||||
state.dashQueries = append(state.dashQueries, query)
|
||||
return nil
|
||||
@ -130,12 +130,12 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
{Role: &editorRole, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
@ -262,7 +262,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
})
|
||||
setting.ViewersCanEdit = false
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
dashboards := []*models.Dashboard{fakeDash}
|
||||
query.Result = dashboards
|
||||
return nil
|
||||
@ -276,18 +276,18 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = aclMockResp
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = fakeDash
|
||||
state.dashQueries = append(state.dashQueries, query)
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
query.Result = []*models.TeamDTO{}
|
||||
return nil
|
||||
})
|
||||
@ -391,7 +391,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
setUpInner := func() *testState {
|
||||
state := setUp()
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@ -443,7 +443,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
{OrgId: 1, DashboardId: 2, UserId: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@ -487,7 +487,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
mockResult := []*models.DashboardAclInfoDTO{
|
||||
{OrgId: 1, DashboardId: 2, UserId: 1, Permission: models.PERMISSION_ADMIN},
|
||||
}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@ -537,7 +537,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
mockResult := []*models.DashboardAclInfoDTO{
|
||||
{OrgId: 1, DashboardId: 2, UserId: 1, Permission: models.PERMISSION_VIEW},
|
||||
}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
@ -588,7 +588,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
dashTwo.FolderId = 3
|
||||
dashTwo.HasAcl = false
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
dashboards := []*models.Dashboard{dashOne, dashTwo}
|
||||
query.Result = dashboards
|
||||
return nil
|
||||
@ -778,12 +778,12 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
t.Run("Given two dashboards being compared", func(t *testing.T) {
|
||||
setUp := func() {
|
||||
mockResult := []*models.DashboardAclInfoDTO{}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = mockResult
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{
|
||||
Data: simplejson.NewFromAny(map[string]interface{}{
|
||||
"title": fmt.Sprintf("Dash%d", query.DashboardId),
|
||||
@ -836,12 +836,12 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDash.FolderId = folderID
|
||||
fakeDash.HasAcl = false
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = fakeDash
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{
|
||||
DashboardId: 2,
|
||||
Version: 1,
|
||||
@ -884,12 +884,12 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
fakeDash.Id = 2
|
||||
fakeDash.HasAcl = false
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = fakeDash
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{
|
||||
DashboardId: 2,
|
||||
Version: 1,
|
||||
@ -928,11 +928,11 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
|
||||
t.Run("Given provisioned dashboard", func(t *testing.T) {
|
||||
setUp := func() {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardsBySlugQuery) error {
|
||||
query.Result = []*models.Dashboard{{}}
|
||||
return nil
|
||||
})
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
dataValue, err := simplejson.NewJson([]byte(`{"id": 1, "editable": true, "style": "dark"}`))
|
||||
require.NoError(t, err)
|
||||
query.Result = &models.Dashboard{Id: 1, Data: dataValue}
|
||||
@ -947,7 +947,7 @@ func TestDashboardAPIEndpoint(t *testing.T) {
|
||||
return &models.DashboardProvisioning{ExternalId: "/tmp/grafana/dashboards/test/dashboard1.json"}, nil
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = []*models.DashboardAclInfoDTO{
|
||||
{OrgId: testOrgID, DashboardId: 1, UserId: testUserID, Permission: models.PERMISSION_EDIT},
|
||||
}
|
||||
@ -1049,7 +1049,7 @@ func callGetDashboard(sc *scenarioContext, hs *HTTPServer) {
|
||||
}
|
||||
|
||||
func callGetDashboardVersion(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardVersionQuery) error {
|
||||
query.Result = &models.DashboardVersion{}
|
||||
return nil
|
||||
})
|
||||
@ -1059,7 +1059,7 @@ func callGetDashboardVersion(sc *scenarioContext) {
|
||||
}
|
||||
|
||||
func callGetDashboardVersions(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardVersionsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardVersionsQuery) error {
|
||||
query.Result = []*models.DashboardVersionDTO{}
|
||||
return nil
|
||||
})
|
||||
@ -1069,7 +1069,7 @@ func callGetDashboardVersions(sc *scenarioContext) {
|
||||
}
|
||||
|
||||
func callDeleteDashboardBySlug(sc *scenarioContext, hs *HTTPServer) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -1078,7 +1078,7 @@ func callDeleteDashboardBySlug(sc *scenarioContext, hs *HTTPServer) {
|
||||
}
|
||||
|
||||
func callDeleteDashboardByUID(sc *scenarioContext, hs *HTTPServer) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -30,7 +30,7 @@ const (
|
||||
func TestDataSourcesProxy_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/datasources/", func(sc *scenarioContext) {
|
||||
// Stubs the database query
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDataSourcesQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDataSourcesQuery) error {
|
||||
assert.Equal(t, testOrgID, query.OrgId)
|
||||
query.Result = []*models.DataSource{
|
||||
{Name: "mmm"},
|
||||
@ -103,7 +103,7 @@ func TestAddDataSource_URLWithoutProtocol(t *testing.T) {
|
||||
const url = "localhost:5432"
|
||||
|
||||
// Stub handler
|
||||
bus.AddHandlerCtx("sql", func(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
bus.AddHandler("sql", func(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
assert.Equal(t, name, cmd.Name)
|
||||
assert.Equal(t, url, cmd.Url)
|
||||
|
||||
@ -157,7 +157,7 @@ func TestUpdateDataSource_URLWithoutProtocol(t *testing.T) {
|
||||
const url = "localhost:5432"
|
||||
|
||||
// Stub handler
|
||||
bus.AddHandlerCtx("sql", func(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
bus.AddHandler("sql", func(ctx context.Context, cmd *models.AddDataSourceCommand) error {
|
||||
assert.Equal(t, name, cmd.Name)
|
||||
assert.Equal(t, url, cmd.Url)
|
||||
|
||||
@ -478,7 +478,7 @@ func TestAPI_Datasources_AccessControl(t *testing.T) {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Cleanup(bus.ClearBusHandlers)
|
||||
for i, handler := range test.busStubs {
|
||||
bus.AddHandlerCtx(fmt.Sprintf("test_handler_%v", i), handler)
|
||||
bus.AddHandler(fmt.Sprintf("test_handler_%v", i), handler)
|
||||
}
|
||||
|
||||
cfg := setting.NewCfg()
|
||||
|
@ -22,7 +22,7 @@ func TestHealthAPI_Version(t *testing.T) {
|
||||
cfg.BuildCommit = "59906ab1bf"
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -45,7 +45,7 @@ func TestHealthAPI_AnonymousHideVersion(t *testing.T) {
|
||||
m, hs := setupHealthAPITestEnvironment(t)
|
||||
hs.Cfg.AnonymousHideVersion = true
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -68,7 +68,7 @@ func TestHealthAPI_DatabaseHealthy(t *testing.T) {
|
||||
m, hs := setupHealthAPITestEnvironment(t)
|
||||
hs.Cfg.AnonymousHideVersion = true
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -99,7 +99,7 @@ func TestHealthAPI_DatabaseUnhealthy(t *testing.T) {
|
||||
m, hs := setupHealthAPITestEnvironment(t)
|
||||
hs.Cfg.AnonymousHideVersion = true
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
return errors.New("bad")
|
||||
})
|
||||
|
||||
@ -131,7 +131,7 @@ func TestHealthAPI_DatabaseHealthCached(t *testing.T) {
|
||||
hs.Cfg.AnonymousHideVersion = true
|
||||
|
||||
// Database is healthy.
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -132,7 +132,7 @@ func TestGetUserFromLDAPAPIEndpoint_OrgNotfound(t *testing.T) {
|
||||
{Id: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
query.Result = mockOrgSearchResult
|
||||
return nil
|
||||
})
|
||||
@ -194,7 +194,7 @@ func TestGetUserFromLDAPAPIEndpoint(t *testing.T) {
|
||||
{Id: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
query.Result = mockOrgSearchResult
|
||||
return nil
|
||||
})
|
||||
@ -269,12 +269,12 @@ func TestGetUserFromLDAPAPIEndpoint_WithTeamHandler(t *testing.T) {
|
||||
{Id: 1, Name: "Main Org."},
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
query.Result = mockOrgSearchResult
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetTeamsForLDAPGroupCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetTeamsForLDAPGroupCommand) error {
|
||||
cmd.Result = []models.TeamOrgGroupDTO{}
|
||||
return nil
|
||||
})
|
||||
@ -430,19 +430,19 @@ func TestPostSyncUserWithLDAPAPIEndpoint_Success(t *testing.T) {
|
||||
Login: "ldap-daniel",
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
require.Equal(t, "ldap-daniel", cmd.ExternalUser.Login)
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
require.Equal(t, q.Id, int64(34))
|
||||
|
||||
q.Result = &models.User{Login: "ldap-daniel", Id: 34}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
require.Equal(t, q.UserId, int64(34))
|
||||
require.Equal(t, q.AuthModule, models.AuthModuleLDAP)
|
||||
|
||||
@ -471,7 +471,7 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenUserNotFound(t *testing.T) {
|
||||
return &LDAPMock{}
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
require.Equal(t, q.Id, int64(34))
|
||||
|
||||
return models.ErrUserNotFound
|
||||
@ -503,14 +503,14 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenGrafanaAdmin(t *testing.T) {
|
||||
|
||||
sc.cfg.AdminUser = "ldap-daniel"
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
require.Equal(t, q.Id, int64(34))
|
||||
|
||||
q.Result = &models.User{Login: "ldap-daniel", Id: 34}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
require.Equal(t, q.UserId, int64(34))
|
||||
require.Equal(t, q.AuthModule, models.AuthModuleLDAP)
|
||||
|
||||
@ -542,26 +542,26 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenUserNotInLDAP(t *testing.T) {
|
||||
|
||||
userSearchResult = nil
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
require.Equal(t, "ldap-daniel", cmd.ExternalUser.Login)
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
require.Equal(t, q.Id, int64(34))
|
||||
|
||||
q.Result = &models.User{Login: "ldap-daniel", Id: 34}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetExternalUserInfoByLoginQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetExternalUserInfoByLoginQuery) error {
|
||||
assert.Equal(t, "ldap-daniel", q.LoginOrEmail)
|
||||
q.Result = &models.ExternalUserInfo{IsDisabled: true, UserId: 34}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DisableUserCommand) error {
|
||||
assert.Equal(t, 34, cmd.UserId)
|
||||
return nil
|
||||
})
|
||||
@ -688,16 +688,16 @@ func TestLDAP_AccessControl(t *testing.T) {
|
||||
return &LDAPMock{}
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetUserByIdQuery) error {
|
||||
q.Result = &models.User{}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetAuthInfoQuery) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -348,7 +348,7 @@ func TestLoginPostRedirect(t *testing.T) {
|
||||
return hs.LoginPost(c)
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
bus.AddHandler("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
query.User = &models.User{
|
||||
Id: 42,
|
||||
Email: "",
|
||||
@ -685,7 +685,7 @@ func TestLoginPostRunLokingHook(t *testing.T) {
|
||||
|
||||
for _, c := range testCases {
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
bus.AddHandlerCtx("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
bus.AddHandler("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
query.User = c.authUser
|
||||
query.AuthModule = c.authModule
|
||||
return c.authErr
|
||||
|
@ -460,7 +460,7 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("When proxying a datasource that has OAuth token pass-through enabled", func(t *testing.T) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetAuthInfoQuery) error {
|
||||
query.Result = &models.UserAuth{
|
||||
Id: 1,
|
||||
UserId: 1,
|
||||
|
@ -29,7 +29,7 @@ func TestPluginProxy(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
key, err := secretsService.Encrypt(ctx, []byte("123"), secrets.WithoutScope())
|
||||
if err != nil {
|
||||
return err
|
||||
@ -136,7 +136,7 @@ func TestPluginProxy(t *testing.T) {
|
||||
Method: "GET",
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(_ context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
bus.AddHandler("test", func(_ context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
query.Result = &models.PluginSetting{
|
||||
JsonData: map[string]interface{}{
|
||||
"dynamicUrl": "https://dynamic.grafana.com",
|
||||
@ -172,7 +172,7 @@ func TestPluginProxy(t *testing.T) {
|
||||
Method: "GET",
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(_ context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
bus.AddHandler("test", func(_ context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
query.Result = &models.PluginSetting{}
|
||||
return nil
|
||||
})
|
||||
@ -204,7 +204,7 @@ func TestPluginProxy(t *testing.T) {
|
||||
Body: []byte(`{ "url": "{{.JsonData.dynamicUrl}}", "secret": "{{.SecureJsonData.key}}" }`),
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
encryptedJsonData, err := secretsService.EncryptJsonData(
|
||||
ctx,
|
||||
map[string]string{"key": "123"},
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func setUpGetTeamMembersHandler() {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamMembersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetTeamMembersQuery) error {
|
||||
query.Result = []*models.TeamMemberDTO{
|
||||
{Email: "testUser@grafana.com", Login: testUserLogin},
|
||||
{Email: "user1@grafana.com", Login: "user1"},
|
||||
|
@ -46,7 +46,7 @@ func TestTeamAPIEndpoint(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/teams/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchTeamsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchTeamsQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@ -71,7 +71,7 @@ func TestTeamAPIEndpoint(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/teams/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchTeamsQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchTeamsQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
|
@ -30,7 +30,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
|
||||
loggedInUserScenario(t, "When calling GET on", "api/users/:id", func(sc *scenarioContext) {
|
||||
fakeNow := time.Date(2019, 2, 11, 17, 30, 40, 0, time.UTC)
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetUserProfileQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetUserProfileQuery) error {
|
||||
query.Result = models.UserProfileDTO{
|
||||
Id: int64(1),
|
||||
Email: "daniel@grafana.com",
|
||||
@ -46,7 +46,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAuthInfoQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetAuthInfoQuery) error {
|
||||
query.Result = &models.UserAuth{
|
||||
AuthModule: models.AuthModuleLDAP,
|
||||
}
|
||||
@ -83,7 +83,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users/lookup", func(sc *scenarioContext) {
|
||||
fakeNow := time.Date(2019, 2, 11, 17, 30, 40, 0, time.UTC)
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetUserByLoginQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetUserByLoginQuery) error {
|
||||
require.Equal(t, "danlee", query.LoginOrEmail)
|
||||
|
||||
query.Result = &models.User{
|
||||
@ -130,7 +130,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@ -154,7 +154,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET with page and limit querystring parameters on", "/api/users", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@ -174,7 +174,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET on", "/api/users/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
@ -200,7 +200,7 @@ func TestUserAPIEndpoint_userLoggedIn(t *testing.T) {
|
||||
loggedInUserScenario(t, "When calling GET with page and perpage querystring parameters on", "/api/users/search", func(sc *scenarioContext) {
|
||||
var sentLimit int
|
||||
var sendPage int
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SearchUsersQuery) error {
|
||||
query.Result = mockResult
|
||||
|
||||
sentLimit = query.Limit
|
||||
|
@ -21,7 +21,7 @@ func TestUserTokenAPIEndpoint(t *testing.T) {
|
||||
revokeUserAuthTokenScenario(t, "Should return not found when calling POST on", "/api/user/revoke-auth-token",
|
||||
"/api/user/revoke-auth-token", cmd, 200, func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
userID = cmd.Id
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
@ -35,7 +35,7 @@ func TestUserTokenAPIEndpoint(t *testing.T) {
|
||||
t.Run("When current user gets auth tokens for a non-existing user", func(t *testing.T) {
|
||||
getUserAuthTokensScenario(t, "Should return not found when calling GET on", "/api/user/auth-tokens", "/api/user/auth-tokens", 200, func(sc *scenarioContext) {
|
||||
var userID int64
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
userID = cmd.Id
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
@ -49,7 +49,7 @@ func TestUserTokenAPIEndpoint(t *testing.T) {
|
||||
t.Run("When logging out an existing user from all devices", func(t *testing.T) {
|
||||
logoutUserFromAllDevicesInternalScenario(t, "Should be successful", 1, func(sc *scenarioContext) {
|
||||
const userID int64 = 200
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
return nil
|
||||
})
|
||||
@ -61,7 +61,7 @@ func TestUserTokenAPIEndpoint(t *testing.T) {
|
||||
|
||||
t.Run("When logout a non-existing user from all devices", func(t *testing.T) {
|
||||
logoutUserFromAllDevicesInternalScenario(t, "Should return not found", testUserID, func(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
@ -75,7 +75,7 @@ func TestUserTokenAPIEndpoint(t *testing.T) {
|
||||
token := &models.UserToken{Id: 1}
|
||||
|
||||
revokeUserAuthTokenInternalScenario(t, "Should be successful", cmd, 200, token, func(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
cmd.Result = &models.User{Id: 200}
|
||||
return nil
|
||||
})
|
||||
@ -93,7 +93,7 @@ func TestUserTokenAPIEndpoint(t *testing.T) {
|
||||
token := &models.UserToken{Id: 2}
|
||||
|
||||
revokeUserAuthTokenInternalScenario(t, "Should not be successful", cmd, testUserID, token, func(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
cmd.Result = &models.User{Id: testUserID}
|
||||
return nil
|
||||
})
|
||||
@ -110,7 +110,7 @@ func TestUserTokenAPIEndpoint(t *testing.T) {
|
||||
currentToken := &models.UserToken{Id: 1}
|
||||
|
||||
getUserAuthTokensInternalScenario(t, "Should be successful", currentToken, func(sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetUserByIdQuery) error {
|
||||
cmd.Result = &models.User{Id: testUserID}
|
||||
return nil
|
||||
})
|
||||
|
@ -37,7 +37,7 @@ type Bus interface {
|
||||
// callback returns an error.
|
||||
InTransaction(ctx context.Context, fn func(ctx context.Context) error) error
|
||||
|
||||
AddHandlerCtx(handler HandlerFunc)
|
||||
AddHandler(handler HandlerFunc)
|
||||
|
||||
AddEventListenerCtx(handler HandlerFunc)
|
||||
|
||||
@ -114,7 +114,7 @@ func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error {
|
||||
if withCtx {
|
||||
params = append(params, reflect.ValueOf(ctx))
|
||||
} else if setting.Env == setting.Dev {
|
||||
b.logger.Warn("DispatchCtx called with message handler registered using AddHandler and should be changed to use AddHandlerCtx", "msgName", msgName)
|
||||
b.logger.Warn("DispatchCtx called with message handler registered using AddHandler and should be changed to use AddHandler", "msgName", msgName)
|
||||
}
|
||||
params = append(params, reflect.ValueOf(msg))
|
||||
|
||||
@ -172,7 +172,7 @@ func callListeners(listeners []HandlerFunc, params []reflect.Value) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *InProcBus) AddHandlerCtx(handler HandlerFunc) {
|
||||
func (b *InProcBus) AddHandler(handler HandlerFunc) {
|
||||
handlerType := reflect.TypeOf(handler)
|
||||
queryTypeName := handlerType.In(1).Elem().Name()
|
||||
b.handlersWithCtx[queryTypeName] = handler
|
||||
@ -193,10 +193,10 @@ func (b *InProcBus) AddEventListenerCtx(handler HandlerFunc) {
|
||||
b.listenersWithCtx[eventName] = append(b.listenersWithCtx[eventName], handler)
|
||||
}
|
||||
|
||||
// AddHandlerCtx attaches a handler function to the global bus context.
|
||||
// AddHandler attaches a handler function to the global bus context.
|
||||
// Package level function.
|
||||
func AddHandlerCtx(implName string, handler HandlerFunc) {
|
||||
globalBus.AddHandlerCtx(handler)
|
||||
func AddHandler(implName string, handler HandlerFunc) {
|
||||
globalBus.AddHandler(handler)
|
||||
}
|
||||
|
||||
// AddEventListenerCtx attaches a handler function to the event listener.
|
||||
|
@ -18,7 +18,7 @@ func TestDispatch(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@ -42,7 +42,7 @@ func TestDispatch_ContextHandler(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@ -58,7 +58,7 @@ func TestDispatchCtx(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@ -74,7 +74,7 @@ func TestDispatchCtx_NoContextHandler(t *testing.T) {
|
||||
|
||||
var invoked bool
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
invoked = true
|
||||
return nil
|
||||
})
|
||||
@ -98,7 +98,7 @@ func TestQuery(t *testing.T) {
|
||||
|
||||
want := "hello from handler"
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, q *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, q *testQuery) error {
|
||||
q.Resp = want
|
||||
return nil
|
||||
})
|
||||
@ -114,7 +114,7 @@ func TestQuery(t *testing.T) {
|
||||
func TestQuery_HandlerReturnsError(t *testing.T) {
|
||||
bus := New()
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, query *testQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, query *testQuery) error {
|
||||
return errors.New("handler error")
|
||||
})
|
||||
|
||||
|
@ -38,7 +38,7 @@ func TestService(t *testing.T) {
|
||||
secretsService: secretsService,
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(_ context.Context, query *models.GetDataSourceQuery) error {
|
||||
bus.AddHandler("test", func(_ context.Context, query *models.GetDataSourceQuery) error {
|
||||
query.Result = &models.DataSource{Uid: "1", OrgId: 1, Type: "test", JsonData: simplejson.New()}
|
||||
return nil
|
||||
})
|
||||
|
@ -41,7 +41,7 @@ func TestMetrics(t *testing.T) {
|
||||
setupSomeDataSourcePlugins(t, uss)
|
||||
|
||||
var getSystemStatsQuery *models.GetSystemStatsQuery
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetSystemStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetSystemStatsQuery) error {
|
||||
query.Result = &models.SystemStats{
|
||||
Dashboards: 1,
|
||||
Datasources: 2,
|
||||
@ -86,7 +86,7 @@ func TestMetrics(t *testing.T) {
|
||||
})
|
||||
|
||||
var getDataSourceStatsQuery *models.GetDataSourceStatsQuery
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetDataSourceStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetDataSourceStatsQuery) error {
|
||||
query.Result = []*models.DataSourceStats{
|
||||
{
|
||||
Type: models.DS_ES,
|
||||
@ -110,7 +110,7 @@ func TestMetrics(t *testing.T) {
|
||||
})
|
||||
|
||||
var getESDatasSourcesQuery *models.GetDataSourcesByTypeQuery
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetDataSourcesByTypeQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetDataSourcesByTypeQuery) error {
|
||||
query.Result = []*models.DataSource{
|
||||
{
|
||||
JsonData: simplejson.NewFromAny(map[string]interface{}{
|
||||
@ -133,7 +133,7 @@ func TestMetrics(t *testing.T) {
|
||||
})
|
||||
|
||||
var getDataSourceAccessStatsQuery *models.GetDataSourceAccessStatsQuery
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetDataSourceAccessStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetDataSourceAccessStatsQuery) error {
|
||||
query.Result = []*models.DataSourceAccessStats{
|
||||
{
|
||||
Type: models.DS_ES,
|
||||
@ -181,7 +181,7 @@ func TestMetrics(t *testing.T) {
|
||||
})
|
||||
|
||||
var getAlertNotifierUsageStatsQuery *models.GetAlertNotifierUsageStatsQuery
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetAlertNotifierUsageStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetAlertNotifierUsageStatsQuery) error {
|
||||
query.Result = []*models.NotifierUsageStats{
|
||||
{
|
||||
Type: "slack",
|
||||
@ -403,7 +403,7 @@ func TestMetrics(t *testing.T) {
|
||||
uss.Cfg.MetricsEndpointEnabled = true
|
||||
uss.Cfg.MetricsEndpointDisableTotalStats = false
|
||||
getSystemStatsWasCalled := false
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetSystemStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetSystemStatsQuery) error {
|
||||
query.Result = &models.SystemStats{}
|
||||
getSystemStatsWasCalled = true
|
||||
return nil
|
||||
@ -464,27 +464,27 @@ func TestMetrics(t *testing.T) {
|
||||
uss := createService(t, setting.Cfg{})
|
||||
metricName := "stats.test_metric.count"
|
||||
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetSystemStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetSystemStatsQuery) error {
|
||||
query.Result = &models.SystemStats{}
|
||||
return nil
|
||||
})
|
||||
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetDataSourceStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetDataSourceStatsQuery) error {
|
||||
query.Result = []*models.DataSourceStats{}
|
||||
return nil
|
||||
})
|
||||
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetDataSourcesByTypeQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetDataSourcesByTypeQuery) error {
|
||||
query.Result = []*models.DataSource{}
|
||||
return nil
|
||||
})
|
||||
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetDataSourceAccessStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetDataSourceAccessStatsQuery) error {
|
||||
query.Result = []*models.DataSourceAccessStats{}
|
||||
return nil
|
||||
})
|
||||
|
||||
uss.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetAlertNotifierUsageStatsQuery) error {
|
||||
uss.Bus.AddHandler(func(ctx context.Context, query *models.GetAlertNotifierUsageStatsQuery) error {
|
||||
query.Result = []*models.NotifierUsageStats{}
|
||||
return nil
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ var (
|
||||
var loginLogger = log.New("login")
|
||||
|
||||
func Init() {
|
||||
bus.AddHandlerCtx("auth", authenticateUser)
|
||||
bus.AddHandler("auth", authenticateUser)
|
||||
}
|
||||
|
||||
// authenticateUser authenticates the user via username & password
|
||||
|
@ -73,7 +73,7 @@ func TestSaveInvalidLoginAttempt(t *testing.T) {
|
||||
t.Cleanup(func() { bus.ClearBusHandlers() })
|
||||
|
||||
createLoginAttemptCmd := &models.CreateLoginAttemptCommand{}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
|
||||
createLoginAttemptCmd = cmd
|
||||
return nil
|
||||
})
|
||||
@ -95,7 +95,7 @@ func TestSaveInvalidLoginAttempt(t *testing.T) {
|
||||
t.Cleanup(func() { bus.ClearBusHandlers() })
|
||||
|
||||
var createLoginAttemptCmd *models.CreateLoginAttemptCommand
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
|
||||
createLoginAttemptCmd = cmd
|
||||
return nil
|
||||
})
|
||||
@ -128,7 +128,7 @@ func cfgWithBruteForceLoginProtectionEnabled(t *testing.T) *setting.Cfg {
|
||||
|
||||
func withLoginAttempts(t *testing.T, loginAttempts int64) {
|
||||
t.Helper()
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetUserLoginAttemptCountQuery) error {
|
||||
query.Result = loginAttempts
|
||||
return nil
|
||||
})
|
||||
|
@ -95,7 +95,7 @@ func mockPasswordValidation(valid bool, sc *grafanaLoginScenarioContext) {
|
||||
}
|
||||
|
||||
func (sc *grafanaLoginScenarioContext) getUserByLoginQueryReturns(user *models.User) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetUserByLoginQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetUserByLoginQuery) error {
|
||||
if user == nil {
|
||||
return models.ErrUserNotFound
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func TestMiddlewareAuth(t *testing.T) {
|
||||
|
||||
middlewareScenario(t, "ReqSignIn true and NoAnonynmous true", func(
|
||||
t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
query.Result = &models.Org{Id: orgID, Name: "test"}
|
||||
return nil
|
||||
})
|
||||
@ -54,7 +54,7 @@ func TestMiddlewareAuth(t *testing.T) {
|
||||
|
||||
middlewareScenario(t, "ReqSignIn true and request with forceLogin in query string", func(
|
||||
t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
query.Result = &models.Org{Id: orgID, Name: "test"}
|
||||
return nil
|
||||
})
|
||||
@ -83,7 +83,7 @@ func TestMiddlewareAuth(t *testing.T) {
|
||||
|
||||
middlewareScenario(t, "ReqSignIn true and request with different org provided in query string", func(
|
||||
t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
query.Result = &models.Org{Id: orgID, Name: "test"}
|
||||
return nil
|
||||
})
|
||||
|
@ -28,7 +28,7 @@ func TestMiddlewareBasicAuth(t *testing.T) {
|
||||
keyhash, err := util.EncodePassword("v5nAwpMafFP6znaS4urhdWDLS5511M42", "asd")
|
||||
require.NoError(t, err)
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
query.Result = &models.ApiKey{OrgId: orgID, Role: models.ROLE_EDITOR, Key: keyhash}
|
||||
return nil
|
||||
})
|
||||
@ -47,7 +47,7 @@ func TestMiddlewareBasicAuth(t *testing.T) {
|
||||
const salt = "Salt"
|
||||
const orgID int64 = 2
|
||||
|
||||
bus.AddHandlerCtx("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
bus.AddHandler("grafana-auth", func(ctx context.Context, query *models.LoginUserQuery) error {
|
||||
t.Log("Handling LoginUserQuery")
|
||||
encoded, err := util.EncodePassword(password, salt)
|
||||
if err != nil {
|
||||
@ -60,7 +60,7 @@ func TestMiddlewareBasicAuth(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
t.Log("Handling GetSignedInUserQuery")
|
||||
query.Result = &models.SignedInUser{OrgId: orgID, UserId: id}
|
||||
return nil
|
||||
@ -80,7 +80,7 @@ func TestMiddlewareBasicAuth(t *testing.T) {
|
||||
|
||||
login.Init()
|
||||
|
||||
bus.AddHandlerCtx("user-query", func(ctx context.Context, query *models.GetUserByLoginQuery) error {
|
||||
bus.AddHandler("user-query", func(ctx context.Context, query *models.GetUserByLoginQuery) error {
|
||||
encoded, err := util.EncodePassword(password, salt)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -93,7 +93,7 @@ func TestMiddlewareBasicAuth(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{UserId: query.UserId}
|
||||
return nil
|
||||
})
|
||||
@ -119,7 +119,7 @@ func TestMiddlewareBasicAuth(t *testing.T) {
|
||||
}, configure)
|
||||
|
||||
middlewareScenario(t, "Should return error if user & password do not match", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("user-query", func(ctx context.Context, loginUserQuery *models.GetUserByLoginQuery) error {
|
||||
bus.AddHandler("user-query", func(ctx context.Context, loginUserQuery *models.GetUserByLoginQuery) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -40,7 +40,7 @@ func TestMiddlewareJWTAuth(t *testing.T) {
|
||||
"foo-username": myUsername,
|
||||
}, nil
|
||||
}
|
||||
bus.AddHandlerCtx("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{
|
||||
UserId: id,
|
||||
OrgId: orgID,
|
||||
@ -67,7 +67,7 @@ func TestMiddlewareJWTAuth(t *testing.T) {
|
||||
"foo-email": myEmail,
|
||||
}, nil
|
||||
}
|
||||
bus.AddHandlerCtx("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("get-sign-user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{
|
||||
UserId: id,
|
||||
OrgId: orgID,
|
||||
|
@ -149,7 +149,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
keyhash, err := util.EncodePassword("v5nAwpMafFP6znaS4urhdWDLS5511M42", "asd")
|
||||
require.NoError(t, err)
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
query.Result = &models.ApiKey{OrgId: orgID, Role: models.ROLE_EDITOR, Key: keyhash}
|
||||
return nil
|
||||
})
|
||||
@ -166,7 +166,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
middlewareScenario(t, "Valid API key, but does not match DB hash", func(t *testing.T, sc *scenarioContext) {
|
||||
const keyhash = "Something_not_matching"
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
query.Result = &models.ApiKey{OrgId: 12, Role: models.ROLE_EDITOR, Key: keyhash}
|
||||
return nil
|
||||
})
|
||||
@ -183,7 +183,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
keyhash, err := util.EncodePassword("v5nAwpMafFP6znaS4urhdWDLS5511M42", "asd")
|
||||
require.NoError(t, err)
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetApiKeyByNameQuery) error {
|
||||
// api key expired one second before
|
||||
expires := sc.contextHandler.GetTime().Add(-1 * time.Second).Unix()
|
||||
query.Result = &models.ApiKey{OrgId: 12, Role: models.ROLE_EDITOR, Key: keyhash,
|
||||
@ -203,7 +203,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
|
||||
sc.withTokenSessionCookie("token")
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: 2, UserId: userID}
|
||||
return nil
|
||||
})
|
||||
@ -231,7 +231,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
|
||||
sc.withTokenSessionCookie("token")
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: 2, UserId: userID}
|
||||
return nil
|
||||
})
|
||||
@ -365,7 +365,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
const group = "grafana-core-team"
|
||||
|
||||
middlewareScenario(t, "Should not sync the user if it's in the cache", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: orgID, UserId: query.UserId}
|
||||
return nil
|
||||
})
|
||||
@ -389,7 +389,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
middlewareScenario(t, "Should respect auto signup option", func(t *testing.T, sc *scenarioContext) {
|
||||
var actualAuthProxyAutoSignUp *bool = nil
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
actualAuthProxyAutoSignUp = &cmd.SignupAllowed
|
||||
return login.ErrInvalidCredentials
|
||||
})
|
||||
@ -408,7 +408,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
})
|
||||
|
||||
middlewareScenario(t, "Should create an user from a header", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
if query.UserId > 0 {
|
||||
query.Result = &models.SignedInUser{OrgId: orgID, UserId: userID}
|
||||
return nil
|
||||
@ -416,7 +416,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
return nil
|
||||
})
|
||||
@ -436,7 +436,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
|
||||
middlewareScenario(t, "Should assign role from header to default org", func(t *testing.T, sc *scenarioContext) {
|
||||
var storedRoleInfo map[int64]models.RoleType = nil
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
if query.UserId > 0 {
|
||||
query.Result = &models.SignedInUser{OrgId: defaultOrgId, UserId: userID, OrgRole: storedRoleInfo[defaultOrgId]}
|
||||
return nil
|
||||
@ -444,7 +444,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
storedRoleInfo = cmd.ExternalUser.OrgRoles
|
||||
return nil
|
||||
@ -467,7 +467,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
|
||||
middlewareScenario(t, "Should NOT assign role from header to non-default org", func(t *testing.T, sc *scenarioContext) {
|
||||
var storedRoleInfo map[int64]models.RoleType = nil
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
if query.UserId > 0 {
|
||||
query.Result = &models.SignedInUser{OrgId: orgID, UserId: userID, OrgRole: storedRoleInfo[orgID]}
|
||||
return nil
|
||||
@ -475,7 +475,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
storedRoleInfo = cmd.ExternalUser.OrgRoles
|
||||
return nil
|
||||
@ -500,7 +500,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
})
|
||||
|
||||
middlewareScenario(t, "Should use organisation specified by targetOrgId parameter", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
if query.UserId > 0 {
|
||||
query.Result = &models.SignedInUser{OrgId: query.OrgId, UserId: userID}
|
||||
return nil
|
||||
@ -508,7 +508,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
return models.ErrUserNotFound
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
return nil
|
||||
})
|
||||
@ -555,12 +555,12 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
const userID int64 = 12
|
||||
const orgID int64 = 2
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: orgID, UserId: userID}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
return nil
|
||||
})
|
||||
@ -578,12 +578,12 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
})
|
||||
|
||||
middlewareScenario(t, "Should allow the request from whitelist IP", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: orgID, UserId: userID}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
return nil
|
||||
})
|
||||
@ -603,12 +603,12 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
})
|
||||
|
||||
middlewareScenario(t, "Should not allow the request from whitelisted IP", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: orgID, UserId: userID}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{Id: userID}
|
||||
return nil
|
||||
})
|
||||
@ -627,7 +627,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
})
|
||||
|
||||
middlewareScenario(t, "Should return 407 status code if LDAP says no", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("LDAP", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("LDAP", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
return errors.New("Do not add user")
|
||||
})
|
||||
|
||||
@ -640,7 +640,7 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
}, configure)
|
||||
|
||||
middlewareScenario(t, "Should return 407 status code if there is cache mishap", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("Do not have the user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("Do not have the user", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
return errors.New("Do not add user")
|
||||
})
|
||||
|
||||
|
@ -13,11 +13,11 @@ import (
|
||||
func TestOrgRedirectMiddleware(t *testing.T) {
|
||||
middlewareScenario(t, "when setting a correct org for the user", func(t *testing.T, sc *scenarioContext) {
|
||||
sc.withTokenSessionCookie("token")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SetUsingOrgCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SetUsingOrgCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: 1, UserId: 12}
|
||||
return nil
|
||||
})
|
||||
@ -37,11 +37,11 @@ func TestOrgRedirectMiddleware(t *testing.T) {
|
||||
|
||||
middlewareScenario(t, "when setting an invalid org for user", func(t *testing.T, sc *scenarioContext) {
|
||||
sc.withTokenSessionCookie("token")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.SetUsingOrgCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.SetUsingOrgCommand) error {
|
||||
return fmt.Errorf("")
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: 1, UserId: 12}
|
||||
return nil
|
||||
})
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
func TestMiddlewareQuota(t *testing.T) {
|
||||
t.Run("With user not logged in", func(t *testing.T) {
|
||||
middlewareScenario(t, "and global quota not reached", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
bus.AddHandler("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
query.Result = &models.GlobalQuotaDTO{
|
||||
Target: query.Target,
|
||||
Limit: query.Default,
|
||||
@ -33,7 +33,7 @@ func TestMiddlewareQuota(t *testing.T) {
|
||||
}, configure)
|
||||
|
||||
middlewareScenario(t, "and global quota reached", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
bus.AddHandler("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
query.Result = &models.GlobalQuotaDTO{
|
||||
Target: query.Target,
|
||||
Limit: query.Default,
|
||||
@ -53,7 +53,7 @@ func TestMiddlewareQuota(t *testing.T) {
|
||||
})
|
||||
|
||||
middlewareScenario(t, "and global session quota not reached", func(t *testing.T, sc *scenarioContext) {
|
||||
bus.AddHandlerCtx("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
bus.AddHandler("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
query.Result = &models.GlobalQuotaDTO{
|
||||
Target: query.Target,
|
||||
Limit: query.Default,
|
||||
@ -89,7 +89,7 @@ func TestMiddlewareQuota(t *testing.T) {
|
||||
|
||||
setUp := func(sc *scenarioContext) {
|
||||
sc.withTokenSessionCookie("token")
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{OrgId: 2, UserId: 12}
|
||||
return nil
|
||||
})
|
||||
@ -101,7 +101,7 @@ func TestMiddlewareQuota(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
bus.AddHandler("globalQuota", func(_ context.Context, query *models.GetGlobalQuotaByTargetQuery) error {
|
||||
query.Result = &models.GlobalQuotaDTO{
|
||||
Target: query.Target,
|
||||
Limit: query.Default,
|
||||
@ -110,7 +110,7 @@ func TestMiddlewareQuota(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("userQuota", func(_ context.Context, query *models.GetUserQuotaByTargetQuery) error {
|
||||
bus.AddHandler("userQuota", func(_ context.Context, query *models.GetUserQuotaByTargetQuery) error {
|
||||
query.Result = &models.UserQuotaDTO{
|
||||
Target: query.Target,
|
||||
Limit: query.Default,
|
||||
@ -119,7 +119,7 @@ func TestMiddlewareQuota(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("orgQuota", func(_ context.Context, query *models.GetOrgQuotaByTargetQuery) error {
|
||||
bus.AddHandler("orgQuota", func(_ context.Context, query *models.GetOrgQuotaByTargetQuery) error {
|
||||
query.Result = &models.OrgQuotaDTO{
|
||||
Target: query.Target,
|
||||
Limit: query.Default,
|
||||
|
@ -27,7 +27,7 @@ func TestGetPluginDashboards(t *testing.T) {
|
||||
err := pm.init()
|
||||
require.NoError(t, err)
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
if query.Slug == "nginx-connections" {
|
||||
dash := models.NewDashboard("Nginx Connections")
|
||||
dash.Data.Set("revision", "1.1")
|
||||
@ -38,7 +38,7 @@ func TestGetPluginDashboards(t *testing.T) {
|
||||
return models.ErrDashboardNotFound
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardsByPluginIdQuery) error {
|
||||
var data = simplejson.New()
|
||||
data.Set("title", "Nginx Connections")
|
||||
data.Set("revision", 22)
|
||||
|
@ -18,7 +18,7 @@ func TestAlertingUsageStats(t *testing.T) {
|
||||
Bus: bus.New(),
|
||||
}
|
||||
|
||||
ae.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetAllAlertsQuery) error {
|
||||
ae.Bus.AddHandler(func(ctx context.Context, query *models.GetAllAlertsQuery) error {
|
||||
var createFake = func(file string) *simplejson.Json {
|
||||
// Ignore gosec warning G304 since it's a test
|
||||
// nolint:gosec
|
||||
@ -39,7 +39,7 @@ func TestAlertingUsageStats(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
ae.Bus.AddHandlerCtx(func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
ae.Bus.AddHandler(func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
ds := map[int64]*models.DataSource{
|
||||
1: {Type: "influxdb"},
|
||||
2: {Type: "graphite"},
|
||||
|
@ -137,7 +137,7 @@ func (rh fakeIntervalTestReqHandler) HandleRequest(ctx context.Context, dsInfo *
|
||||
//nolint: staticcheck // legacydata.DataResponse deprecated
|
||||
func applyScenario(t *testing.T, timeRange string, dataSourceJsonData *simplejson.Json, queryModel string, verifier func(query legacydata.DataSubQuery)) {
|
||||
t.Run("desc", func(t *testing.T) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
query.Result = &models.DataSource{Id: 1, Type: "graphite", JsonData: dataSourceJsonData}
|
||||
return nil
|
||||
})
|
||||
|
@ -35,7 +35,7 @@ func newTimeSeriesPointsFromArgs(values ...float64) legacydata.DataTimeSeriesPoi
|
||||
func TestQueryCondition(t *testing.T) {
|
||||
setup := func() *queryConditionTestContext {
|
||||
ctx := &queryConditionTestContext{}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
query.Result = &models.DataSource{Id: 1, Type: "graphite"}
|
||||
return nil
|
||||
})
|
||||
|
@ -53,7 +53,7 @@ func TestEngineProcessJob(t *testing.T) {
|
||||
job := &Job{running: true, Rule: &Rule{}}
|
||||
|
||||
t.Run("Should register usage metrics func", func(t *testing.T) {
|
||||
bus.AddHandlerCtx(func(ctx context.Context, q *models.GetAllAlertsQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, q *models.GetAllAlertsQuery) error {
|
||||
settings, err := simplejson.NewJson([]byte(`{"conditions": [{"query": { "datasourceId": 1}}]}`))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -62,7 +62,7 @@ func TestEngineProcessJob(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx(func(ctx context.Context, q *models.GetDataSourceQuery) error {
|
||||
bus.AddHandler(func(ctx context.Context, q *models.GetDataSourceQuery) error {
|
||||
q.Result = &models.DataSource{Id: 1, Type: models.DS_PROMETHEUS}
|
||||
return nil
|
||||
})
|
||||
|
@ -24,12 +24,12 @@ func TestAlertRuleExtraction(t *testing.T) {
|
||||
influxDBDs := &models.DataSource{Id: 16, OrgId: 1, Name: "InfluxDB", Uid: "InfluxDB-uid"}
|
||||
prom := &models.DataSource{Id: 17, OrgId: 1, Name: "Prometheus", Uid: "Prometheus-uid"}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDefaultDataSourceQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDefaultDataSourceQuery) error {
|
||||
query.Result = defaultDs
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDataSourceQuery) error {
|
||||
if query.Name == defaultDs.Name || query.Uid == defaultDs.Uid {
|
||||
query.Result = defaultDs
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ func notificationServiceScenario(t *testing.T, name string, evalCtx *EvalContext
|
||||
|
||||
evalCtx.dashboardRef = &models.DashboardRef{Uid: "db-uid"}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetAlertNotificationsWithUidToSendQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetAlertNotificationsWithUidToSendQuery) error {
|
||||
query.Result = []*models.AlertNotification{
|
||||
{
|
||||
Id: 1,
|
||||
@ -190,7 +190,7 @@ func notificationServiceScenario(t *testing.T, name string, evalCtx *EvalContext
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetOrCreateNotificationStateQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetOrCreateNotificationStateQuery) error {
|
||||
query.Result = &models.AlertNotificationState{
|
||||
AlertId: evalCtx.Rule.ID,
|
||||
AlertRuleStateUpdatedVersion: 1,
|
||||
@ -201,11 +201,11 @@ func notificationServiceScenario(t *testing.T, name string, evalCtx *EvalContext
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.SetAlertNotificationStateToPendingCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.SetAlertNotificationStateToPendingCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.SetAlertNotificationStateToCompleteCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.SetAlertNotificationStateToCompleteCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -107,7 +107,7 @@ func TestOpsGenieNotifier(t *testing.T) {
|
||||
|
||||
tags := make([]string, 0)
|
||||
details := make(map[string]interface{})
|
||||
bus.AddHandlerCtx("alerting", func(ctx context.Context, cmd *models.SendWebhookSync) error {
|
||||
bus.AddHandler("alerting", func(ctx context.Context, cmd *models.SendWebhookSync) error {
|
||||
bodyJSON, err := simplejson.NewJson([]byte(cmd.Body))
|
||||
if err == nil {
|
||||
tags = bodyJSON.Get("tags").MustStringArray([]string{})
|
||||
@ -157,7 +157,7 @@ func TestOpsGenieNotifier(t *testing.T) {
|
||||
|
||||
tags := make([]string, 0)
|
||||
details := make(map[string]interface{})
|
||||
bus.AddHandlerCtx("alerting", func(ctx context.Context, cmd *models.SendWebhookSync) error {
|
||||
bus.AddHandler("alerting", func(ctx context.Context, cmd *models.SendWebhookSync) error {
|
||||
bodyJSON, err := simplejson.NewJson([]byte(cmd.Body))
|
||||
if err == nil {
|
||||
tags = bodyJSON.Get("tags").MustStringArray([]string{})
|
||||
@ -207,7 +207,7 @@ func TestOpsGenieNotifier(t *testing.T) {
|
||||
|
||||
tags := make([]string, 0)
|
||||
details := make(map[string]interface{})
|
||||
bus.AddHandlerCtx("alerting", func(ctx context.Context, cmd *models.SendWebhookSync) error {
|
||||
bus.AddHandler("alerting", func(ctx context.Context, cmd *models.SendWebhookSync) error {
|
||||
bodyJSON, err := simplejson.NewJson([]byte(cmd.Body))
|
||||
if err == nil {
|
||||
tags = bodyJSON.Get("tags").MustStringArray([]string{})
|
||||
|
@ -24,19 +24,19 @@ func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, encryptionService enc
|
||||
EncryptionService: encryptionService,
|
||||
}
|
||||
|
||||
s.Bus.AddHandlerCtx(s.GetAlertNotifications)
|
||||
s.Bus.AddHandlerCtx(s.CreateAlertNotificationCommand)
|
||||
s.Bus.AddHandlerCtx(s.UpdateAlertNotification)
|
||||
s.Bus.AddHandlerCtx(s.DeleteAlertNotification)
|
||||
s.Bus.AddHandlerCtx(s.GetAllAlertNotifications)
|
||||
s.Bus.AddHandlerCtx(s.GetOrCreateAlertNotificationState)
|
||||
s.Bus.AddHandlerCtx(s.SetAlertNotificationStateToCompleteCommand)
|
||||
s.Bus.AddHandlerCtx(s.SetAlertNotificationStateToPendingCommand)
|
||||
s.Bus.AddHandlerCtx(s.GetAlertNotificationsWithUid)
|
||||
s.Bus.AddHandlerCtx(s.UpdateAlertNotificationWithUid)
|
||||
s.Bus.AddHandlerCtx(s.DeleteAlertNotificationWithUid)
|
||||
s.Bus.AddHandlerCtx(s.GetAlertNotificationsWithUidToSend)
|
||||
s.Bus.AddHandlerCtx(s.HandleNotificationTestCommand)
|
||||
s.Bus.AddHandler(s.GetAlertNotifications)
|
||||
s.Bus.AddHandler(s.CreateAlertNotificationCommand)
|
||||
s.Bus.AddHandler(s.UpdateAlertNotification)
|
||||
s.Bus.AddHandler(s.DeleteAlertNotification)
|
||||
s.Bus.AddHandler(s.GetAllAlertNotifications)
|
||||
s.Bus.AddHandler(s.GetOrCreateAlertNotificationState)
|
||||
s.Bus.AddHandler(s.SetAlertNotificationStateToCompleteCommand)
|
||||
s.Bus.AddHandler(s.SetAlertNotificationStateToPendingCommand)
|
||||
s.Bus.AddHandler(s.GetAlertNotificationsWithUid)
|
||||
s.Bus.AddHandler(s.UpdateAlertNotificationWithUid)
|
||||
s.Bus.AddHandler(s.DeleteAlertNotificationWithUid)
|
||||
s.Bus.AddHandler(s.GetAlertNotificationsWithUidToSend)
|
||||
s.Bus.AddHandler(s.HandleNotificationTestCommand)
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ func TestInitContextWithAuthProxy_CachedInvalidUserID(t *testing.T) {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
bus.AddHandlerCtx("", upsertHandler)
|
||||
bus.AddHandlerCtx("", getUserHandler)
|
||||
bus.AddHandler("", upsertHandler)
|
||||
bus.AddHandler("", getUserHandler)
|
||||
t.Cleanup(func() {
|
||||
bus.ClearBusHandlers()
|
||||
})
|
||||
|
@ -131,7 +131,7 @@ func TestMiddlewareContext_ldap(t *testing.T) {
|
||||
t.Run("Logs in via LDAP", func(t *testing.T) {
|
||||
const id int64 = 42
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpsertUserCommand) error {
|
||||
cmd.Result = &models.User{
|
||||
Id: id,
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ func setupDeleteHandlers(t *testing.T, fakeStore *fakeDashboardStore, provisione
|
||||
}
|
||||
|
||||
result := &Result{}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
require.Equal(t, cmd.Id, int64(1))
|
||||
require.Equal(t, cmd.OrgId, int64(1))
|
||||
result.deleteWasCalled = true
|
||||
|
@ -25,7 +25,7 @@ func TestFolderService(t *testing.T) {
|
||||
origNewGuardian := guardian.New
|
||||
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = models.NewDashboardFolder("Folder")
|
||||
return nil
|
||||
})
|
||||
@ -85,7 +85,7 @@ func TestFolderService(t *testing.T) {
|
||||
dash := models.NewDashboardFolder("Folder")
|
||||
dash.Id = 1
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = dash
|
||||
return nil
|
||||
})
|
||||
@ -99,12 +99,12 @@ func TestFolderService(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.SaveDashboardCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.SaveDashboardCommand) error {
|
||||
cmd.Result = dash
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.DeleteDashboardCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -139,7 +139,7 @@ func TestFolderService(t *testing.T) {
|
||||
dashFolder.Id = 1
|
||||
dashFolder.Uid = "uid-abc"
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardQuery) error {
|
||||
query.Result = dashFolder
|
||||
return nil
|
||||
})
|
||||
|
@ -23,11 +23,11 @@ func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, secretsService secret
|
||||
SecretsService: secretsService,
|
||||
}
|
||||
|
||||
s.Bus.AddHandlerCtx(s.CreateDashboardSnapshot)
|
||||
s.Bus.AddHandlerCtx(s.GetDashboardSnapshot)
|
||||
s.Bus.AddHandlerCtx(s.DeleteDashboardSnapshot)
|
||||
s.Bus.AddHandlerCtx(s.SearchDashboardSnapshots)
|
||||
s.Bus.AddHandlerCtx(s.DeleteExpiredSnapshots)
|
||||
s.Bus.AddHandler(s.CreateDashboardSnapshot)
|
||||
s.Bus.AddHandler(s.GetDashboardSnapshot)
|
||||
s.Bus.AddHandler(s.DeleteDashboardSnapshot)
|
||||
s.Bus.AddHandler(s.SearchDashboardSnapshots)
|
||||
s.Bus.AddHandler(s.DeleteExpiredSnapshots)
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -62,13 +62,13 @@ func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, secretsService secret
|
||||
},
|
||||
}
|
||||
|
||||
s.Bus.AddHandlerCtx(s.GetDataSources)
|
||||
s.Bus.AddHandlerCtx(s.GetDataSourcesByType)
|
||||
s.Bus.AddHandlerCtx(s.GetDataSource)
|
||||
s.Bus.AddHandlerCtx(s.AddDataSource)
|
||||
s.Bus.AddHandlerCtx(s.DeleteDataSource)
|
||||
s.Bus.AddHandlerCtx(s.UpdateDataSource)
|
||||
s.Bus.AddHandlerCtx(s.GetDefaultDataSource)
|
||||
s.Bus.AddHandler(s.GetDataSources)
|
||||
s.Bus.AddHandler(s.GetDataSourcesByType)
|
||||
s.Bus.AddHandler(s.GetDataSource)
|
||||
s.Bus.AddHandler(s.AddDataSource)
|
||||
s.Bus.AddHandler(s.DeleteDataSource)
|
||||
s.Bus.AddHandler(s.UpdateDataSource)
|
||||
s.Bus.AddHandler(s.GetDefaultDataSource)
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -684,7 +684,7 @@ func TestGuardianGetHiddenACL(t *testing.T) {
|
||||
t.Run("Get hidden ACL tests", func(t *testing.T) {
|
||||
bus.ClearBusHandlers()
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = []*models.DashboardAclInfoDTO{
|
||||
{Inherited: false, UserId: 1, UserLogin: "user1", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: false, UserId: 2, UserLogin: "user2", Permission: models.PERMISSION_ADMIN},
|
||||
@ -732,7 +732,7 @@ func TestGuardianGetAclWithoutDuplicates(t *testing.T) {
|
||||
t.Run("Get hidden ACL tests", func(t *testing.T) {
|
||||
t.Cleanup(bus.ClearBusHandlers)
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
query.Result = []*models.DashboardAclInfoDTO{
|
||||
{Inherited: true, UserId: 3, UserLogin: "user3", Permission: models.PERMISSION_EDIT},
|
||||
{Inherited: false, UserId: 3, UserLogin: "user3", Permission: models.PERMISSION_VIEW},
|
||||
|
@ -75,7 +75,7 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext,
|
||||
sc.t.Run(desc, func(t *testing.T) {
|
||||
bus.ClearBusHandlers()
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetDashboardAclInfoListQuery) error {
|
||||
if query.OrgID != sc.givenUser.OrgId {
|
||||
sc.reportFailure("Invalid organization id for GetDashboardAclInfoListQuery", sc.givenUser.OrgId, query.OrgID)
|
||||
}
|
||||
@ -95,7 +95,7 @@ func permissionScenario(desc string, dashboardID int64, sc *scenarioContext,
|
||||
}
|
||||
}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetTeamsByUserQuery) error {
|
||||
if query.OrgId != sc.givenUser.OrgId {
|
||||
sc.reportFailure("Invalid organization id for GetTeamsByUserQuery", sc.givenUser.OrgId, query.OrgId)
|
||||
}
|
||||
|
@ -32,11 +32,11 @@ func ProvideAuthInfoService(bus bus.Bus, store *sqlstore.SQLStore, userProtectio
|
||||
logger: log.New("login.authinfo"),
|
||||
}
|
||||
|
||||
s.Bus.AddHandlerCtx(s.GetExternalUserInfoByLogin)
|
||||
s.Bus.AddHandlerCtx(s.GetAuthInfo)
|
||||
s.Bus.AddHandlerCtx(s.SetAuthInfo)
|
||||
s.Bus.AddHandlerCtx(s.UpdateAuthInfo)
|
||||
s.Bus.AddHandlerCtx(s.DeleteAuthInfo)
|
||||
s.Bus.AddHandler(s.GetExternalUserInfoByLogin)
|
||||
s.Bus.AddHandler(s.GetAuthInfo)
|
||||
s.Bus.AddHandler(s.SetAuthInfo)
|
||||
s.Bus.AddHandler(s.UpdateAuthInfo)
|
||||
s.Bus.AddHandler(s.DeleteAuthInfo)
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func ProvideService(sqlStore *sqlstore.SQLStore, bus bus.Bus, quotaService *quot
|
||||
QuotaService: quotaService,
|
||||
AuthInfoService: authInfoService,
|
||||
}
|
||||
bus.AddHandlerCtx(s.UpsertUser)
|
||||
bus.AddHandler(s.UpsertUser)
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -20,20 +20,20 @@ func Test_syncOrgRoles_doesNotBreakWhenTryingToRemoveLastOrgAdmin(t *testing.T)
|
||||
|
||||
bus.ClearBusHandlers()
|
||||
defer bus.ClearBusHandlers()
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetUserOrgListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetUserOrgListQuery) error {
|
||||
q.Result = createUserOrgDTO()
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.RemoveOrgUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.RemoveOrgUserCommand) error {
|
||||
testData := remResp[0]
|
||||
remResp = remResp[1:]
|
||||
|
||||
require.Equal(t, testData.orgId, cmd.OrgId)
|
||||
return testData.response
|
||||
})
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.SetUsingOrgCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.SetUsingOrgCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
@ -55,20 +55,20 @@ func Test_syncOrgRoles_whenTryingToRemoveLastOrgLogsError(t *testing.T) {
|
||||
|
||||
bus.ClearBusHandlers()
|
||||
defer bus.ClearBusHandlers()
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, q *models.GetUserOrgListQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, q *models.GetUserOrgListQuery) error {
|
||||
q.Result = createUserOrgDTO()
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.RemoveOrgUserCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.RemoveOrgUserCommand) error {
|
||||
testData := remResp[0]
|
||||
remResp = remResp[1:]
|
||||
|
||||
require.Equal(t, testData.orgId, cmd.OrgId)
|
||||
return testData.response
|
||||
})
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.SetUsingOrgCommand) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.SetUsingOrgCommand) error {
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -107,7 +107,7 @@ func TestDingdingNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -151,7 +151,7 @@ func TestDiscordNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -53,7 +53,7 @@ func TestEmailNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := map[string]interface{}{}
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.SendEmailCommandSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.SendEmailCommandSync) error {
|
||||
expected["subject"] = cmd.SendEmailCommand.Subject
|
||||
expected["to"] = cmd.SendEmailCommand.To
|
||||
expected["single_email"] = cmd.SendEmailCommand.SingleEmail
|
||||
|
@ -175,7 +175,7 @@ func TestGoogleChatNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -127,7 +127,7 @@ func TestKafkaNotifier(t *testing.T) {
|
||||
|
||||
body := ""
|
||||
actUrl := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
actUrl = webhook.Url
|
||||
return nil
|
||||
|
@ -104,7 +104,7 @@ func TestLineNotifier(t *testing.T) {
|
||||
|
||||
body := ""
|
||||
var headers map[string]string
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
headers = webhook.HttpHeader
|
||||
return nil
|
||||
|
@ -183,7 +183,7 @@ func TestOpsgenieNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := "<not-sent>"
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -149,7 +149,7 @@ func TestPagerdutyNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -157,7 +157,7 @@ func TestPushoverNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -157,7 +157,7 @@ func TestSensuGoNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -132,7 +132,7 @@ func TestTeamsNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -121,7 +121,7 @@ func TestThreemaNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -104,7 +104,7 @@ func TestVictoropsNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -203,7 +203,7 @@ func TestWebhookNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
var payload *models.SendWebhookSync
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
payload = webhook
|
||||
return nil
|
||||
})
|
||||
|
@ -106,7 +106,7 @@ func TestWeComNotifier(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
body := ""
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, webhook *models.SendWebhookSync) error {
|
||||
body = webhook.Body
|
||||
return nil
|
||||
})
|
||||
|
@ -31,12 +31,12 @@ func ProvideService(bus bus.Bus, cfg *setting.Cfg) (*NotificationService, error)
|
||||
webhookQueue: make(chan *Webhook, 10),
|
||||
}
|
||||
|
||||
ns.Bus.AddHandlerCtx(ns.sendResetPasswordEmail)
|
||||
ns.Bus.AddHandlerCtx(ns.validateResetPasswordCode)
|
||||
ns.Bus.AddHandlerCtx(ns.sendEmailCommandHandler)
|
||||
ns.Bus.AddHandler(ns.sendResetPasswordEmail)
|
||||
ns.Bus.AddHandler(ns.validateResetPasswordCode)
|
||||
ns.Bus.AddHandler(ns.sendEmailCommandHandler)
|
||||
|
||||
ns.Bus.AddHandlerCtx(ns.sendEmailCommandHandlerSync)
|
||||
ns.Bus.AddHandlerCtx(ns.SendWebhookSync)
|
||||
ns.Bus.AddHandler(ns.sendEmailCommandHandlerSync)
|
||||
ns.Bus.AddHandler(ns.SendWebhookSync)
|
||||
|
||||
ns.Bus.AddEventListenerCtx(ns.signUpStartedHandler)
|
||||
ns.Bus.AddEventListenerCtx(ns.signUpCompletedHandler)
|
||||
|
@ -42,9 +42,9 @@ func ProvideService(bus bus.Bus, store *sqlstore.SQLStore, secretsService secret
|
||||
},
|
||||
}
|
||||
|
||||
s.Bus.AddHandlerCtx(s.GetPluginSettingById)
|
||||
s.Bus.AddHandlerCtx(s.UpdatePluginSetting)
|
||||
s.Bus.AddHandlerCtx(s.UpdatePluginSettingVersion)
|
||||
s.Bus.AddHandler(s.GetPluginSettingById)
|
||||
s.Bus.AddHandler(s.UpdatePluginSetting)
|
||||
s.Bus.AddHandler(s.UpdatePluginSettingVersion)
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func TestDashboardFileReader(t *testing.T) {
|
||||
setup := func() {
|
||||
bus.ClearBusHandlers()
|
||||
fakeService = mockDashboardProvisioningService()
|
||||
bus.AddHandlerCtx("test", mockGetDashboardQuery)
|
||||
bus.AddHandler("test", mockGetDashboardQuery)
|
||||
cfg = &config{
|
||||
Name: "Default",
|
||||
Type: "file",
|
||||
|
@ -20,7 +20,7 @@ func TestDuplicatesValidator(t *testing.T) {
|
||||
bus.ClearBusHandlers()
|
||||
fakeService = mockDashboardProvisioningService()
|
||||
|
||||
bus.AddHandlerCtx("test", mockGetDashboardQuery)
|
||||
bus.AddHandler("test", mockGetDashboardQuery)
|
||||
cfg := &config{
|
||||
Name: "Default",
|
||||
Type: "file",
|
||||
|
@ -33,11 +33,11 @@ func TestDatasourceAsConfig(t *testing.T) {
|
||||
setup := func() {
|
||||
fakeRepo = &fakeRepository{}
|
||||
bus.ClearBusHandlers()
|
||||
bus.AddHandlerCtx("test", mockDelete)
|
||||
bus.AddHandlerCtx("test", mockInsert)
|
||||
bus.AddHandlerCtx("test", mockUpdate)
|
||||
bus.AddHandlerCtx("test", mockGet)
|
||||
bus.AddHandlerCtx("test", mockGetOrg)
|
||||
bus.AddHandler("test", mockDelete)
|
||||
bus.AddHandler("test", mockInsert)
|
||||
bus.AddHandler("test", mockUpdate)
|
||||
bus.AddHandler("test", mockGet)
|
||||
bus.AddHandler("test", mockGetOrg)
|
||||
}
|
||||
|
||||
t.Run("when some values missing", func(t *testing.T) {
|
||||
|
@ -362,31 +362,31 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
func setupBusHandlers(sqlStore *sqlstore.SQLStore) {
|
||||
bus.AddHandlerCtx("getOrg", func(ctx context.Context, q *models.GetOrgByNameQuery) error {
|
||||
bus.AddHandler("getOrg", func(ctx context.Context, q *models.GetOrgByNameQuery) error {
|
||||
return sqlstore.GetOrgByName(ctx, q)
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("getAlertNotifications", func(ctx context.Context, q *models.GetAlertNotificationsWithUidQuery) error {
|
||||
bus.AddHandler("getAlertNotifications", func(ctx context.Context, q *models.GetAlertNotificationsWithUidQuery) error {
|
||||
return sqlStore.GetAlertNotificationsWithUid(ctx, q)
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("createAlertNotification", func(ctx context.Context, cmd *models.CreateAlertNotificationCommand) error {
|
||||
bus.AddHandler("createAlertNotification", func(ctx context.Context, cmd *models.CreateAlertNotificationCommand) error {
|
||||
return sqlStore.CreateAlertNotificationCommand(ctx, cmd)
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("updateAlertNotification", func(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error {
|
||||
bus.AddHandler("updateAlertNotification", func(ctx context.Context, cmd *models.UpdateAlertNotificationCommand) error {
|
||||
return sqlStore.UpdateAlertNotification(ctx, cmd)
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("updateAlertNotification", func(ctx context.Context, cmd *models.UpdateAlertNotificationWithUidCommand) error {
|
||||
bus.AddHandler("updateAlertNotification", func(ctx context.Context, cmd *models.UpdateAlertNotificationWithUidCommand) error {
|
||||
return sqlStore.UpdateAlertNotificationWithUid(ctx, cmd)
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
|
||||
bus.AddHandler("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
|
||||
return sqlStore.DeleteAlertNotification(ctx, cmd)
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationWithUidCommand) error {
|
||||
bus.AddHandler("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationWithUidCommand) error {
|
||||
return sqlStore.DeleteAlertNotificationWithUid(ctx, cmd)
|
||||
})
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Should apply configurations", func(t *testing.T) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
if query.Name == "Org 4" {
|
||||
query.Result = &models.Org{Id: 4}
|
||||
}
|
||||
@ -29,7 +29,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, query *models.GetPluginSettingByIdQuery) error {
|
||||
if query.PluginId == "test-plugin" && query.OrgId == 2 {
|
||||
query.Result = &models.PluginSetting{
|
||||
PluginVersion: "2.0.1",
|
||||
@ -42,7 +42,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
|
||||
sentCommands := []*models.UpdatePluginSettingCmd{}
|
||||
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.UpdatePluginSettingCmd) error {
|
||||
sentCommands = append(sentCommands, cmd)
|
||||
return nil
|
||||
})
|
||||
|
@ -19,7 +19,7 @@ func ProvideService(cfg *setting.Cfg, bus bus.Bus) *SearchService {
|
||||
SortAlphaDesc.Name: SortAlphaDesc,
|
||||
},
|
||||
}
|
||||
s.Bus.AddHandlerCtx(s.searchHandler)
|
||||
s.Bus.AddHandler(s.searchHandler)
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestSearch_SortedResults(t *testing.T) {
|
||||
bus.AddHandlerCtx("test", func(_ context.Context, query *FindPersistedDashboardsQuery) error {
|
||||
bus.AddHandler("test", func(_ context.Context, query *FindPersistedDashboardsQuery) error {
|
||||
query.Result = HitList{
|
||||
&Hit{ID: 16, Title: "CCAA", Type: "dash-db", Tags: []string{"BB", "AA"}},
|
||||
&Hit{ID: 10, Title: "AABB", Type: "dash-db", Tags: []string{"CC", "AA"}},
|
||||
@ -22,12 +22,12 @@ func TestSearch_SortedResults(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(_ context.Context, query *models.GetUserStarsQuery) error {
|
||||
bus.AddHandler("test", func(_ context.Context, query *models.GetUserStarsQuery) error {
|
||||
query.Result = map[int64]bool{10: true, 12: true}
|
||||
return nil
|
||||
})
|
||||
|
||||
bus.AddHandlerCtx("test", func(_ context.Context, query *models.GetSignedInUserQuery) error {
|
||||
bus.AddHandler("test", func(_ context.Context, query *models.GetSignedInUserQuery) error {
|
||||
query.Result = &models.SignedInUser{IsGrafanaAdmin: true}
|
||||
return nil
|
||||
})
|
||||
|
@ -15,14 +15,14 @@ import (
|
||||
var timeNow = time.Now
|
||||
|
||||
func (ss *SQLStore) addAlertQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", SaveAlerts)
|
||||
bus.AddHandlerCtx("sql", ss.HandleAlertsQuery)
|
||||
bus.AddHandlerCtx("sql", ss.GetAlertById)
|
||||
bus.AddHandlerCtx("sql", ss.GetAllAlertQueryHandler)
|
||||
bus.AddHandlerCtx("sql", ss.SetAlertState)
|
||||
bus.AddHandlerCtx("sql", ss.GetAlertStatesForDashboard)
|
||||
bus.AddHandlerCtx("sql", PauseAlert)
|
||||
bus.AddHandlerCtx("sql", PauseAllAlerts)
|
||||
bus.AddHandler("sql", SaveAlerts)
|
||||
bus.AddHandler("sql", ss.HandleAlertsQuery)
|
||||
bus.AddHandler("sql", ss.GetAlertById)
|
||||
bus.AddHandler("sql", ss.GetAllAlertQueryHandler)
|
||||
bus.AddHandler("sql", ss.SetAlertState)
|
||||
bus.AddHandler("sql", ss.GetAlertStatesForDashboard)
|
||||
bus.AddHandler("sql", PauseAlert)
|
||||
bus.AddHandler("sql", PauseAllAlerts)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetAlertById(ctx context.Context, query *models.GetAlertByIdQuery) error {
|
||||
|
@ -64,7 +64,7 @@ func (ss *SQLStore) GetAlertNotifications(ctx context.Context, query *models.Get
|
||||
}
|
||||
|
||||
func (ss *SQLStore) addAlertNotificationUidByIdHandler() {
|
||||
bus.AddHandlerCtx("sql", ss.GetAlertNotificationUidWithId)
|
||||
bus.AddHandler("sql", ss.GetAlertNotificationUidWithId)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetAlertNotificationUidWithId(ctx context.Context, query *models.GetAlertNotificationUidQuery) error {
|
||||
|
@ -23,7 +23,7 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
sqlStore := InitTestDB(t)
|
||||
|
||||
// Set up bus handlers
|
||||
bus.AddHandlerCtx("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
|
||||
bus.AddHandler("deleteAlertNotification", func(ctx context.Context, cmd *models.DeleteAlertNotificationCommand) error {
|
||||
return sqlStore.DeleteAlertNotification(ctx, cmd)
|
||||
})
|
||||
}
|
||||
|
@ -11,11 +11,11 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addAPIKeysQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.GetAPIKeys)
|
||||
bus.AddHandlerCtx("sql", ss.GetApiKeyById)
|
||||
bus.AddHandlerCtx("sql", ss.GetApiKeyByName)
|
||||
bus.AddHandlerCtx("sql", ss.DeleteApiKey)
|
||||
bus.AddHandlerCtx("sql", ss.AddAPIKey)
|
||||
bus.AddHandler("sql", ss.GetAPIKeys)
|
||||
bus.AddHandler("sql", ss.GetApiKeyById)
|
||||
bus.AddHandler("sql", ss.GetApiKeyByName)
|
||||
bus.AddHandler("sql", ss.DeleteApiKey)
|
||||
bus.AddHandler("sql", ss.AddAPIKey)
|
||||
}
|
||||
|
||||
// GetAPIKeys queries the database based
|
||||
|
@ -27,23 +27,23 @@ var shadowSearchCounter = prometheus.NewCounterVec(
|
||||
)
|
||||
|
||||
func init() {
|
||||
bus.AddHandlerCtx("sql", GetDashboard)
|
||||
bus.AddHandlerCtx("sql", GetDashboards)
|
||||
bus.AddHandlerCtx("sql", DeleteDashboard)
|
||||
bus.AddHandlerCtx("sql", GetDashboardTags)
|
||||
bus.AddHandlerCtx("sql", GetDashboardSlugById)
|
||||
bus.AddHandlerCtx("sql", GetDashboardsByPluginId)
|
||||
bus.AddHandlerCtx("sql", GetDashboardPermissionsForUser)
|
||||
bus.AddHandlerCtx("sql", GetDashboardsBySlug)
|
||||
bus.AddHandlerCtx("sql", HasEditPermissionInFolders)
|
||||
bus.AddHandlerCtx("sql", HasAdminPermissionInFolders)
|
||||
bus.AddHandler("sql", GetDashboard)
|
||||
bus.AddHandler("sql", GetDashboards)
|
||||
bus.AddHandler("sql", DeleteDashboard)
|
||||
bus.AddHandler("sql", GetDashboardTags)
|
||||
bus.AddHandler("sql", GetDashboardSlugById)
|
||||
bus.AddHandler("sql", GetDashboardsByPluginId)
|
||||
bus.AddHandler("sql", GetDashboardPermissionsForUser)
|
||||
bus.AddHandler("sql", GetDashboardsBySlug)
|
||||
bus.AddHandler("sql", HasEditPermissionInFolders)
|
||||
bus.AddHandler("sql", HasAdminPermissionInFolders)
|
||||
|
||||
prometheus.MustRegister(shadowSearchCounter)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) addDashboardQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.GetDashboardUIDById)
|
||||
bus.AddHandlerCtx("sql", ss.SearchDashboards)
|
||||
bus.AddHandler("sql", ss.GetDashboardUIDById)
|
||||
bus.AddHandler("sql", ss.SearchDashboards)
|
||||
}
|
||||
|
||||
var generateNewUid func() string = util.GenerateShortUID
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addDashboardACLQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.GetDashboardAclInfoList)
|
||||
bus.AddHandler("sql", ss.GetDashboardAclInfoList)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) UpdateDashboardACL(ctx context.Context, dashboardID int64, items []*models.DashboardAcl) error {
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
bus.AddHandlerCtx("sql", UnprovisionDashboard)
|
||||
bus.AddHandlerCtx("sql", DeleteOrphanedProvisionedDashboards)
|
||||
bus.AddHandler("sql", UnprovisionDashboard)
|
||||
bus.AddHandler("sql", DeleteOrphanedProvisionedDashboards)
|
||||
}
|
||||
|
||||
type DashboardExtras struct {
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addDashboardVersionQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.GetDashboardVersion)
|
||||
bus.AddHandlerCtx("sql", ss.GetDashboardVersions)
|
||||
bus.AddHandlerCtx("sql", ss.DeleteExpiredVersions)
|
||||
bus.AddHandler("sql", ss.GetDashboardVersion)
|
||||
bus.AddHandler("sql", ss.GetDashboardVersions)
|
||||
bus.AddHandler("sql", ss.DeleteExpiredVersions)
|
||||
}
|
||||
|
||||
// GetDashboardVersion gets the dashboard version for the given dashboard ID and version number.
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
bus.AddHandlerCtx("sql", GetDBHealthQuery)
|
||||
bus.AddHandler("sql", GetDBHealthQuery)
|
||||
}
|
||||
|
||||
// GetDBHealthQuery executes a query to check
|
||||
|
@ -12,9 +12,9 @@ import (
|
||||
var getTimeNow = time.Now
|
||||
|
||||
func init() {
|
||||
bus.AddHandlerCtx("sql", CreateLoginAttempt)
|
||||
bus.AddHandlerCtx("sql", DeleteOldLoginAttempts)
|
||||
bus.AddHandlerCtx("sql", GetUserLoginAttemptCount)
|
||||
bus.AddHandler("sql", CreateLoginAttempt)
|
||||
bus.AddHandler("sql", DeleteOldLoginAttempts)
|
||||
bus.AddHandler("sql", GetUserLoginAttemptCount)
|
||||
}
|
||||
|
||||
func CreateLoginAttempt(ctx context.Context, cmd *models.CreateLoginAttemptCommand) error {
|
||||
|
@ -16,13 +16,13 @@ import (
|
||||
const MainOrgName = "Main Org."
|
||||
|
||||
func init() {
|
||||
bus.AddHandlerCtx("sql", GetOrgById)
|
||||
bus.AddHandlerCtx("sql", CreateOrg)
|
||||
bus.AddHandlerCtx("sql", UpdateOrg)
|
||||
bus.AddHandlerCtx("sql", UpdateOrgAddress)
|
||||
bus.AddHandlerCtx("sql", GetOrgByName)
|
||||
bus.AddHandlerCtx("sql", SearchOrgs)
|
||||
bus.AddHandlerCtx("sql", DeleteOrg)
|
||||
bus.AddHandler("sql", GetOrgById)
|
||||
bus.AddHandler("sql", CreateOrg)
|
||||
bus.AddHandler("sql", UpdateOrg)
|
||||
bus.AddHandler("sql", UpdateOrgAddress)
|
||||
bus.AddHandler("sql", GetOrgByName)
|
||||
bus.AddHandler("sql", SearchOrgs)
|
||||
bus.AddHandler("sql", DeleteOrg)
|
||||
}
|
||||
|
||||
func SearchOrgs(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
|
@ -12,10 +12,10 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addOrgUsersQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.AddOrgUser)
|
||||
bus.AddHandlerCtx("sql", ss.RemoveOrgUser)
|
||||
bus.AddHandlerCtx("sql", ss.GetOrgUsers)
|
||||
bus.AddHandlerCtx("sql", ss.UpdateOrgUser)
|
||||
bus.AddHandler("sql", ss.AddOrgUser)
|
||||
bus.AddHandler("sql", ss.RemoveOrgUser)
|
||||
bus.AddHandler("sql", ss.GetOrgUsers)
|
||||
bus.AddHandler("sql", ss.UpdateOrgUser)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) AddOrgUser(ctx context.Context, cmd *models.AddOrgUserCommand) error {
|
||||
|
@ -8,12 +8,12 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addPlaylistQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.CreatePlaylist)
|
||||
bus.AddHandlerCtx("sql", ss.UpdatePlaylist)
|
||||
bus.AddHandlerCtx("sql", ss.DeletePlaylist)
|
||||
bus.AddHandlerCtx("sql", ss.SearchPlaylists)
|
||||
bus.AddHandlerCtx("sql", ss.GetPlaylist)
|
||||
bus.AddHandlerCtx("sql", ss.GetPlaylistItem)
|
||||
bus.AddHandler("sql", ss.CreatePlaylist)
|
||||
bus.AddHandler("sql", ss.UpdatePlaylist)
|
||||
bus.AddHandler("sql", ss.DeletePlaylist)
|
||||
bus.AddHandler("sql", ss.SearchPlaylists)
|
||||
bus.AddHandler("sql", ss.GetPlaylist)
|
||||
bus.AddHandler("sql", ss.GetPlaylistItem)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) CreatePlaylist(ctx context.Context, cmd *models.CreatePlaylistCommand) error {
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addPreferencesQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.GetPreferences)
|
||||
bus.AddHandlerCtx("sql", ss.GetPreferencesWithDefaults)
|
||||
bus.AddHandlerCtx("sql", ss.SavePreferences)
|
||||
bus.AddHandler("sql", ss.GetPreferences)
|
||||
bus.AddHandler("sql", ss.GetPreferencesWithDefaults)
|
||||
bus.AddHandler("sql", ss.SavePreferences)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) GetPreferencesWithDefaults(ctx context.Context, query *models.GetPreferencesWithDefaultsQuery) error {
|
||||
|
@ -16,13 +16,13 @@ const (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addQuotaQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.GetOrgQuotaByTarget)
|
||||
bus.AddHandlerCtx("sql", ss.GetOrgQuotas)
|
||||
bus.AddHandlerCtx("sql", ss.UpdateOrgQuota)
|
||||
bus.AddHandlerCtx("sql", ss.GetUserQuotaByTarget)
|
||||
bus.AddHandlerCtx("sql", ss.GetUserQuotas)
|
||||
bus.AddHandlerCtx("sql", ss.UpdateUserQuota)
|
||||
bus.AddHandlerCtx("sql", ss.GetGlobalQuotaByTarget)
|
||||
bus.AddHandler("sql", ss.GetOrgQuotaByTarget)
|
||||
bus.AddHandler("sql", ss.GetOrgQuotas)
|
||||
bus.AddHandler("sql", ss.UpdateOrgQuota)
|
||||
bus.AddHandler("sql", ss.GetUserQuotaByTarget)
|
||||
bus.AddHandler("sql", ss.GetUserQuotas)
|
||||
bus.AddHandler("sql", ss.UpdateUserQuota)
|
||||
bus.AddHandler("sql", ss.GetGlobalQuotaByTarget)
|
||||
}
|
||||
|
||||
type targetCount struct {
|
||||
|
@ -8,10 +8,10 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addStarQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.StarDashboard)
|
||||
bus.AddHandlerCtx("sql", ss.UnstarDashboard)
|
||||
bus.AddHandlerCtx("sql", ss.GetUserStars)
|
||||
bus.AddHandlerCtx("sql", ss.IsStarredByUserCtx)
|
||||
bus.AddHandler("sql", ss.StarDashboard)
|
||||
bus.AddHandler("sql", ss.UnstarDashboard)
|
||||
bus.AddHandler("sql", ss.GetUserStars)
|
||||
bus.AddHandler("sql", ss.IsStarredByUserCtx)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) IsStarredByUserCtx(ctx context.Context, query *models.IsStarredByUserQuery) error {
|
||||
|
@ -10,12 +10,12 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
bus.AddHandlerCtx("sql", GetSystemStats)
|
||||
bus.AddHandlerCtx("sql", GetDataSourceStats)
|
||||
bus.AddHandlerCtx("sql", GetDataSourceAccessStats)
|
||||
bus.AddHandlerCtx("sql", GetAdminStats)
|
||||
bus.AddHandlerCtx("sql", GetAlertNotifiersUsageStats)
|
||||
bus.AddHandlerCtx("sql", GetSystemUserCountStats)
|
||||
bus.AddHandler("sql", GetSystemStats)
|
||||
bus.AddHandler("sql", GetDataSourceStats)
|
||||
bus.AddHandler("sql", GetDataSourceAccessStats)
|
||||
bus.AddHandler("sql", GetAdminStats)
|
||||
bus.AddHandler("sql", GetAlertNotifiersUsageStats)
|
||||
bus.AddHandler("sql", GetSystemUserCountStats)
|
||||
}
|
||||
|
||||
const activeUserTimeLimit = time.Hour * 24 * 30
|
||||
|
@ -12,16 +12,16 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
bus.AddHandlerCtx("sql", UpdateTeam)
|
||||
bus.AddHandlerCtx("sql", DeleteTeam)
|
||||
bus.AddHandlerCtx("sql", SearchTeams)
|
||||
bus.AddHandlerCtx("sql", GetTeamById)
|
||||
bus.AddHandlerCtx("sql", GetTeamsByUser)
|
||||
bus.AddHandler("sql", UpdateTeam)
|
||||
bus.AddHandler("sql", DeleteTeam)
|
||||
bus.AddHandler("sql", SearchTeams)
|
||||
bus.AddHandler("sql", GetTeamById)
|
||||
bus.AddHandler("sql", GetTeamsByUser)
|
||||
|
||||
bus.AddHandlerCtx("sql", UpdateTeamMember)
|
||||
bus.AddHandlerCtx("sql", RemoveTeamMember)
|
||||
bus.AddHandlerCtx("sql", GetTeamMembers)
|
||||
bus.AddHandlerCtx("sql", IsAdminOfTeams)
|
||||
bus.AddHandler("sql", UpdateTeamMember)
|
||||
bus.AddHandler("sql", RemoveTeamMember)
|
||||
bus.AddHandler("sql", GetTeamMembers)
|
||||
bus.AddHandler("sql", IsAdminOfTeams)
|
||||
}
|
||||
|
||||
func getFilteredUsers(signedInUser *models.SignedInUser, hiddenUsers map[string]struct{}) []string {
|
||||
|
@ -9,12 +9,12 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addTempUserQueryAndCommandHandlers() {
|
||||
bus.AddHandlerCtx("sql", ss.CreateTempUser)
|
||||
bus.AddHandlerCtx("sql", ss.GetTempUsersQuery)
|
||||
bus.AddHandlerCtx("sql", ss.UpdateTempUserStatus)
|
||||
bus.AddHandlerCtx("sql", ss.GetTempUserByCode)
|
||||
bus.AddHandlerCtx("sql", ss.UpdateTempUserWithEmailSent)
|
||||
bus.AddHandlerCtx("sql", ss.ExpireOldUserInvites)
|
||||
bus.AddHandler("sql", ss.CreateTempUser)
|
||||
bus.AddHandler("sql", ss.GetTempUsersQuery)
|
||||
bus.AddHandler("sql", ss.UpdateTempUserStatus)
|
||||
bus.AddHandler("sql", ss.GetTempUserByCode)
|
||||
bus.AddHandler("sql", ss.UpdateTempUserWithEmailSent)
|
||||
bus.AddHandler("sql", ss.ExpireOldUserInvites)
|
||||
}
|
||||
|
||||
func (ss *SQLStore) UpdateTempUserStatus(ctx context.Context, cmd *models.UpdateTempUserStatusCommand) error {
|
||||
|
@ -18,22 +18,22 @@ import (
|
||||
)
|
||||
|
||||
func (ss *SQLStore) addUserQueryAndCommandHandlers() {
|
||||
ss.Bus.AddHandlerCtx(ss.GetSignedInUserWithCacheCtx)
|
||||
ss.Bus.AddHandler(ss.GetSignedInUserWithCacheCtx)
|
||||
|
||||
bus.AddHandlerCtx("sql", GetUserById)
|
||||
bus.AddHandlerCtx("sql", UpdateUser)
|
||||
bus.AddHandlerCtx("sql", ChangeUserPassword)
|
||||
bus.AddHandlerCtx("sql", ss.GetUserByLogin)
|
||||
bus.AddHandlerCtx("sql", ss.GetUserByEmail)
|
||||
bus.AddHandlerCtx("sql", SetUsingOrg)
|
||||
bus.AddHandlerCtx("sql", UpdateUserLastSeenAt)
|
||||
bus.AddHandlerCtx("sql", ss.GetUserProfile)
|
||||
bus.AddHandlerCtx("sql", SearchUsers)
|
||||
bus.AddHandlerCtx("sql", GetUserOrgList)
|
||||
bus.AddHandlerCtx("sql", DisableUser)
|
||||
bus.AddHandlerCtx("sql", BatchDisableUsers)
|
||||
bus.AddHandlerCtx("sql", DeleteUser)
|
||||
bus.AddHandlerCtx("sql", SetUserHelpFlag)
|
||||
bus.AddHandler("sql", GetUserById)
|
||||
bus.AddHandler("sql", UpdateUser)
|
||||
bus.AddHandler("sql", ChangeUserPassword)
|
||||
bus.AddHandler("sql", ss.GetUserByLogin)
|
||||
bus.AddHandler("sql", ss.GetUserByEmail)
|
||||
bus.AddHandler("sql", SetUsingOrg)
|
||||
bus.AddHandler("sql", UpdateUserLastSeenAt)
|
||||
bus.AddHandler("sql", ss.GetUserProfile)
|
||||
bus.AddHandler("sql", SearchUsers)
|
||||
bus.AddHandler("sql", GetUserOrgList)
|
||||
bus.AddHandler("sql", DisableUser)
|
||||
bus.AddHandler("sql", BatchDisableUsers)
|
||||
bus.AddHandler("sql", DeleteUser)
|
||||
bus.AddHandler("sql", SetUserHelpFlag)
|
||||
}
|
||||
|
||||
func getOrgIdForNewUser(sess *DBSession, cmd models.CreateUserCommand) (int64, error) {
|
||||
|
@ -31,7 +31,7 @@ func TestUpdateTeam(t *testing.T) {
|
||||
|
||||
t.Run("Given an editor and a team he isn't a member of", func(t *testing.T) {
|
||||
t.Run("Should not be able to update the team", func(t *testing.T) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetTeamMembersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetTeamMembersQuery) error {
|
||||
cmd.Result = []*models.TeamMemberDTO{}
|
||||
return nil
|
||||
})
|
||||
@ -43,7 +43,7 @@ func TestUpdateTeam(t *testing.T) {
|
||||
|
||||
t.Run("Given an editor and a team he is an admin in", func(t *testing.T) {
|
||||
t.Run("Should be able to update the team", func(t *testing.T) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetTeamMembersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetTeamMembersQuery) error {
|
||||
cmd.Result = []*models.TeamMemberDTO{{
|
||||
OrgId: testTeam.OrgId,
|
||||
TeamId: testTeam.Id,
|
||||
@ -65,7 +65,7 @@ func TestUpdateTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("Shouldn't be able to update the team", func(t *testing.T) {
|
||||
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *models.GetTeamMembersQuery) error {
|
||||
bus.AddHandler("test", func(ctx context.Context, cmd *models.GetTeamMembersQuery) error {
|
||||
cmd.Result = []*models.TeamMemberDTO{{
|
||||
OrgId: testTeamOtherOrg.OrgId,
|
||||
TeamId: testTeamOtherOrg.Id,
|
||||
|
@ -80,9 +80,9 @@ func TestTestReceivers(t *testing.T) {
|
||||
|
||||
oldEmailBus := bus.GetHandlerCtx("SendEmailCommandSync")
|
||||
mockEmails := &mockEmailHandler{}
|
||||
bus.AddHandlerCtx("", mockEmails.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmails.sendEmailCommandHandlerSync)
|
||||
t.Cleanup(func() {
|
||||
bus.AddHandlerCtx("", oldEmailBus)
|
||||
bus.AddHandler("", oldEmailBus)
|
||||
})
|
||||
|
||||
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr)
|
||||
@ -166,9 +166,9 @@ func TestTestReceivers(t *testing.T) {
|
||||
|
||||
oldEmailBus := bus.GetHandlerCtx("SendEmailCommandSync")
|
||||
mockEmails := &mockEmailHandler{}
|
||||
bus.AddHandlerCtx("", mockEmails.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmails.sendEmailCommandHandlerSync)
|
||||
t.Cleanup(func() {
|
||||
bus.AddHandlerCtx("", oldEmailBus)
|
||||
bus.AddHandler("", oldEmailBus)
|
||||
})
|
||||
|
||||
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr)
|
||||
@ -249,9 +249,9 @@ func TestTestReceivers(t *testing.T) {
|
||||
mockEmails := &mockEmailHandlerWithTimeout{
|
||||
timeout: 5 * time.Second,
|
||||
}
|
||||
bus.AddHandlerCtx("", mockEmails.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmails.sendEmailCommandHandlerSync)
|
||||
t.Cleanup(func() {
|
||||
bus.AddHandlerCtx("", oldEmailBus)
|
||||
bus.AddHandler("", oldEmailBus)
|
||||
})
|
||||
|
||||
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr)
|
||||
@ -340,9 +340,9 @@ func TestTestReceivers(t *testing.T) {
|
||||
mockEmails := &mockEmailHandlerWithTimeout{
|
||||
timeout: 5 * time.Second,
|
||||
}
|
||||
bus.AddHandlerCtx("", mockEmails.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmails.sendEmailCommandHandlerSync)
|
||||
t.Cleanup(func() {
|
||||
bus.AddHandlerCtx("", oldEmailBus)
|
||||
bus.AddHandler("", oldEmailBus)
|
||||
})
|
||||
|
||||
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr)
|
||||
@ -455,9 +455,9 @@ func TestTestReceiversAlertCustomization(t *testing.T) {
|
||||
|
||||
oldEmailBus := bus.GetHandlerCtx("SendEmailCommandSync")
|
||||
mockEmails := &mockEmailHandler{}
|
||||
bus.AddHandlerCtx("", mockEmails.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmails.sendEmailCommandHandlerSync)
|
||||
t.Cleanup(func() {
|
||||
bus.AddHandlerCtx("", oldEmailBus)
|
||||
bus.AddHandler("", oldEmailBus)
|
||||
})
|
||||
|
||||
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr)
|
||||
@ -552,9 +552,9 @@ func TestTestReceiversAlertCustomization(t *testing.T) {
|
||||
|
||||
oldEmailBus := bus.GetHandlerCtx("SendEmailCommandSync")
|
||||
mockEmails := &mockEmailHandler{}
|
||||
bus.AddHandlerCtx("", mockEmails.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmails.sendEmailCommandHandlerSync)
|
||||
t.Cleanup(func() {
|
||||
bus.AddHandlerCtx("", oldEmailBus)
|
||||
bus.AddHandler("", oldEmailBus)
|
||||
})
|
||||
|
||||
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr)
|
||||
@ -644,9 +644,9 @@ func TestTestReceiversAlertCustomization(t *testing.T) {
|
||||
|
||||
oldEmailBus := bus.GetHandlerCtx("SendEmailCommandSync")
|
||||
mockEmails := &mockEmailHandler{}
|
||||
bus.AddHandlerCtx("", mockEmails.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmails.sendEmailCommandHandlerSync)
|
||||
t.Cleanup(func() {
|
||||
bus.AddHandlerCtx("", oldEmailBus)
|
||||
bus.AddHandler("", oldEmailBus)
|
||||
})
|
||||
|
||||
testReceiversURL := fmt.Sprintf("http://grafana:password@%s/api/alertmanager/grafana/config/api/v1/receivers/test", grafanaListedAddr)
|
||||
@ -743,7 +743,7 @@ func TestNotificationChannels(t *testing.T) {
|
||||
channels.TelegramAPIURL, channels.PushoverEndpoint, channels.GetBoundary,
|
||||
channels.LineNotifyURL, channels.ThreemaGwBaseURL = os, opa, ot, opu, ogb, ol, oth
|
||||
channels.DefaultTemplateString = originalTemplate
|
||||
bus.AddHandlerCtx("", originalEmailBus)
|
||||
bus.AddHandler("", originalEmailBus)
|
||||
})
|
||||
channels.DefaultTemplateString = channels.TemplateForTestsString
|
||||
channels.SlackAPIEndpoint = fmt.Sprintf("http://%s/slack_recvX/slack_testX", mockChannel.server.Addr)
|
||||
@ -753,7 +753,7 @@ func TestNotificationChannels(t *testing.T) {
|
||||
channels.LineNotifyURL = fmt.Sprintf("http://%s/line_recv/line_test", mockChannel.server.Addr)
|
||||
channels.ThreemaGwBaseURL = fmt.Sprintf("http://%s/threema_recv/threema_test", mockChannel.server.Addr)
|
||||
channels.GetBoundary = func() string { return "abcd" }
|
||||
bus.AddHandlerCtx("", mockEmail.sendEmailCommandHandlerSync)
|
||||
bus.AddHandler("", mockEmail.sendEmailCommandHandlerSync)
|
||||
|
||||
// Create a user to make authenticated requests
|
||||
createUser(t, s, models.CreateUserCommand{
|
||||
|
Loading…
Reference in New Issue
Block a user