Rename DispatchCtx to Dispatch (#43563)

This commit is contained in:
idafurjes 2021-12-28 17:36:22 +01:00 committed by GitHub
parent 7936c4c522
commit 8e6d6af744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
107 changed files with 291 additions and 291 deletions

View File

@ -22,7 +22,7 @@ func (hs *HTTPServer) AdminGetSettings(c *models.ReqContext) response.Response {
func AdminGetStats(c *models.ReqContext) response.Response { func AdminGetStats(c *models.ReqContext) response.Response {
statsQuery := models.GetAdminStatsQuery{} statsQuery := models.GetAdminStatsQuery{}
if err := bus.DispatchCtx(c.Req.Context(), &statsQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &statsQuery); err != nil {
return response.Error(500, "Failed to get admin stats from database", err) return response.Error(500, "Failed to get admin stats from database", err)
} }

View File

@ -75,7 +75,7 @@ func AdminUpdateUserPassword(c *models.ReqContext) response.Response {
userQuery := models.GetUserByIdQuery{Id: userID} userQuery := models.GetUserByIdQuery{Id: userID}
if err := bus.DispatchCtx(c.Req.Context(), &userQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &userQuery); err != nil {
return response.Error(500, "Could not read user from database", err) return response.Error(500, "Could not read user from database", err)
} }
@ -89,7 +89,7 @@ func AdminUpdateUserPassword(c *models.ReqContext) response.Response {
NewPassword: passwordHashed, NewPassword: passwordHashed,
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to update user password", err) return response.Error(500, "Failed to update user password", err)
} }
@ -121,7 +121,7 @@ func AdminDeleteUser(c *models.ReqContext) response.Response {
cmd := models.DeleteUserCommand{UserId: userID} cmd := models.DeleteUserCommand{UserId: userID}
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, models.ErrUserNotFound.Error(), nil) return response.Error(404, models.ErrUserNotFound.Error(), nil)
} }
@ -137,12 +137,12 @@ func (hs *HTTPServer) AdminDisableUser(c *models.ReqContext) response.Response {
// External users shouldn't be disabled from API // External users shouldn't be disabled from API
authInfoQuery := &models.GetAuthInfoQuery{UserId: userID} authInfoQuery := &models.GetAuthInfoQuery{UserId: userID}
if err := bus.DispatchCtx(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) { if err := bus.Dispatch(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) {
return response.Error(500, "Could not disable external user", nil) return response.Error(500, "Could not disable external user", nil)
} }
disableCmd := models.DisableUserCommand{UserId: userID, IsDisabled: true} disableCmd := models.DisableUserCommand{UserId: userID, IsDisabled: true}
if err := bus.DispatchCtx(c.Req.Context(), &disableCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &disableCmd); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, models.ErrUserNotFound.Error(), nil) return response.Error(404, models.ErrUserNotFound.Error(), nil)
} }
@ -163,12 +163,12 @@ func AdminEnableUser(c *models.ReqContext) response.Response {
// External users shouldn't be disabled from API // External users shouldn't be disabled from API
authInfoQuery := &models.GetAuthInfoQuery{UserId: userID} authInfoQuery := &models.GetAuthInfoQuery{UserId: userID}
if err := bus.DispatchCtx(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) { if err := bus.Dispatch(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) {
return response.Error(500, "Could not enable external user", nil) return response.Error(500, "Could not enable external user", nil)
} }
disableCmd := models.DisableUserCommand{UserId: userID, IsDisabled: false} disableCmd := models.DisableUserCommand{UserId: userID, IsDisabled: false}
if err := bus.DispatchCtx(c.Req.Context(), &disableCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &disableCmd); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, models.ErrUserNotFound.Error(), nil) return response.Error(404, models.ErrUserNotFound.Error(), nil)
} }

View File

@ -24,7 +24,7 @@ func ValidateOrgAlert(c *models.ReqContext) {
id := c.ParamsInt64(":alertId") id := c.ParamsInt64(":alertId")
query := models.GetAlertByIdQuery{Id: id} query := models.GetAlertByIdQuery{Id: id}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
c.JsonApiErr(404, "Alert not found", nil) c.JsonApiErr(404, "Alert not found", nil)
return return
} }
@ -47,7 +47,7 @@ func GetAlertStatesForDashboard(c *models.ReqContext) response.Response {
DashboardId: c.QueryInt64("dashboardId"), DashboardId: c.QueryInt64("dashboardId"),
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to fetch alert states", err) return response.Error(500, "Failed to fetch alert states", err)
} }
@ -90,7 +90,7 @@ func GetAlerts(c *models.ReqContext) response.Response {
Permission: models.PERMISSION_VIEW, Permission: models.PERMISSION_VIEW,
} }
err := bus.DispatchCtx(c.Req.Context(), &searchQuery) err := bus.Dispatch(c.Req.Context(), &searchQuery)
if err != nil { if err != nil {
return response.Error(500, "List alerts failed", err) return response.Error(500, "List alerts failed", err)
} }
@ -121,7 +121,7 @@ func GetAlerts(c *models.ReqContext) response.Response {
query.State = states query.State = states
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "List alerts failed", err) return response.Error(500, "List alerts failed", err)
} }
@ -181,7 +181,7 @@ func GetAlert(c *models.ReqContext) response.Response {
id := c.ParamsInt64(":alertId") id := c.ParamsInt64(":alertId")
query := models.GetAlertByIdQuery{Id: id} query := models.GetAlertByIdQuery{Id: id}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "List alerts failed", err) return response.Error(500, "List alerts failed", err)
} }
@ -232,7 +232,7 @@ func GetAlertNotifications(c *models.ReqContext) response.Response {
func getAlertNotificationsInternal(c *models.ReqContext) ([]*models.AlertNotification, error) { func getAlertNotificationsInternal(c *models.ReqContext) ([]*models.AlertNotification, error) {
query := &models.GetAllAlertNotificationsQuery{OrgId: c.OrgId} query := &models.GetAllAlertNotificationsQuery{OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil { if err := bus.Dispatch(c.Req.Context(), query); err != nil {
return nil, err return nil, err
} }
@ -249,7 +249,7 @@ func GetAlertNotificationByID(c *models.ReqContext) response.Response {
return response.Error(404, "Alert notification not found", nil) return response.Error(404, "Alert notification not found", nil)
} }
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil { if err := bus.Dispatch(c.Req.Context(), query); err != nil {
return response.Error(500, "Failed to get alert notifications", err) return response.Error(500, "Failed to get alert notifications", err)
} }
@ -270,7 +270,7 @@ func GetAlertNotificationByUID(c *models.ReqContext) response.Response {
return response.Error(404, "Alert notification not found", nil) return response.Error(404, "Alert notification not found", nil)
} }
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil { if err := bus.Dispatch(c.Req.Context(), query); err != nil {
return response.Error(500, "Failed to get alert notifications", err) return response.Error(500, "Failed to get alert notifications", err)
} }
@ -288,7 +288,7 @@ func CreateAlertNotification(c *models.ReqContext) response.Response {
} }
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationWithSameNameExists) || errors.Is(err, models.ErrAlertNotificationWithSameUIDExists) { if errors.Is(err, models.ErrAlertNotificationWithSameNameExists) || errors.Is(err, models.ErrAlertNotificationWithSameUIDExists) {
return response.Error(409, "Failed to create alert notification", err) return response.Error(409, "Failed to create alert notification", err)
} }
@ -314,7 +314,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res
return response.Error(500, "Failed to update alert notification", err) return response.Error(500, "Failed to update alert notification", err)
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), err) return response.Error(404, err.Error(), err)
} }
@ -330,7 +330,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res
Id: cmd.Id, Id: cmd.Id,
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to get alert notification", err) return response.Error(500, "Failed to get alert notification", err)
} }
@ -350,7 +350,7 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons
return response.Error(500, "Failed to update alert notification", err) return response.Error(500, "Failed to update alert notification", err)
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil) return response.Error(404, err.Error(), nil)
} }
@ -362,7 +362,7 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons
Uid: cmd.Uid, Uid: cmd.Uid,
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to get alert notification", err) return response.Error(500, "Failed to get alert notification", err)
} }
@ -379,7 +379,7 @@ func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *model
Id: cmd.Id, Id: cmd.Id,
} }
if err := bus.DispatchCtx(ctx, query); err != nil { if err := bus.Dispatch(ctx, query); err != nil {
return err return err
} }
@ -407,7 +407,7 @@ func (hs *HTTPServer) fillWithSecureSettingsDataByUID(ctx context.Context, cmd *
Uid: cmd.Uid, Uid: cmd.Uid,
} }
if err := bus.DispatchCtx(ctx, query); err != nil { if err := bus.Dispatch(ctx, query); err != nil {
return err return err
} }
@ -431,7 +431,7 @@ func DeleteAlertNotification(c *models.ReqContext) response.Response {
Id: c.ParamsInt64(":notificationId"), Id: c.ParamsInt64(":notificationId"),
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil) return response.Error(404, err.Error(), nil)
} }
@ -447,7 +447,7 @@ func DeleteAlertNotificationByUID(c *models.ReqContext) response.Response {
Uid: web.Params(c.Req)[":uid"], Uid: web.Params(c.Req)[":uid"],
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrAlertNotificationNotFound) { if errors.Is(err, models.ErrAlertNotificationNotFound) {
return response.Error(404, err.Error(), nil) return response.Error(404, err.Error(), nil)
} }
@ -475,7 +475,7 @@ func NotificationTest(c *models.ReqContext) response.Response {
SecureSettings: dto.SecureSettings, SecureSettings: dto.SecureSettings,
} }
if err := bus.DispatchCtx(c.Req.Context(), cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), cmd); err != nil {
if errors.Is(err, models.ErrSmtpNotEnabled) { if errors.Is(err, models.ErrSmtpNotEnabled) {
return response.Error(412, err.Error(), err) return response.Error(412, err.Error(), err)
} }
@ -501,7 +501,7 @@ func PauseAlert(c *models.ReqContext) response.Response {
result["alertId"] = alertID result["alertId"] = alertID
query := models.GetAlertByIdQuery{Id: alertID} query := models.GetAlertByIdQuery{Id: alertID}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Get Alert failed", err) return response.Error(500, "Get Alert failed", err)
} }
@ -531,7 +531,7 @@ func PauseAlert(c *models.ReqContext) response.Response {
Paused: dto.Paused, Paused: dto.Paused,
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "", err) return response.Error(500, "", err)
} }
@ -557,7 +557,7 @@ func PauseAllAlerts(c *models.ReqContext) response.Response {
Paused: dto.Paused, Paused: dto.Paused,
} }
if err := bus.DispatchCtx(c.Req.Context(), &updateCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &updateCmd); err != nil {
return response.Error(500, "Failed to pause alerts", err) return response.Error(500, "Failed to pause alerts", err)
} }

View File

@ -17,7 +17,7 @@ import (
func GetAPIKeys(c *models.ReqContext) response.Response { func GetAPIKeys(c *models.ReqContext) response.Response {
query := models.GetApiKeysQuery{OrgId: c.OrgId, IncludeExpired: c.QueryBool("includeExpired")} query := models.GetApiKeysQuery{OrgId: c.OrgId, IncludeExpired: c.QueryBool("includeExpired")}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to list api keys", err) return response.Error(500, "Failed to list api keys", err)
} }
@ -45,7 +45,7 @@ func DeleteAPIKey(c *models.ReqContext) response.Response {
cmd := &models.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId} cmd := &models.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId}
err := bus.DispatchCtx(c.Req.Context(), cmd) err := bus.Dispatch(c.Req.Context(), cmd)
if err != nil { if err != nil {
var status int var status int
if errors.Is(err, models.ErrApiKeyNotFound) { if errors.Is(err, models.ErrApiKeyNotFound) {
@ -94,7 +94,7 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext) response.Response {
//Check if user and service account are in the same org //Check if user and service account are in the same org
query := models.GetUserByIdQuery{Id: cmd.ServiceAccountId} query := models.GetUserByIdQuery{Id: cmd.ServiceAccountId}
err = bus.DispatchCtx(c.Req.Context(), &query) err = bus.Dispatch(c.Req.Context(), &query)
if err != nil { if err != nil {
hs.log.Warn("Unable to link new API key to existing service account", "err", err, "query", query) hs.log.Warn("Unable to link new API key to existing service account", "err", err, "query", query)
return response.Error(500, "Unable to link new API key to existing service account", err) return response.Error(500, "Unable to link new API key to existing service account", err)
@ -118,7 +118,7 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext) response.Response {
cmd.Key = newKeyInfo.HashedKey cmd.Key = newKeyInfo.HashedKey
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrInvalidApiKeyExpiration) { if errors.Is(err, models.ErrInvalidApiKeyExpiration) {
return response.Error(400, err.Error(), nil) return response.Error(400, err.Error(), nil)
} }

View File

@ -34,7 +34,7 @@ func isDashboardStarredByUser(c *models.ReqContext, dashID int64) (bool, error)
} }
query := models.IsStarredByUserQuery{UserId: c.UserId, DashboardId: dashID} query := models.IsStarredByUserQuery{UserId: c.UserId, DashboardId: dashID}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return false, err return false, err
} }
@ -142,7 +142,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
// lookup folder title // lookup folder title
if dash.FolderId > 0 { if dash.FolderId > 0 {
query := models.GetDashboardQuery{Id: dash.FolderId, OrgId: c.OrgId} query := models.GetDashboardQuery{Id: dash.FolderId, OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrFolderNotFound) { if errors.Is(err, models.ErrFolderNotFound) {
return response.Error(404, "Folder not found", err) return response.Error(404, "Folder not found", err)
} }
@ -196,7 +196,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
func getUserLogin(ctx context.Context, userID int64) string { func getUserLogin(ctx context.Context, userID int64) string {
query := models.GetUserByIdQuery{Id: userID} query := models.GetUserByIdQuery{Id: userID}
err := bus.DispatchCtx(ctx, &query) err := bus.Dispatch(ctx, &query)
if err != nil { if err != nil {
return anonString return anonString
} }
@ -212,7 +212,7 @@ func getDashboardHelper(ctx context.Context, orgID int64, id int64, uid string)
query = models.GetDashboardQuery{Id: id, OrgId: orgID} query = models.GetDashboardQuery{Id: id, OrgId: orgID}
} }
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return nil, response.Error(404, "Dashboard not found", err) return nil, response.Error(404, "Dashboard not found", err)
} }
@ -222,7 +222,7 @@ func getDashboardHelper(ctx context.Context, orgID int64, id int64, uid string)
func (hs *HTTPServer) DeleteDashboardBySlug(c *models.ReqContext) response.Response { func (hs *HTTPServer) DeleteDashboardBySlug(c *models.ReqContext) response.Response {
query := models.GetDashboardsBySlugQuery{OrgId: c.OrgId, Slug: web.Params(c.Req)[":slug"]} query := models.GetDashboardsBySlugQuery{OrgId: c.OrgId, Slug: web.Params(c.Req)[":slug"]}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to retrieve dashboards by slug", err) return response.Error(500, "Failed to retrieve dashboards by slug", err)
} }
@ -448,7 +448,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser} prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
homePage := hs.Cfg.HomePage homePage := hs.Cfg.HomePage
if err := hs.Bus.DispatchCtx(c.Req.Context(), &prefsQuery); err != nil { if err := hs.Bus.Dispatch(c.Req.Context(), &prefsQuery); err != nil {
return response.Error(500, "Failed to get preferences", err) return response.Error(500, "Failed to get preferences", err)
} }
@ -459,7 +459,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
if prefsQuery.Result.HomeDashboardId != 0 { if prefsQuery.Result.HomeDashboardId != 0 {
slugQuery := models.GetDashboardRefByIdQuery{Id: prefsQuery.Result.HomeDashboardId} slugQuery := models.GetDashboardRefByIdQuery{Id: prefsQuery.Result.HomeDashboardId}
err := hs.Bus.DispatchCtx(c.Req.Context(), &slugQuery) err := hs.Bus.Dispatch(c.Req.Context(), &slugQuery)
if err == nil { if err == nil {
url := models.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug) url := models.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug)
dashRedirect := dtos.DashboardRedirect{RedirectUri: url} dashRedirect := dtos.DashboardRedirect{RedirectUri: url}
@ -543,7 +543,7 @@ func GetDashboardVersions(c *models.ReqContext) response.Response {
Start: c.QueryInt("start"), Start: c.QueryInt("start"),
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(404, fmt.Sprintf("No versions found for dashboardId %d", dashID), err) return response.Error(404, fmt.Sprintf("No versions found for dashboardId %d", dashID), err)
} }
@ -582,7 +582,7 @@ func GetDashboardVersion(c *models.ReqContext) response.Response {
Version: int(version), Version: int(version),
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, fmt.Sprintf("Dashboard version %d not found for dashboardId %d", query.Version, dashID), err) return response.Error(500, fmt.Sprintf("Dashboard version %d not found for dashboardId %d", query.Version, dashID), err)
} }
@ -671,7 +671,7 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext) response.Res
} }
versionQuery := models.GetDashboardVersionQuery{DashboardId: dash.Id, Version: apiCmd.Version, OrgId: c.OrgId} versionQuery := models.GetDashboardVersionQuery{DashboardId: dash.Id, Version: apiCmd.Version, OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), &versionQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &versionQuery); err != nil {
return response.Error(404, "Dashboard version not found", nil) return response.Error(404, "Dashboard version not found", nil)
} }
@ -692,7 +692,7 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext) response.Res
func GetDashboardTags(c *models.ReqContext) { func GetDashboardTags(c *models.ReqContext) {
query := models.GetDashboardTagsQuery{OrgId: c.OrgId} query := models.GetDashboardTagsQuery{OrgId: c.OrgId}
err := bus.DispatchCtx(c.Req.Context(), &query) err := bus.Dispatch(c.Req.Context(), &query)
if err != nil { if err != nil {
c.JsonApiErr(500, "Failed to get tags from database", err) c.JsonApiErr(500, "Failed to get tags from database", err)
return return

View File

@ -134,7 +134,7 @@ func CreateDashboardSnapshot(c *models.ReqContext) response.Response {
metrics.MApiDashboardSnapshotCreate.Inc() metrics.MApiDashboardSnapshotCreate.Inc()
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
c.JsonApiErr(500, "Failed to create snapshot", err) c.JsonApiErr(500, "Failed to create snapshot", err)
return nil return nil
} }
@ -158,7 +158,7 @@ func GetDashboardSnapshot(c *models.ReqContext) response.Response {
query := &models.GetDashboardSnapshotQuery{Key: key} query := &models.GetDashboardSnapshotQuery{Key: key}
err := bus.DispatchCtx(c.Req.Context(), query) err := bus.Dispatch(c.Req.Context(), query)
if err != nil { if err != nil {
return response.Error(500, "Failed to get dashboard snapshot", err) return response.Error(500, "Failed to get dashboard snapshot", err)
} }
@ -226,7 +226,7 @@ func DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) response.Response
query := &models.GetDashboardSnapshotQuery{DeleteKey: key} query := &models.GetDashboardSnapshotQuery{DeleteKey: key}
err := bus.DispatchCtx(c.Req.Context(), query) err := bus.Dispatch(c.Req.Context(), query)
if err != nil { if err != nil {
return response.Error(500, "Failed to get dashboard snapshot", err) return response.Error(500, "Failed to get dashboard snapshot", err)
} }
@ -240,7 +240,7 @@ func DeleteDashboardSnapshotByDeleteKey(c *models.ReqContext) response.Response
cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey} cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey}
if err := bus.DispatchCtx(c.Req.Context(), cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), cmd); err != nil {
return response.Error(500, "Failed to delete dashboard snapshot", err) return response.Error(500, "Failed to delete dashboard snapshot", err)
} }
@ -259,7 +259,7 @@ func DeleteDashboardSnapshot(c *models.ReqContext) response.Response {
query := &models.GetDashboardSnapshotQuery{Key: key} query := &models.GetDashboardSnapshotQuery{Key: key}
err := bus.DispatchCtx(c.Req.Context(), query) err := bus.Dispatch(c.Req.Context(), query)
if err != nil { if err != nil {
return response.Error(500, "Failed to get dashboard snapshot", err) return response.Error(500, "Failed to get dashboard snapshot", err)
} }
@ -288,7 +288,7 @@ func DeleteDashboardSnapshot(c *models.ReqContext) response.Response {
cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey} cmd := &models.DeleteDashboardSnapshotCommand{DeleteKey: query.Result.DeleteKey}
if err := bus.DispatchCtx(c.Req.Context(), cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), cmd); err != nil {
return response.Error(500, "Failed to delete dashboard snapshot", err) return response.Error(500, "Failed to delete dashboard snapshot", err)
} }
@ -314,7 +314,7 @@ func SearchDashboardSnapshots(c *models.ReqContext) response.Response {
SignedInUser: c.SignedInUser, SignedInUser: c.SignedInUser,
} }
err := bus.DispatchCtx(c.Req.Context(), &searchQuery) err := bus.Dispatch(c.Req.Context(), &searchQuery)
if err != nil { if err != nil {
return response.Error(500, "Search failed", err) return response.Error(500, "Search failed", err)
} }

View File

@ -26,7 +26,7 @@ var datasourcesLogger = log.New("datasources")
func (hs *HTTPServer) GetDataSources(c *models.ReqContext) response.Response { func (hs *HTTPServer) GetDataSources(c *models.ReqContext) response.Response {
query := models.GetDataSourcesQuery{OrgId: c.OrgId, DataSourceLimit: hs.Cfg.DataSourceLimit} query := models.GetDataSourcesQuery{OrgId: c.OrgId, DataSourceLimit: hs.Cfg.DataSourceLimit}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to query datasources", err) return response.Error(500, "Failed to query datasources", err)
} }
@ -92,7 +92,7 @@ func (hs *HTTPServer) GetDataSourceById(c *models.ReqContext) response.Response
OrgId: c.OrgId, OrgId: c.OrgId,
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrDataSourceNotFound) { if errors.Is(err, models.ErrDataSourceNotFound) {
return response.Error(404, "Data source not found", nil) return response.Error(404, "Data source not found", nil)
} }
@ -136,7 +136,7 @@ func (hs *HTTPServer) DeleteDataSourceById(c *models.ReqContext) response.Respon
cmd := &models.DeleteDataSourceCommand{ID: id, OrgID: c.OrgId} cmd := &models.DeleteDataSourceCommand{ID: id, OrgID: c.OrgId}
err = bus.DispatchCtx(c.Req.Context(), cmd) err = bus.Dispatch(c.Req.Context(), cmd)
if err != nil { if err != nil {
return response.Error(500, "Failed to delete datasource", err) return response.Error(500, "Failed to delete datasource", err)
} }
@ -191,7 +191,7 @@ func (hs *HTTPServer) DeleteDataSourceByUID(c *models.ReqContext) response.Respo
cmd := &models.DeleteDataSourceCommand{UID: uid, OrgID: c.OrgId} cmd := &models.DeleteDataSourceCommand{UID: uid, OrgID: c.OrgId}
err = bus.DispatchCtx(c.Req.Context(), cmd) err = bus.Dispatch(c.Req.Context(), cmd)
if err != nil { if err != nil {
return response.Error(500, "Failed to delete datasource", err) return response.Error(500, "Failed to delete datasource", err)
} }
@ -212,7 +212,7 @@ func (hs *HTTPServer) DeleteDataSourceByName(c *models.ReqContext) response.Resp
} }
getCmd := &models.GetDataSourceQuery{Name: name, OrgId: c.OrgId} getCmd := &models.GetDataSourceQuery{Name: name, OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), getCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), getCmd); err != nil {
if errors.Is(err, models.ErrDataSourceNotFound) { if errors.Is(err, models.ErrDataSourceNotFound) {
return response.Error(404, "Data source not found", nil) return response.Error(404, "Data source not found", nil)
} }
@ -224,7 +224,7 @@ func (hs *HTTPServer) DeleteDataSourceByName(c *models.ReqContext) response.Resp
} }
cmd := &models.DeleteDataSourceCommand{Name: name, OrgID: c.OrgId} cmd := &models.DeleteDataSourceCommand{Name: name, OrgID: c.OrgId}
err := bus.DispatchCtx(c.Req.Context(), cmd) err := bus.Dispatch(c.Req.Context(), cmd)
if err != nil { if err != nil {
return response.Error(500, "Failed to delete datasource", err) return response.Error(500, "Failed to delete datasource", err)
} }
@ -260,7 +260,7 @@ func AddDataSource(c *models.ReqContext) response.Response {
return resp return resp
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrDataSourceNameExists) || errors.Is(err, models.ErrDataSourceUidExists) { if errors.Is(err, models.ErrDataSourceNameExists) || errors.Is(err, models.ErrDataSourceUidExists) {
return response.Error(409, err.Error(), err) return response.Error(409, err.Error(), err)
} }
@ -294,7 +294,7 @@ func (hs *HTTPServer) UpdateDataSource(c *models.ReqContext) response.Response {
return response.Error(500, "Failed to update datasource", err) return response.Error(500, "Failed to update datasource", err)
} }
err = bus.DispatchCtx(c.Req.Context(), &cmd) err = bus.Dispatch(c.Req.Context(), &cmd)
if err != nil { if err != nil {
if errors.Is(err, models.ErrDataSourceUpdatingOldVersion) { if errors.Is(err, models.ErrDataSourceUpdatingOldVersion) {
return response.Error(409, "Datasource has already been updated by someone else. Please reload and try again", err) return response.Error(409, "Datasource has already been updated by someone else. Please reload and try again", err)
@ -307,7 +307,7 @@ func (hs *HTTPServer) UpdateDataSource(c *models.ReqContext) response.Response {
OrgId: c.OrgId, OrgId: c.OrgId,
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrDataSourceNotFound) { if errors.Is(err, models.ErrDataSourceNotFound) {
return response.Error(404, "Data source not found", nil) return response.Error(404, "Data source not found", nil)
} }
@ -359,7 +359,7 @@ func getRawDataSourceById(ctx context.Context, id int64, orgID int64) (*models.D
OrgId: orgID, OrgId: orgID,
} }
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return nil, err return nil, err
} }
@ -372,7 +372,7 @@ func getRawDataSourceByUID(ctx context.Context, uid string, orgID int64) (*model
OrgId: orgID, OrgId: orgID,
} }
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return nil, err return nil, err
} }
@ -383,7 +383,7 @@ func getRawDataSourceByUID(ctx context.Context, uid string, orgID int64) (*model
func GetDataSourceByName(c *models.ReqContext) response.Response { func GetDataSourceByName(c *models.ReqContext) response.Response {
query := models.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgId: c.OrgId} query := models.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrDataSourceNotFound) { if errors.Is(err, models.ErrDataSourceNotFound) {
return response.Error(404, "Data source not found", nil) return response.Error(404, "Data source not found", nil)
} }
@ -398,7 +398,7 @@ func GetDataSourceByName(c *models.ReqContext) response.Response {
func GetDataSourceIdByName(c *models.ReqContext) response.Response { func GetDataSourceIdByName(c *models.ReqContext) response.Response {
query := models.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgId: c.OrgId} query := models.GetDataSourceQuery{Name: web.Params(c.Req)[":name"], OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrDataSourceNotFound) { if errors.Is(err, models.ErrDataSourceNotFound) {
return response.Error(404, "Data source not found", nil) return response.Error(404, "Data source not found", nil)
} }

View File

@ -19,7 +19,7 @@ func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins Enab
if c.OrgId != 0 { if c.OrgId != 0 {
query := models.GetDataSourcesQuery{OrgId: c.OrgId, DataSourceLimit: hs.Cfg.DataSourceLimit} query := models.GetDataSourcesQuery{OrgId: c.OrgId, DataSourceLimit: hs.Cfg.DataSourceLimit}
err := bus.DispatchCtx(c.Req.Context(), &query) err := bus.Dispatch(c.Req.Context(), &query)
if err != nil { if err != nil {
return nil, err return nil, err
@ -30,7 +30,7 @@ func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins Enab
Datasources: query.Result, Datasources: query.Result,
} }
if err := bus.DispatchCtx(c.Req.Context(), &dsFilterQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &dsFilterQuery); err != nil {
if !errors.Is(err, bus.ErrHandlerNotFound) { if !errors.Is(err, bus.ErrHandlerNotFound) {
return nil, err return nil, err
} }

View File

@ -15,7 +15,7 @@ func (hs *HTTPServer) databaseHealthy(ctx context.Context) bool {
return cached.(bool) return cached.(bool)
} }
healthy := bus.DispatchCtx(ctx, &models.GetDBHealthQuery{}) == nil healthy := bus.Dispatch(ctx, &models.GetDBHealthQuery{}) == nil
hs.CacheService.Set(cacheKey, healthy, time.Second*5) hs.CacheService.Set(cacheKey, healthy, time.Second*5)
return healthy return healthy

View File

@ -519,7 +519,7 @@ func (hs *HTTPServer) buildAdminNavLinks(c *models.ReqContext) []*dtos.NavLink {
func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewData, error) { func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewData, error) {
hasEditPermissionInFoldersQuery := models.HasEditPermissionInFoldersQuery{SignedInUser: c.SignedInUser} hasEditPermissionInFoldersQuery := models.HasEditPermissionInFoldersQuery{SignedInUser: c.SignedInUser}
if err := bus.DispatchCtx(c.Req.Context(), &hasEditPermissionInFoldersQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &hasEditPermissionInFoldersQuery); err != nil {
return nil, err return nil, err
} }
hasEditPerm := hasEditPermissionInFoldersQuery.Result hasEditPerm := hasEditPermissionInFoldersQuery.Result
@ -532,7 +532,7 @@ func (hs *HTTPServer) setIndexViewData(c *models.ReqContext) (*dtos.IndexViewDat
settings["dateFormats"] = hs.Cfg.DateFormats settings["dateFormats"] = hs.Cfg.DateFormats
prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser} prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
if err := bus.DispatchCtx(c.Req.Context(), &prefsQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &prefsQuery); err != nil {
return nil, err return nil, err
} }
prefs := prefsQuery.Result prefs := prefsQuery.Result

View File

@ -73,7 +73,7 @@ func (user *LDAPUserDTO) FetchOrgs(ctx context.Context) error {
q := &models.SearchOrgsQuery{} q := &models.SearchOrgsQuery{}
q.Ids = orgIds q.Ids = orgIds
if err := bus.DispatchCtx(ctx, q); err != nil { if err := bus.Dispatch(ctx, q); err != nil {
return err return err
} }
@ -167,7 +167,7 @@ func (hs *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) response.Respon
query := models.GetUserByIdQuery{Id: userId} query := models.GetUserByIdQuery{Id: userId}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { // validate the userId exists if err := bus.Dispatch(c.Req.Context(), &query); err != nil { // validate the userId exists
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, models.ErrUserNotFound.Error(), nil) return response.Error(404, models.ErrUserNotFound.Error(), nil)
} }
@ -177,7 +177,7 @@ func (hs *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) response.Respon
authModuleQuery := &models.GetAuthInfoQuery{UserId: query.Result.Id, AuthModule: models.AuthModuleLDAP} authModuleQuery := &models.GetAuthInfoQuery{UserId: query.Result.Id, AuthModule: models.AuthModuleLDAP}
if err := bus.DispatchCtx(c.Req.Context(), authModuleQuery); err != nil { // validate the userId comes from LDAP if err := bus.Dispatch(c.Req.Context(), authModuleQuery); err != nil { // validate the userId comes from LDAP
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, models.ErrUserNotFound.Error(), nil) return response.Error(404, models.ErrUserNotFound.Error(), nil)
} }
@ -219,7 +219,7 @@ func (hs *HTTPServer) PostSyncUserWithLDAP(c *models.ReqContext) response.Respon
SignupAllowed: hs.Cfg.LDAPAllowSignup, SignupAllowed: hs.Cfg.LDAPAllowSignup,
} }
err = bus.DispatchCtx(c.Req.Context(), upsertCmd) err = bus.Dispatch(c.Req.Context(), upsertCmd)
if err != nil { if err != nil {
return response.Error(http.StatusInternalServerError, "Failed to update the user", err) return response.Error(http.StatusInternalServerError, "Failed to update the user", err)
} }
@ -308,7 +308,7 @@ func (hs *HTTPServer) GetUserFromLDAP(c *models.ReqContext) response.Response {
} }
cmd := &models.GetTeamsForLDAPGroupCommand{Groups: user.Groups} cmd := &models.GetTeamsForLDAPGroupCommand{Groups: user.Groups}
err = bus.DispatchCtx(c.Req.Context(), cmd) err = bus.Dispatch(c.Req.Context(), cmd)
if err != nil && !errors.Is(err, bus.ErrHandlerNotFound) { if err != nil && !errors.Is(err, bus.ErrHandlerNotFound) {
return response.Error(http.StatusBadRequest, "Unable to find the teams for this user", err) return response.Error(http.StatusBadRequest, "Unable to find the teams for this user", err)
} }

View File

@ -207,7 +207,7 @@ func (hs *HTTPServer) LoginPost(c *models.ReqContext) response.Response {
Cfg: hs.Cfg, Cfg: hs.Cfg,
} }
err := bus.DispatchCtx(c.Req.Context(), authQuery) err := bus.Dispatch(c.Req.Context(), authQuery)
authModule = authQuery.AuthModule authModule = authQuery.AuthModule
if err != nil { if err != nil {
resp = response.Error(401, "Invalid username or password", err) resp = response.Error(401, "Invalid username or password", err)

View File

@ -313,7 +313,7 @@ func syncUser(
ExternalUser: extUser, ExternalUser: extUser,
SignupAllowed: connect.IsSignupAllowed(), SignupAllowed: connect.IsSignupAllowed(),
} }
if err := bus.DispatchCtx(ctx.Req.Context(), cmd); err != nil { if err := bus.Dispatch(ctx.Req.Context(), cmd); err != nil {
return nil, err return nil, err
} }

View File

@ -20,7 +20,7 @@ import (
func GetPendingOrgInvites(c *models.ReqContext) response.Response { func GetPendingOrgInvites(c *models.ReqContext) response.Response {
query := models.GetTempUsersQuery{OrgId: c.OrgId, Status: models.TmpUserInvitePending} query := models.GetTempUsersQuery{OrgId: c.OrgId, Status: models.TmpUserInvitePending}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to get invites from db", err) return response.Error(500, "Failed to get invites from db", err)
} }
@ -42,7 +42,7 @@ func AddOrgInvite(c *models.ReqContext) response.Response {
// first try get existing user // first try get existing user
userQuery := models.GetUserByLoginQuery{LoginOrEmail: inviteDto.LoginOrEmail} userQuery := models.GetUserByLoginQuery{LoginOrEmail: inviteDto.LoginOrEmail}
if err := bus.DispatchCtx(c.Req.Context(), &userQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &userQuery); err != nil {
if !errors.Is(err, models.ErrUserNotFound) { if !errors.Is(err, models.ErrUserNotFound) {
return response.Error(500, "Failed to query db for existing user check", err) return response.Error(500, "Failed to query db for existing user check", err)
} }
@ -68,7 +68,7 @@ func AddOrgInvite(c *models.ReqContext) response.Response {
cmd.Role = inviteDto.Role cmd.Role = inviteDto.Role
cmd.RemoteAddr = c.Req.RemoteAddr cmd.RemoteAddr = c.Req.RemoteAddr
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to save invite to database", err) return response.Error(500, "Failed to save invite to database", err)
} }
@ -86,7 +86,7 @@ func AddOrgInvite(c *models.ReqContext) response.Response {
}, },
} }
if err := bus.DispatchCtx(c.Req.Context(), &emailCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &emailCmd); err != nil {
if errors.Is(err, models.ErrSmtpNotEnabled) { if errors.Is(err, models.ErrSmtpNotEnabled) {
return response.Error(412, err.Error(), err) return response.Error(412, err.Error(), err)
} }
@ -95,7 +95,7 @@ func AddOrgInvite(c *models.ReqContext) response.Response {
} }
emailSentCmd := models.UpdateTempUserWithEmailSentCommand{Code: cmd.Result.Code} emailSentCmd := models.UpdateTempUserWithEmailSentCommand{Code: cmd.Result.Code}
if err := bus.DispatchCtx(c.Req.Context(), &emailSentCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &emailSentCmd); err != nil {
return response.Error(500, "Failed to update invite with email sent info", err) return response.Error(500, "Failed to update invite with email sent info", err)
} }
@ -108,7 +108,7 @@ func AddOrgInvite(c *models.ReqContext) response.Response {
func inviteExistingUserToOrg(c *models.ReqContext, user *models.User, inviteDto *dtos.AddInviteForm) response.Response { func inviteExistingUserToOrg(c *models.ReqContext, user *models.User, inviteDto *dtos.AddInviteForm) response.Response {
// user exists, add org role // user exists, add org role
createOrgUserCmd := models.AddOrgUserCommand{OrgId: c.OrgId, UserId: user.Id, Role: inviteDto.Role} createOrgUserCmd := models.AddOrgUserCommand{OrgId: c.OrgId, UserId: user.Id, Role: inviteDto.Role}
if err := bus.DispatchCtx(c.Req.Context(), &createOrgUserCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &createOrgUserCmd); err != nil {
if errors.Is(err, models.ErrOrgUserAlreadyAdded) { if errors.Is(err, models.ErrOrgUserAlreadyAdded) {
return response.Error(412, fmt.Sprintf("User %s is already added to organization", inviteDto.LoginOrEmail), err) return response.Error(412, fmt.Sprintf("User %s is already added to organization", inviteDto.LoginOrEmail), err)
} }
@ -126,7 +126,7 @@ func inviteExistingUserToOrg(c *models.ReqContext, user *models.User, inviteDto
}, },
} }
if err := bus.DispatchCtx(c.Req.Context(), &emailCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &emailCmd); err != nil {
return response.Error(500, "Failed to send email invited_to_org", err) return response.Error(500, "Failed to send email invited_to_org", err)
} }
} }
@ -150,7 +150,7 @@ func RevokeInvite(c *models.ReqContext) response.Response {
// If a (pending) invite is not found, 404 is returned. // If a (pending) invite is not found, 404 is returned.
func GetInviteInfoByCode(c *models.ReqContext) response.Response { func GetInviteInfoByCode(c *models.ReqContext) response.Response {
query := models.GetTempUserByCodeQuery{Code: web.Params(c.Req)[":code"]} query := models.GetTempUserByCodeQuery{Code: web.Params(c.Req)[":code"]}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrTempUserNotFound) { if errors.Is(err, models.ErrTempUserNotFound) {
return response.Error(404, "Invite not found", nil) return response.Error(404, "Invite not found", nil)
} }
@ -177,7 +177,7 @@ func (hs *HTTPServer) CompleteInvite(c *models.ReqContext) response.Response {
} }
query := models.GetTempUserByCodeQuery{Code: completeInvite.InviteCode} query := models.GetTempUserByCodeQuery{Code: completeInvite.InviteCode}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrTempUserNotFound) { if errors.Is(err, models.ErrTempUserNotFound) {
return response.Error(404, "Invite not found", nil) return response.Error(404, "Invite not found", nil)
} }
@ -234,7 +234,7 @@ func (hs *HTTPServer) CompleteInvite(c *models.ReqContext) response.Response {
func updateTempUserStatus(ctx context.Context, code string, status models.TempUserStatus) (bool, response.Response) { func updateTempUserStatus(ctx context.Context, code string, status models.TempUserStatus) (bool, response.Response) {
// update temp user status // update temp user status
updateTmpUserCmd := models.UpdateTempUserStatusCommand{Code: code, Status: status} updateTmpUserCmd := models.UpdateTempUserStatusCommand{Code: code, Status: status}
if err := bus.DispatchCtx(ctx, &updateTmpUserCmd); err != nil { if err := bus.Dispatch(ctx, &updateTmpUserCmd); err != nil {
return false, response.Error(500, "Failed to update invite status", err) return false, response.Error(500, "Failed to update invite status", err)
} }
@ -244,7 +244,7 @@ func updateTempUserStatus(ctx context.Context, code string, status models.TempUs
func applyUserInvite(ctx context.Context, user *models.User, invite *models.TempUserDTO, setActive bool) (bool, response.Response) { func applyUserInvite(ctx context.Context, user *models.User, invite *models.TempUserDTO, setActive bool) (bool, response.Response) {
// add to org // add to org
addOrgUserCmd := models.AddOrgUserCommand{OrgId: invite.OrgId, UserId: user.Id, Role: invite.Role} addOrgUserCmd := models.AddOrgUserCommand{OrgId: invite.OrgId, UserId: user.Id, Role: invite.Role}
if err := bus.DispatchCtx(ctx, &addOrgUserCmd); err != nil { if err := bus.Dispatch(ctx, &addOrgUserCmd); err != nil {
if !errors.Is(err, models.ErrOrgUserAlreadyAdded) { if !errors.Is(err, models.ErrOrgUserAlreadyAdded) {
return false, response.Error(500, "Error while trying to create org user", err) return false, response.Error(500, "Error while trying to create org user", err)
} }
@ -257,7 +257,7 @@ func applyUserInvite(ctx context.Context, user *models.User, invite *models.Temp
if setActive { if setActive {
// set org to active // set org to active
if err := bus.DispatchCtx(ctx, &models.SetUsingOrgCommand{OrgId: invite.OrgId, UserId: user.Id}); err != nil { if err := bus.Dispatch(ctx, &models.SetUsingOrgCommand{OrgId: invite.OrgId, UserId: user.Id}); err != nil {
return false, response.Error(500, "Failed to set org as active", err) return false, response.Error(500, "Failed to set org as active", err)
} }
} }

View File

@ -27,13 +27,13 @@ func SendResetPasswordEmail(c *models.ReqContext) response.Response {
userQuery := models.GetUserByLoginQuery{LoginOrEmail: form.UserOrEmail} userQuery := models.GetUserByLoginQuery{LoginOrEmail: form.UserOrEmail}
if err := bus.DispatchCtx(c.Req.Context(), &userQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &userQuery); err != nil {
c.Logger.Info("Requested password reset for user that was not found", "user", userQuery.LoginOrEmail) c.Logger.Info("Requested password reset for user that was not found", "user", userQuery.LoginOrEmail)
return response.Error(200, "Email sent", err) return response.Error(200, "Email sent", err)
} }
emailCmd := models.SendResetPasswordEmailCommand{User: userQuery.Result} emailCmd := models.SendResetPasswordEmailCommand{User: userQuery.Result}
if err := bus.DispatchCtx(c.Req.Context(), &emailCmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &emailCmd); err != nil {
return response.Error(500, "Failed to send email", err) return response.Error(500, "Failed to send email", err)
} }
@ -47,7 +47,7 @@ func ResetPassword(c *models.ReqContext) response.Response {
} }
query := models.ValidateResetPasswordCodeQuery{Code: form.Code} query := models.ValidateResetPasswordCodeQuery{Code: form.Code}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrInvalidEmailCode) { if errors.Is(err, models.ErrInvalidEmailCode) {
return response.Error(400, "Invalid or expired reset password code", nil) return response.Error(400, "Invalid or expired reset password code", nil)
} }
@ -66,7 +66,7 @@ func ResetPassword(c *models.ReqContext) response.Response {
return response.Error(500, "Failed to encode password", err) return response.Error(500, "Failed to encode password", err)
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to change user password", err) return response.Error(500, "Failed to change user password", err)
} }

View File

@ -13,7 +13,7 @@ import (
func ValidateOrgPlaylist(c *models.ReqContext) { func ValidateOrgPlaylist(c *models.ReqContext) {
id := c.ParamsInt64(":id") id := c.ParamsInt64(":id")
query := models.GetPlaylistByIdQuery{Id: id} query := models.GetPlaylistByIdQuery{Id: id}
err := bus.DispatchCtx(c.Req.Context(), &query) err := bus.Dispatch(c.Req.Context(), &query)
if err != nil { if err != nil {
c.JsonApiErr(404, "Playlist not found", err) c.JsonApiErr(404, "Playlist not found", err)
@ -45,7 +45,7 @@ func SearchPlaylists(c *models.ReqContext) response.Response {
OrgId: c.OrgId, OrgId: c.OrgId,
} }
err := bus.DispatchCtx(c.Req.Context(), &searchQuery) err := bus.Dispatch(c.Req.Context(), &searchQuery)
if err != nil { if err != nil {
return response.Error(500, "Search failed", err) return response.Error(500, "Search failed", err)
} }
@ -57,7 +57,7 @@ func GetPlaylist(c *models.ReqContext) response.Response {
id := c.ParamsInt64(":id") id := c.ParamsInt64(":id")
cmd := models.GetPlaylistByIdQuery{Id: id} cmd := models.GetPlaylistByIdQuery{Id: id}
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Playlist not found", err) return response.Error(500, "Playlist not found", err)
} }
@ -99,7 +99,7 @@ func LoadPlaylistItemDTOs(ctx context.Context, id int64) ([]models.PlaylistItemD
func LoadPlaylistItems(ctx context.Context, id int64) ([]models.PlaylistItem, error) { func LoadPlaylistItems(ctx context.Context, id int64) ([]models.PlaylistItem, error) {
itemQuery := models.GetPlaylistItemsByIdQuery{PlaylistId: id} itemQuery := models.GetPlaylistItemsByIdQuery{PlaylistId: id}
if err := bus.DispatchCtx(ctx, &itemQuery); err != nil { if err := bus.Dispatch(ctx, &itemQuery); err != nil {
return nil, err return nil, err
} }
@ -133,7 +133,7 @@ func DeletePlaylist(c *models.ReqContext) response.Response {
id := c.ParamsInt64(":id") id := c.ParamsInt64(":id")
cmd := models.DeletePlaylistCommand{Id: id, OrgId: c.OrgId} cmd := models.DeletePlaylistCommand{Id: id, OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to delete playlist", err) return response.Error(500, "Failed to delete playlist", err)
} }
@ -147,7 +147,7 @@ func CreatePlaylist(c *models.ReqContext) response.Response {
} }
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to create playlist", err) return response.Error(500, "Failed to create playlist", err)
} }
@ -162,7 +162,7 @@ func UpdatePlaylist(c *models.ReqContext) response.Response {
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
cmd.Id = c.ParamsInt64(":id") cmd.Id = c.ParamsInt64(":id")
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to save playlist", err) return response.Error(500, "Failed to save playlist", err)
} }

View File

@ -17,7 +17,7 @@ func populateDashboardsByID(ctx context.Context, dashboardByIDs []int64, dashboa
if len(dashboardByIDs) > 0 { if len(dashboardByIDs) > 0 {
dashboardQuery := models.GetDashboardsQuery{DashboardIds: dashboardByIDs} dashboardQuery := models.GetDashboardsQuery{DashboardIds: dashboardByIDs}
if err := bus.DispatchCtx(ctx, &dashboardQuery); err != nil { if err := bus.Dispatch(ctx, &dashboardQuery); err != nil {
return result, err return result, err
} }
@ -49,7 +49,7 @@ func populateDashboardsByTag(ctx context.Context, orgID int64, signedInUser *mod
OrgId: orgID, OrgId: orgID,
} }
if err := bus.DispatchCtx(ctx, &searchQuery); err == nil { if err := bus.Dispatch(ctx, &searchQuery); err == nil {
for _, item := range searchQuery.Result { for _, item := range searchQuery.Result {
result = append(result, dtos.PlaylistDashboard{ result = append(result, dtos.PlaylistDashboard{
Id: item.ID, Id: item.ID,

View File

@ -25,7 +25,7 @@ func NewApiPluginProxy(ctx *models.ReqContext, proxyPath string, route *plugins.
appID string, cfg *setting.Cfg, secretsService secrets.Service) *httputil.ReverseProxy { appID string, cfg *setting.Cfg, secretsService secrets.Service) *httputil.ReverseProxy {
director := func(req *http.Request) { director := func(req *http.Request) {
query := models.GetPluginSettingByIdQuery{OrgId: ctx.OrgId, PluginId: appID} query := models.GetPluginSettingByIdQuery{OrgId: ctx.OrgId, PluginId: appID}
if err := bus.DispatchCtx(ctx.Req.Context(), &query); err != nil { if err := bus.Dispatch(ctx.Req.Context(), &query); err != nil {
ctx.JsonApiErr(500, "Failed to fetch plugin settings", err) ctx.JsonApiErr(500, "Failed to fetch plugin settings", err)
return return
} }

View File

@ -141,7 +141,7 @@ func (hs *HTTPServer) GetPluginSettingByID(c *models.ReqContext) response.Respon
} }
query := models.GetPluginSettingByIdQuery{PluginId: pluginID, OrgId: c.OrgId} query := models.GetPluginSettingByIdQuery{PluginId: pluginID, OrgId: c.OrgId}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if !errors.Is(err, models.ErrPluginSettingNotFound) { if !errors.Is(err, models.ErrPluginSettingNotFound) {
return response.Error(500, "Failed to get login settings", nil) return response.Error(500, "Failed to get login settings", nil)
} }
@ -167,7 +167,7 @@ func (hs *HTTPServer) UpdatePluginSetting(c *models.ReqContext) response.Respons
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
cmd.PluginId = pluginID cmd.PluginId = pluginID
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to update plugin setting", err) return response.Error(500, "Failed to update plugin setting", err)
} }

View File

@ -26,7 +26,7 @@ func SetHomeDashboard(c *models.ReqContext) response.Response {
cmd.UserId = c.UserId cmd.UserId = c.UserId
cmd.OrgId = c.OrgId cmd.OrgId = c.OrgId
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to set home dashboard", err) return response.Error(500, "Failed to set home dashboard", err)
} }

View File

@ -58,7 +58,7 @@ func GetUserQuotas(c *models.ReqContext) response.Response {
} }
query := models.GetUserQuotasQuery{UserId: c.ParamsInt64(":id")} query := models.GetUserQuotasQuery{UserId: c.ParamsInt64(":id")}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to get org quotas", err) return response.Error(500, "Failed to get org quotas", err)
} }
@ -80,7 +80,7 @@ func UpdateUserQuota(c *models.ReqContext) response.Response {
return response.Error(404, "Invalid quota target", nil) return response.Error(404, "Invalid quota target", nil)
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to update org quotas", err) return response.Error(500, "Failed to update org quotas", err)
} }
return response.Success("Organization quota updated") return response.Success("Organization quota updated")

View File

@ -62,7 +62,7 @@ func Search(c *models.ReqContext) response.Response {
Sort: sort, Sort: sort,
} }
err := bus.DispatchCtx(c.Req.Context(), &searchQuery) err := bus.Dispatch(c.Req.Context(), &searchQuery)
if err != nil { if err != nil {
return response.Error(500, "Search failed", err) return response.Error(500, "Search failed", err)
} }

View File

@ -35,7 +35,7 @@ func SignUp(c *models.ReqContext) response.Response {
} }
existing := models.GetUserByLoginQuery{LoginOrEmail: form.Email} existing := models.GetUserByLoginQuery{LoginOrEmail: form.Email}
if err := bus.DispatchCtx(c.Req.Context(), &existing); err == nil { if err := bus.Dispatch(c.Req.Context(), &existing); err == nil {
return response.Error(422, "User with same email address already exists", nil) return response.Error(422, "User with same email address already exists", nil)
} }
@ -51,7 +51,7 @@ func SignUp(c *models.ReqContext) response.Response {
} }
cmd.RemoteAddr = c.Req.RemoteAddr cmd.RemoteAddr = c.Req.RemoteAddr
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to create signup", err) return response.Error(500, "Failed to create signup", err)
} }
@ -116,7 +116,7 @@ func (hs *HTTPServer) SignUpStep2(c *models.ReqContext) response.Response {
// check for pending invites // check for pending invites
invitesQuery := models.GetTempUsersQuery{Email: form.Email, Status: models.TmpUserInvitePending} invitesQuery := models.GetTempUsersQuery{Email: form.Email, Status: models.TmpUserInvitePending}
if err := bus.DispatchCtx(c.Req.Context(), &invitesQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &invitesQuery); err != nil {
return response.Error(500, "Failed to query database for invites", err) return response.Error(500, "Failed to query database for invites", err)
} }
@ -141,7 +141,7 @@ func (hs *HTTPServer) SignUpStep2(c *models.ReqContext) response.Response {
func verifyUserSignUpEmail(ctx context.Context, email string, code string) (bool, response.Response) { func verifyUserSignUpEmail(ctx context.Context, email string, code string) (bool, response.Response) {
query := models.GetTempUserByCodeQuery{Code: code} query := models.GetTempUserByCodeQuery{Code: code}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
if errors.Is(err, models.ErrTempUserNotFound) { if errors.Is(err, models.ErrTempUserNotFound) {
return false, response.Error(404, "Invalid email verification code", nil) return false, response.Error(404, "Invalid email verification code", nil)
} }

View File

@ -13,7 +13,7 @@ func StarDashboard(c *models.ReqContext) response.Response {
return response.Error(400, "Missing dashboard id", nil) return response.Error(400, "Missing dashboard id", nil)
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to star dashboard", err) return response.Error(500, "Failed to star dashboard", err)
} }
@ -27,7 +27,7 @@ func UnstarDashboard(c *models.ReqContext) response.Response {
return response.Error(400, "Missing dashboard id", nil) return response.Error(400, "Missing dashboard id", nil)
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to unstar dashboard", err) return response.Error(500, "Failed to unstar dashboard", err)
} }

View File

@ -65,7 +65,7 @@ func (hs *HTTPServer) UpdateTeam(c *models.ReqContext) response.Response {
return response.Error(403, "Not allowed to update team", err) return response.Error(403, "Not allowed to update team", err)
} }
if err := hs.Bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := hs.Bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrTeamNameTaken) { if errors.Is(err, models.ErrTeamNameTaken) {
return response.Error(400, "Team name taken", err) return response.Error(400, "Team name taken", err)
} }
@ -85,7 +85,7 @@ func (hs *HTTPServer) DeleteTeamByID(c *models.ReqContext) response.Response {
return response.Error(403, "Not allowed to delete team", err) return response.Error(403, "Not allowed to delete team", err)
} }
if err := hs.Bus.DispatchCtx(c.Req.Context(), &models.DeleteTeamCommand{OrgId: orgId, Id: teamId}); err != nil { if err := hs.Bus.Dispatch(c.Req.Context(), &models.DeleteTeamCommand{OrgId: orgId, Id: teamId}); err != nil {
if errors.Is(err, models.ErrTeamNotFound) { if errors.Is(err, models.ErrTeamNotFound) {
return response.Error(404, "Failed to delete Team. ID not found", nil) return response.Error(404, "Failed to delete Team. ID not found", nil)
} }
@ -121,7 +121,7 @@ func (hs *HTTPServer) SearchTeams(c *models.ReqContext) response.Response {
HiddenUsers: hs.Cfg.HiddenUsers, HiddenUsers: hs.Cfg.HiddenUsers,
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to search Teams", err) return response.Error(500, "Failed to search Teams", err)
} }
@ -144,7 +144,7 @@ func (hs *HTTPServer) GetTeamByID(c *models.ReqContext) response.Response {
HiddenUsers: hs.Cfg.HiddenUsers, HiddenUsers: hs.Cfg.HiddenUsers,
} }
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrTeamNotFound) { if errors.Is(err, models.ErrTeamNotFound) {
return response.Error(404, "Team not found", err) return response.Error(404, "Team not found", err)
} }

View File

@ -18,7 +18,7 @@ import (
func (hs *HTTPServer) GetTeamMembers(c *models.ReqContext) response.Response { func (hs *HTTPServer) GetTeamMembers(c *models.ReqContext) response.Response {
query := models.GetTeamMembersQuery{OrgId: c.OrgId, TeamId: c.ParamsInt64(":teamId")} query := models.GetTeamMembersQuery{OrgId: c.OrgId, TeamId: c.ParamsInt64(":teamId")}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
return response.Error(500, "Failed to get Team Members", err) return response.Error(500, "Failed to get Team Members", err)
} }
@ -94,7 +94,7 @@ func (hs *HTTPServer) UpdateTeamMember(c *models.ReqContext) response.Response {
cmd.UserId = c.ParamsInt64(":userId") cmd.UserId = c.ParamsInt64(":userId")
cmd.OrgId = orgId cmd.OrgId = orgId
if err := hs.Bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := hs.Bus.Dispatch(c.Req.Context(), &cmd); err != nil {
if errors.Is(err, models.ErrTeamMemberNotFound) { if errors.Is(err, models.ErrTeamMemberNotFound) {
return response.Error(404, "Team member not found.", nil) return response.Error(404, "Team member not found.", nil)
} }
@ -118,7 +118,7 @@ func (hs *HTTPServer) RemoveTeamMember(c *models.ReqContext) response.Response {
protectLastAdmin = true protectLastAdmin = true
} }
if err := hs.Bus.DispatchCtx(c.Req.Context(), &models.RemoveTeamMemberCommand{OrgId: orgId, TeamId: teamId, UserId: userId, ProtectLastAdmin: protectLastAdmin}); err != nil { if err := hs.Bus.Dispatch(c.Req.Context(), &models.RemoveTeamMemberCommand{OrgId: orgId, TeamId: teamId, UserId: userId, ProtectLastAdmin: protectLastAdmin}); err != nil {
if errors.Is(err, models.ErrTeamNotFound) { if errors.Is(err, models.ErrTeamNotFound) {
return response.Error(404, "Team not found", nil) return response.Error(404, "Team not found", nil)
} }

View File

@ -27,7 +27,7 @@ func GetUserByID(c *models.ReqContext) response.Response {
func getUserUserProfile(ctx context.Context, userID int64) response.Response { func getUserUserProfile(ctx context.Context, userID int64) response.Response {
query := models.GetUserProfileQuery{UserId: userID} query := models.GetUserProfileQuery{UserId: userID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, models.ErrUserNotFound.Error(), nil) return response.Error(404, models.ErrUserNotFound.Error(), nil)
} }
@ -36,7 +36,7 @@ func getUserUserProfile(ctx context.Context, userID int64) response.Response {
getAuthQuery := models.GetAuthInfoQuery{UserId: userID} getAuthQuery := models.GetAuthInfoQuery{UserId: userID}
query.Result.AuthLabels = []string{} query.Result.AuthLabels = []string{}
if err := bus.DispatchCtx(ctx, &getAuthQuery); err == nil { if err := bus.Dispatch(ctx, &getAuthQuery); err == nil {
authLabel := GetAuthProviderLabel(getAuthQuery.Result.AuthModule) authLabel := GetAuthProviderLabel(getAuthQuery.Result.AuthModule)
query.Result.AuthLabels = append(query.Result.AuthLabels, authLabel) query.Result.AuthLabels = append(query.Result.AuthLabels, authLabel)
query.Result.IsExternal = true query.Result.IsExternal = true
@ -50,7 +50,7 @@ func getUserUserProfile(ctx context.Context, userID int64) response.Response {
// GET /api/users/lookup // GET /api/users/lookup
func GetUserByLoginOrEmail(c *models.ReqContext) response.Response { func GetUserByLoginOrEmail(c *models.ReqContext) response.Response {
query := models.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")} query := models.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")}
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil { if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, models.ErrUserNotFound.Error(), nil) return response.Error(404, models.ErrUserNotFound.Error(), nil)
} }
@ -110,7 +110,7 @@ func UpdateUserActiveOrg(c *models.ReqContext) response.Response {
cmd := models.SetUsingOrgCommand{UserId: userID, OrgId: orgID} cmd := models.SetUsingOrgCommand{UserId: userID, OrgId: orgID}
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to change active organization", err) return response.Error(500, "Failed to change active organization", err)
} }
@ -125,7 +125,7 @@ func handleUpdateUser(ctx context.Context, cmd models.UpdateUserCommand) respons
} }
} }
if err := bus.DispatchCtx(ctx, &cmd); err != nil { if err := bus.Dispatch(ctx, &cmd); err != nil {
return response.Error(500, "Failed to update user", err) return response.Error(500, "Failed to update user", err)
} }
@ -150,7 +150,7 @@ func GetUserTeams(c *models.ReqContext) response.Response {
func getUserTeamList(ctx context.Context, orgID int64, userID int64) response.Response { func getUserTeamList(ctx context.Context, orgID int64, userID int64) response.Response {
query := models.GetTeamsByUserQuery{OrgId: orgID, UserId: userID} query := models.GetTeamsByUserQuery{OrgId: orgID, UserId: userID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return response.Error(500, "Failed to get user teams", err) return response.Error(500, "Failed to get user teams", err)
} }
@ -168,7 +168,7 @@ func GetUserOrgList(c *models.ReqContext) response.Response {
func getUserOrgList(ctx context.Context, userID int64) response.Response { func getUserOrgList(ctx context.Context, userID int64) response.Response {
query := models.GetUserOrgListQuery{UserId: userID} query := models.GetUserOrgListQuery{UserId: userID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return response.Error(500, "Failed to get user organizations", err) return response.Error(500, "Failed to get user organizations", err)
} }
@ -178,7 +178,7 @@ func getUserOrgList(ctx context.Context, userID int64) response.Response {
func validateUsingOrg(ctx context.Context, userID int64, orgID int64) bool { func validateUsingOrg(ctx context.Context, userID int64, orgID int64) bool {
query := models.GetUserOrgListQuery{UserId: userID} query := models.GetUserOrgListQuery{UserId: userID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return false return false
} }
@ -203,7 +203,7 @@ func UserSetUsingOrg(c *models.ReqContext) response.Response {
cmd := models.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgID} cmd := models.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgID}
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to change active organization", err) return response.Error(500, "Failed to change active organization", err)
} }
@ -220,7 +220,7 @@ func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *models.ReqContext) {
cmd := models.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgID} cmd := models.SetUsingOrgCommand{UserId: c.UserId, OrgId: orgID}
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
hs.NotFoundHandler(c) hs.NotFoundHandler(c)
} }
@ -238,7 +238,7 @@ func ChangeUserPassword(c *models.ReqContext) response.Response {
userQuery := models.GetUserByIdQuery{Id: c.UserId} userQuery := models.GetUserByIdQuery{Id: c.UserId}
if err := bus.DispatchCtx(c.Req.Context(), &userQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &userQuery); err != nil {
return response.Error(500, "Could not read user from database", err) return response.Error(500, "Could not read user from database", err)
} }
@ -261,7 +261,7 @@ func ChangeUserPassword(c *models.ReqContext) response.Response {
return response.Error(500, "Failed to encode password", err) return response.Error(500, "Failed to encode password", err)
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to change user password", err) return response.Error(500, "Failed to change user password", err)
} }
@ -284,7 +284,7 @@ func SetHelpFlag(c *models.ReqContext) response.Response {
HelpFlags1: *bitmask, HelpFlags1: *bitmask,
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to update help flag", err) return response.Error(500, "Failed to update help flag", err)
} }
@ -297,7 +297,7 @@ func ClearHelpFlags(c *models.ReqContext) response.Response {
HelpFlags1: models.HelpFlags1(0), HelpFlags1: models.HelpFlags1(0),
} }
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
return response.Error(500, "Failed to update help flag", err) return response.Error(500, "Failed to update help flag", err)
} }

View File

@ -32,7 +32,7 @@ func (hs *HTTPServer) RevokeUserAuthToken(c *models.ReqContext) response.Respons
func (hs *HTTPServer) logoutUserFromAllDevicesInternal(ctx context.Context, userID int64) response.Response { func (hs *HTTPServer) logoutUserFromAllDevicesInternal(ctx context.Context, userID int64) response.Response {
userQuery := models.GetUserByIdQuery{Id: userID} userQuery := models.GetUserByIdQuery{Id: userID}
if err := bus.DispatchCtx(ctx, &userQuery); err != nil { if err := bus.Dispatch(ctx, &userQuery); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, "User not found", err) return response.Error(404, "User not found", err)
} }
@ -52,7 +52,7 @@ func (hs *HTTPServer) logoutUserFromAllDevicesInternal(ctx context.Context, user
func (hs *HTTPServer) getUserAuthTokensInternal(c *models.ReqContext, userID int64) response.Response { func (hs *HTTPServer) getUserAuthTokensInternal(c *models.ReqContext, userID int64) response.Response {
userQuery := models.GetUserByIdQuery{Id: userID} userQuery := models.GetUserByIdQuery{Id: userID}
if err := bus.DispatchCtx(c.Req.Context(), &userQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &userQuery); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, "User not found", err) return response.Error(404, "User not found", err)
} }
@ -119,7 +119,7 @@ func (hs *HTTPServer) getUserAuthTokensInternal(c *models.ReqContext, userID int
func (hs *HTTPServer) revokeUserAuthTokenInternal(c *models.ReqContext, userID int64, cmd models.RevokeAuthTokenCmd) response.Response { func (hs *HTTPServer) revokeUserAuthTokenInternal(c *models.ReqContext, userID int64, cmd models.RevokeAuthTokenCmd) response.Response {
userQuery := models.GetUserByIdQuery{Id: userID} userQuery := models.GetUserByIdQuery{Id: userID}
if err := bus.DispatchCtx(c.Req.Context(), &userQuery); err != nil { if err := bus.Dispatch(c.Req.Context(), &userQuery); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
return response.Error(404, "User not found", err) return response.Error(404, "User not found", err)
} }

View File

@ -27,7 +27,7 @@ type TransactionManager interface {
// Bus type defines the bus interface structure // Bus type defines the bus interface structure
type Bus interface { type Bus interface {
DispatchCtx(ctx context.Context, msg Msg) error Dispatch(ctx context.Context, msg Msg) error
PublishCtx(ctx context.Context, msg Msg) error PublishCtx(ctx context.Context, msg Msg) error
@ -92,7 +92,7 @@ func (b *InProcBus) SetTransactionManager(tm TransactionManager) {
} }
// DispatchCtx function dispatch a message to the bus context. // DispatchCtx function dispatch a message to the bus context.
func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error { func (b *InProcBus) Dispatch(ctx context.Context, msg Msg) error {
var msgName = reflect.TypeOf(msg).Elem().Name() var msgName = reflect.TypeOf(msg).Elem().Name()
span, ctx := opentracing.StartSpanFromContext(ctx, "bus - "+msgName) span, ctx := opentracing.StartSpanFromContext(ctx, "bus - "+msgName)
@ -205,8 +205,8 @@ func AddEventListenerCtx(handler HandlerFunc) {
globalBus.AddEventListenerCtx(handler) globalBus.AddEventListenerCtx(handler)
} }
func DispatchCtx(ctx context.Context, msg Msg) error { func Dispatch(ctx context.Context, msg Msg) error {
return globalBus.DispatchCtx(ctx, msg) return globalBus.Dispatch(ctx, msg)
} }
func PublishCtx(ctx context.Context, msg Msg) error { func PublishCtx(ctx context.Context, msg Msg) error {

View File

@ -23,7 +23,7 @@ func TestDispatch(t *testing.T) {
return nil return nil
}) })
err := bus.DispatchCtx(context.Background(), &testQuery{}) err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err) require.NoError(t, err)
require.True(t, invoked, "expected handler to be called") require.True(t, invoked, "expected handler to be called")
@ -32,7 +32,7 @@ func TestDispatch(t *testing.T) {
func TestDispatch_NoRegisteredHandler(t *testing.T) { func TestDispatch_NoRegisteredHandler(t *testing.T) {
bus := New() bus := New()
err := bus.DispatchCtx(context.Background(), &testQuery{}) err := bus.Dispatch(context.Background(), &testQuery{})
require.Equal(t, err, ErrHandlerNotFound, require.Equal(t, err, ErrHandlerNotFound,
"expected bus to return HandlerNotFound since no handler is registered") "expected bus to return HandlerNotFound since no handler is registered")
} }
@ -47,7 +47,7 @@ func TestDispatch_ContextHandler(t *testing.T) {
return nil return nil
}) })
err := bus.DispatchCtx(context.Background(), &testQuery{}) err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err) require.NoError(t, err)
require.True(t, invoked, "expected handler to be called") require.True(t, invoked, "expected handler to be called")
@ -63,7 +63,7 @@ func TestDispatchCtx(t *testing.T) {
return nil return nil
}) })
err := bus.DispatchCtx(context.Background(), &testQuery{}) err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err) require.NoError(t, err)
require.True(t, invoked, "expected handler to be called") require.True(t, invoked, "expected handler to be called")
@ -79,7 +79,7 @@ func TestDispatchCtx_NoContextHandler(t *testing.T) {
return nil return nil
}) })
err := bus.DispatchCtx(context.Background(), &testQuery{}) err := bus.Dispatch(context.Background(), &testQuery{})
require.NoError(t, err) require.NoError(t, err)
require.True(t, invoked, "expected handler to be called") require.True(t, invoked, "expected handler to be called")
@ -88,7 +88,7 @@ func TestDispatchCtx_NoContextHandler(t *testing.T) {
func TestDispatchCtx_NoRegisteredHandler(t *testing.T) { func TestDispatchCtx_NoRegisteredHandler(t *testing.T) {
bus := New() bus := New()
err := bus.DispatchCtx(context.Background(), &testQuery{}) err := bus.Dispatch(context.Background(), &testQuery{})
require.Equal(t, err, ErrHandlerNotFound, require.Equal(t, err, ErrHandlerNotFound,
"expected bus to return HandlerNotFound since no handler is registered") "expected bus to return HandlerNotFound since no handler is registered")
} }
@ -105,7 +105,7 @@ func TestQuery(t *testing.T) {
q := &testQuery{} q := &testQuery{}
err := bus.DispatchCtx(context.Background(), q) err := bus.Dispatch(context.Background(), q)
require.NoError(t, err, "unable to dispatch query") require.NoError(t, err, "unable to dispatch query")
require.Equal(t, want, q.Resp) require.Equal(t, want, q.Resp)
@ -118,7 +118,7 @@ func TestQuery_HandlerReturnsError(t *testing.T) {
return errors.New("handler error") return errors.New("handler error")
}) })
err := bus.DispatchCtx(context.Background(), &testQuery{}) err := bus.Dispatch(context.Background(), &testQuery{})
require.Error(t, err, "expected error but got none") require.Error(t, err, "expected error but got none")
} }

View File

@ -43,7 +43,7 @@ func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SQLStore) erro
userQuery := models.GetUserByIdQuery{Id: AdminUserId} userQuery := models.GetUserByIdQuery{Id: AdminUserId}
if err := bus.DispatchCtx(context.Background(), &userQuery); err != nil { if err := bus.Dispatch(context.Background(), &userQuery); err != nil {
return fmt.Errorf("could not read user from database. Error: %v", err) return fmt.Errorf("could not read user from database. Error: %v", err)
} }
@ -57,7 +57,7 @@ func resetPasswordCommand(c utils.CommandLine, sqlStore *sqlstore.SQLStore) erro
NewPassword: passwordHashed, NewPassword: passwordHashed,
} }
if err := bus.DispatchCtx(context.Background(), &cmd); err != nil { if err := bus.Dispatch(context.Background(), &cmd); err != nil {
return errutil.Wrapf(err, "failed to update user password") return errutil.Wrapf(err, "failed to update user password")
} }

View File

@ -65,7 +65,7 @@ func CalculateDiff(ctx context.Context, options *Options) (*Result, error) {
OrgId: options.OrgId, OrgId: options.OrgId,
} }
if err := bus.DispatchCtx(ctx, &baseVersionQuery); err != nil { if err := bus.Dispatch(ctx, &baseVersionQuery); err != nil {
return nil, err return nil, err
} }
@ -75,7 +75,7 @@ func CalculateDiff(ctx context.Context, options *Options) (*Result, error) {
OrgId: options.OrgId, OrgId: options.OrgId,
} }
if err := bus.DispatchCtx(ctx, &newVersionQuery); err != nil { if err := bus.Dispatch(ctx, &newVersionQuery); err != nil {
return nil, err return nil, err
} }

View File

@ -39,7 +39,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
} }
statsQuery := models.GetSystemStatsQuery{} statsQuery := models.GetSystemStatsQuery{}
if err := uss.Bus.DispatchCtx(ctx, &statsQuery); err != nil { if err := uss.Bus.Dispatch(ctx, &statsQuery); err != nil {
uss.log.Error("Failed to get system stats", "error", err) uss.log.Error("Failed to get system stats", "error", err)
return report, err return report, err
} }
@ -113,7 +113,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
metrics["stats.avg_auth_token_per_user.count"] = avgAuthTokensPerUser metrics["stats.avg_auth_token_per_user.count"] = avgAuthTokensPerUser
dsStats := models.GetDataSourceStatsQuery{} dsStats := models.GetDataSourceStatsQuery{}
if err := uss.Bus.DispatchCtx(ctx, &dsStats); err != nil { if err := uss.Bus.Dispatch(ctx, &dsStats); err != nil {
uss.log.Error("Failed to get datasource stats", "error", err) uss.log.Error("Failed to get datasource stats", "error", err)
return report, err return report, err
} }
@ -132,7 +132,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
metrics["stats.ds.other.count"] = dsOtherCount metrics["stats.ds.other.count"] = dsOtherCount
esDataSourcesQuery := models.GetDataSourcesByTypeQuery{Type: models.DS_ES} esDataSourcesQuery := models.GetDataSourcesByTypeQuery{Type: models.DS_ES}
if err := uss.Bus.DispatchCtx(ctx, &esDataSourcesQuery); err != nil { if err := uss.Bus.Dispatch(ctx, &esDataSourcesQuery); err != nil {
uss.log.Error("Failed to get elasticsearch json data", "error", err) uss.log.Error("Failed to get elasticsearch json data", "error", err)
return report, err return report, err
} }
@ -155,7 +155,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
// fetch datasource access stats // fetch datasource access stats
dsAccessStats := models.GetDataSourceAccessStatsQuery{} dsAccessStats := models.GetDataSourceAccessStatsQuery{}
if err := uss.Bus.DispatchCtx(ctx, &dsAccessStats); err != nil { if err := uss.Bus.Dispatch(ctx, &dsAccessStats); err != nil {
uss.log.Error("Failed to get datasource access stats", "error", err) uss.log.Error("Failed to get datasource access stats", "error", err)
return report, err return report, err
} }
@ -185,7 +185,7 @@ func (uss *UsageStats) GetUsageReport(ctx context.Context) (usagestats.Report, e
// get stats about alert notifier usage // get stats about alert notifier usage
anStats := models.GetAlertNotifierUsageStatsQuery{} anStats := models.GetAlertNotifierUsageStatsQuery{}
if err := uss.Bus.DispatchCtx(ctx, &anStats); err != nil { if err := uss.Bus.Dispatch(ctx, &anStats); err != nil {
uss.log.Error("Failed to get alert notification stats", "error", err) uss.log.Error("Failed to get alert notification stats", "error", err)
return report, err return report, err
} }
@ -296,7 +296,7 @@ func (uss *UsageStats) updateTotalStats(ctx context.Context) {
} }
statsQuery := models.GetSystemStatsQuery{} statsQuery := models.GetSystemStatsQuery{}
if err := uss.Bus.DispatchCtx(ctx, &statsQuery); err != nil { if err := uss.Bus.Dispatch(ctx, &statsQuery); err != nil {
uss.log.Error("Failed to get system stats", "error", err) uss.log.Error("Failed to get system stats", "error", err)
return return
} }
@ -320,7 +320,7 @@ func (uss *UsageStats) updateTotalStats(ctx context.Context) {
metrics.StatsTotalLibraryVariables.Set(float64(statsQuery.Result.LibraryVariables)) metrics.StatsTotalLibraryVariables.Set(float64(statsQuery.Result.LibraryVariables))
dsStats := models.GetDataSourceStatsQuery{} dsStats := models.GetDataSourceStatsQuery{}
if err := uss.Bus.DispatchCtx(ctx, &dsStats); err != nil { if err := uss.Bus.Dispatch(ctx, &dsStats); err != nil {
uss.log.Error("Failed to get datasource stats", "error", err) uss.log.Error("Failed to get datasource stats", "error", err)
return return
} }

View File

@ -23,7 +23,7 @@ var validateLoginAttempts = func(ctx context.Context, query *models.LoginUserQue
Since: time.Now().Add(-loginAttemptsWindow), Since: time.Now().Add(-loginAttemptsWindow),
} }
if err := bus.DispatchCtx(ctx, &loginAttemptCountQuery); err != nil { if err := bus.Dispatch(ctx, &loginAttemptCountQuery); err != nil {
return err return err
} }
@ -44,5 +44,5 @@ var saveInvalidLoginAttempt = func(ctx context.Context, query *models.LoginUserQ
IpAddress: query.IpAddress, IpAddress: query.IpAddress,
} }
return bus.DispatchCtx(ctx, &loginAttemptCommand) return bus.Dispatch(ctx, &loginAttemptCommand)
} }

View File

@ -24,7 +24,7 @@ var validatePassword = func(providedPassword string, userPassword string, userSa
var loginUsingGrafanaDB = func(ctx context.Context, query *models.LoginUserQuery) error { var loginUsingGrafanaDB = func(ctx context.Context, query *models.LoginUserQuery) error {
userQuery := models.GetUserByLoginQuery{LoginOrEmail: query.Username} userQuery := models.GetUserByLoginQuery{LoginOrEmail: query.Username}
if err := bus.DispatchCtx(ctx, &userQuery); err != nil { if err := bus.Dispatch(ctx, &userQuery); err != nil {
return err return err
} }

View File

@ -58,7 +58,7 @@ var loginUsingLDAP = func(ctx context.Context, query *models.LoginUserQuery) (bo
ExternalUser: externalUser, ExternalUser: externalUser,
SignupAllowed: setting.LDAPAllowSignup, SignupAllowed: setting.LDAPAllowSignup,
} }
err = bus.DispatchCtx(ctx, upsert) err = bus.Dispatch(ctx, upsert)
if err != nil { if err != nil {
return true, err return true, err
} }
@ -74,7 +74,7 @@ func DisableExternalUser(ctx context.Context, username string) error {
LoginOrEmail: username, LoginOrEmail: username,
} }
if err := bus.DispatchCtx(ctx, userQuery); err != nil { if err := bus.Dispatch(ctx, userQuery); err != nil {
return err return err
} }
@ -92,7 +92,7 @@ func DisableExternalUser(ctx context.Context, username string) error {
IsDisabled: true, IsDisabled: true,
} }
if err := bus.DispatchCtx(ctx, disableUserCmd); err != nil { if err := bus.Dispatch(ctx, disableUserCmd); err != nil {
ldapLogger.Debug( ldapLogger.Debug(
"Error disabling external user", "Error disabling external user",
"user", "user",

View File

@ -34,7 +34,7 @@ func OrgRedirect(cfg *setting.Cfg) web.Handler {
} }
cmd := models.SetUsingOrgCommand{UserId: ctx.UserId, OrgId: orgId} cmd := models.SetUsingOrgCommand{UserId: ctx.UserId, OrgId: orgId}
if err := bus.DispatchCtx(ctx.Req.Context(), &cmd); err != nil { if err := bus.Dispatch(ctx.Req.Context(), &cmd); err != nil {
if ctx.IsApiRequest() { if ctx.IsApiRequest() {
ctx.JsonApiErr(404, "Not found", nil) ctx.JsonApiErr(404, "Not found", nil)
} else { } else {

View File

@ -22,7 +22,7 @@ func (m *PluginManager) GetPluginDashboards(ctx context.Context, orgID int64, pl
// load current dashboards // load current dashboards
query := models.GetDashboardsByPluginIdQuery{OrgId: orgID, PluginId: pluginID} query := models.GetDashboardsByPluginIdQuery{OrgId: orgID, PluginId: pluginID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return nil, err return nil, err
} }

View File

@ -114,7 +114,7 @@ func (p *Provider) getCachedPluginSettings(ctx context.Context, pluginID string,
} }
query := models.GetPluginSettingByIdQuery{PluginId: pluginID, OrgId: user.OrgId} query := models.GetPluginSettingByIdQuery{PluginId: pluginID, OrgId: user.OrgId}
if err := p.Bus.DispatchCtx(ctx, &query); err != nil { if err := p.Bus.Dispatch(ctx, &query); err != nil {
return nil, err return nil, err
} }

View File

@ -72,7 +72,7 @@ func (s *Service) syncPluginDashboards(ctx context.Context, plugin plugins.Plugi
s.logger.Info("Deleting plugin dashboard", "pluginId", plugin.ID, "dashboard", dash.Slug) s.logger.Info("Deleting plugin dashboard", "pluginId", plugin.ID, "dashboard", dash.Slug)
deleteCmd := models.DeleteDashboardCommand{OrgId: orgID, Id: dash.DashboardId} deleteCmd := models.DeleteDashboardCommand{OrgId: orgID, Id: dash.DashboardId}
if err := bus.DispatchCtx(ctx, &deleteCmd); err != nil { if err := bus.Dispatch(ctx, &deleteCmd); err != nil {
s.logger.Error("Failed to auto update app dashboard", "pluginId", plugin.ID, "error", err) s.logger.Error("Failed to auto update app dashboard", "pluginId", plugin.ID, "error", err)
return return
} }
@ -91,7 +91,7 @@ func (s *Service) syncPluginDashboards(ctx context.Context, plugin plugins.Plugi
// update version in plugin_setting table to mark that we have processed the update // update version in plugin_setting table to mark that we have processed the update
query := models.GetPluginSettingByIdQuery{PluginId: plugin.ID, OrgId: orgID} query := models.GetPluginSettingByIdQuery{PluginId: plugin.ID, OrgId: orgID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
s.logger.Error("Failed to read plugin setting by ID", "error", err) s.logger.Error("Failed to read plugin setting by ID", "error", err)
return return
} }
@ -103,7 +103,7 @@ func (s *Service) syncPluginDashboards(ctx context.Context, plugin plugins.Plugi
PluginVersion: plugin.Info.Version, PluginVersion: plugin.Info.Version,
} }
if err := bus.DispatchCtx(ctx, &cmd); err != nil { if err := bus.Dispatch(ctx, &cmd); err != nil {
s.logger.Error("Failed to update plugin setting version", "error", err) s.logger.Error("Failed to update plugin setting version", "error", err)
} }
} }
@ -120,14 +120,14 @@ func (s *Service) handlePluginStateChanged(ctx context.Context, event *models.Pl
s.syncPluginDashboards(ctx, p, event.OrgId) s.syncPluginDashboards(ctx, p, event.OrgId)
} else { } else {
query := models.GetDashboardsByPluginIdQuery{PluginId: event.PluginId, OrgId: event.OrgId} query := models.GetDashboardsByPluginIdQuery{PluginId: event.PluginId, OrgId: event.OrgId}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return err return err
} }
for _, dash := range query.Result { for _, dash := range query.Result {
s.logger.Info("Deleting plugin dashboard", "pluginId", event.PluginId, "dashboard", dash.Slug) s.logger.Info("Deleting plugin dashboard", "pluginId", event.PluginId, "dashboard", dash.Slug)
deleteCmd := models.DeleteDashboardCommand{OrgId: dash.OrgId, Id: dash.Id} deleteCmd := models.DeleteDashboardCommand{OrgId: dash.OrgId, Id: dash.Id}
if err := bus.DispatchCtx(ctx, &deleteCmd); err != nil { if err := bus.Dispatch(ctx, &deleteCmd); err != nil {
return err return err
} }
} }

View File

@ -28,7 +28,7 @@ type UsageStatsQuerier interface {
// configured in Grafana. // configured in Grafana.
func (e *AlertEngine) QueryUsageStats(ctx context.Context) (*UsageStats, error) { func (e *AlertEngine) QueryUsageStats(ctx context.Context) (*UsageStats, error) {
cmd := &models.GetAllAlertsQuery{} cmd := &models.GetAllAlertsQuery{}
err := e.Bus.DispatchCtx(ctx, cmd) err := e.Bus.Dispatch(ctx, cmd)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -63,7 +63,7 @@ func (e *AlertEngine) mapRulesToUsageStats(ctx context.Context, rules []*models.
result := map[string]int{} result := map[string]int{}
for k, v := range typeCount { for k, v := range typeCount {
query := &models.GetDataSourceQuery{Id: k} query := &models.GetDataSourceQuery{Id: k}
err := e.Bus.DispatchCtx(ctx, query) err := e.Bus.Dispatch(ctx, query)
if err != nil { if err != nil {
return map[string]int{}, nil return map[string]int{}, nil
} }

View File

@ -140,7 +140,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange l
OrgId: context.Rule.OrgID, OrgId: context.Rule.OrgID,
} }
if err := bus.DispatchCtx(context.Ctx, getDsInfo); err != nil { if err := bus.Dispatch(context.Ctx, getDsInfo); err != nil {
return nil, fmt.Errorf("could not find datasource: %w", err) return nil, fmt.Errorf("could not find datasource: %w", err)
} }

View File

@ -108,7 +108,7 @@ func (c *EvalContext) GetDashboardUID() (*models.DashboardRef, error) {
} }
uidQuery := &models.GetDashboardRefByIdQuery{Id: c.Rule.DashboardID} uidQuery := &models.GetDashboardRefByIdQuery{Id: c.Rule.DashboardID}
if err := bus.DispatchCtx(c.Ctx, uidQuery); err != nil { if err := bus.Dispatch(c.Ctx, uidQuery); err != nil {
return nil, err return nil, err
} }

View File

@ -48,14 +48,14 @@ func (e *DashAlertExtractor) lookupQueryDataSource(ctx context.Context, panel *s
if dsName == "" && dsUid == "" { if dsName == "" && dsUid == "" {
query := &models.GetDefaultDataSourceQuery{OrgId: e.OrgID} query := &models.GetDefaultDataSourceQuery{OrgId: e.OrgID}
if err := bus.DispatchCtx(ctx, query); err != nil { if err := bus.Dispatch(ctx, query); err != nil {
return nil, err return nil, err
} }
return query.Result, nil return query.Result, nil
} }
query := &models.GetDataSourceQuery{Name: dsName, Uid: dsUid, OrgId: e.OrgID} query := &models.GetDataSourceQuery{Name: dsName, Uid: dsUid, OrgId: e.OrgID}
if err := bus.DispatchCtx(ctx, query); err != nil { if err := bus.Dispatch(ctx, query); err != nil {
return nil, err return nil, err
} }
@ -208,7 +208,7 @@ func (e *DashAlertExtractor) getAlertFromPanels(ctx context.Context, jsonWithPan
Datasources: []*models.DataSource{datasource}, Datasources: []*models.DataSource{datasource},
} }
if err := bus.DispatchCtx(ctx, &dsFilterQuery); err != nil { if err := bus.Dispatch(ctx, &dsFilterQuery); err != nil {
if !errors.Is(err, bus.ErrHandlerNotFound) { if !errors.Is(err, bus.ErrHandlerNotFound) {
return nil, err return nil, err
} }

View File

@ -152,7 +152,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
Version: notifierState.state.Version, Version: notifierState.state.Version,
} }
return bus.DispatchCtx(evalContext.Ctx, cmd) return bus.Dispatch(evalContext.Ctx, cmd)
} }
func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error { func (n *notificationService) sendNotification(evalContext *EvalContext, notifierState *notifierState) error {
@ -163,7 +163,7 @@ func (n *notificationService) sendNotification(evalContext *EvalContext, notifie
AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges, AlertRuleStateUpdatedVersion: evalContext.Rule.StateChanges,
} }
err := bus.DispatchCtx(evalContext.Ctx, setPendingCmd) err := bus.Dispatch(evalContext.Ctx, setPendingCmd)
if err != nil { if err != nil {
if errors.Is(err, models.ErrAlertNotificationStateVersionConflict) { if errors.Is(err, models.ErrAlertNotificationStateVersionConflict) {
return nil return nil
@ -247,7 +247,7 @@ func (n *notificationService) renderAndUploadImage(evalCtx *EvalContext, timeout
func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) { func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids []string, evalContext *EvalContext) (notifierStateSlice, error) {
query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids} query := &models.GetAlertNotificationsWithUidToSendQuery{OrgId: orgID, Uids: notificationUids}
if err := bus.DispatchCtx(evalContext.Ctx, query); err != nil { if err := bus.Dispatch(evalContext.Ctx, query); err != nil {
return nil, err return nil, err
} }
@ -265,7 +265,7 @@ func (n *notificationService) getNeededNotifiers(orgID int64, notificationUids [
OrgId: evalContext.Rule.OrgID, OrgId: evalContext.Rule.OrgID,
} }
err = bus.DispatchCtx(evalContext.Ctx, query) err = bus.Dispatch(evalContext.Ctx, query)
if err != nil { if err != nil {
n.log.Error("Could not get notification state.", "notifier", notification.Id, "error", err) n.log.Error("Could not get notification state.", "notifier", notification.Id, "error", err)
continue continue

View File

@ -183,7 +183,7 @@ func (am *AlertmanagerNotifier) Notify(evalContext *alerting.EvalContext) error
Body: string(body), Body: string(body),
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
am.log.Error("Failed to send alertmanager", "error", err, "alertmanager", am.Name, "url", url) am.log.Error("Failed to send alertmanager", "error", err, "alertmanager", am.Name, "url", url)
errCnt++ errCnt++
} }

View File

@ -91,7 +91,7 @@ func (dd *DingDingNotifier) Notify(evalContext *alerting.EvalContext) error {
Body: string(body), Body: string(body),
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
dd.log.Error("Failed to send DingDing", "error", err, "dingding", dd.Name) dd.log.Error("Failed to send DingDing", "error", err, "dingding", dd.Name)
return err return err
} }

View File

@ -177,7 +177,7 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
} }
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
dn.log.Error("Failed to send notification to Discord", "error", err) dn.log.Error("Failed to send notification to Discord", "error", err)
return err return err
} }

View File

@ -117,7 +117,7 @@ func (en *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
} }
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
en.log.Error("Failed to send alert notification email", "error", err) en.log.Error("Failed to send alert notification email", "error", err)
return err return err
} }

View File

@ -220,7 +220,7 @@ func (gcn *GoogleChatNotifier) Notify(evalContext *alerting.EvalContext) error {
Body: string(body), Body: string(body),
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
gcn.log.Error("Failed to send Google Hangouts Chat alert", "error", err, "webhook", gcn.Name) gcn.log.Error("Failed to send Google Hangouts Chat alert", "error", err, "webhook", gcn.Name)
return err return err
} }

View File

@ -177,7 +177,7 @@ func (hc *HipChatNotifier) Notify(evalContext *alerting.EvalContext) error {
hc.log.Info("Request payload", "json", string(data)) hc.log.Info("Request payload", "json", string(data))
cmd := &models.SendWebhookSync{Url: hipURL, Body: string(data)} cmd := &models.SendWebhookSync{Url: hipURL, Body: string(data)}
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
hc.log.Error("Failed to send hipchat notification", "error", err, "webhook", hc.Name) hc.log.Error("Failed to send hipchat notification", "error", err, "webhook", hc.Name)
return err return err
} }

View File

@ -124,7 +124,7 @@ func (kn *KafkaNotifier) Notify(evalContext *alerting.EvalContext) error {
}, },
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
kn.log.Error("Failed to send notification to Kafka", "error", err, "body", string(body)) kn.log.Error("Failed to send notification to Kafka", "error", err, "body", string(body))
return err return err
} }

View File

@ -92,7 +92,7 @@ func (ln *LineNotifier) createAlert(evalContext *alerting.EvalContext) error {
Body: form.Encode(), Body: form.Encode(),
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
ln.log.Error("Failed to send notification to LINE", "error", err, "body", body) ln.log.Error("Failed to send notification to LINE", "error", err, "body", body)
return err return err
} }

View File

@ -205,7 +205,7 @@ func (on *OpsGenieNotifier) createAlert(evalContext *alerting.EvalContext) error
}, },
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
on.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body)) on.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body))
} }
@ -229,7 +229,7 @@ func (on *OpsGenieNotifier) closeAlert(evalContext *alerting.EvalContext) error
}, },
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
on.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body)) on.log.Error("Failed to send notification to OpsGenie", "error", err, "body", string(body))
return err return err
} }

View File

@ -240,7 +240,7 @@ func (pn *PagerdutyNotifier) Notify(evalContext *alerting.EvalContext) error {
}, },
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
pn.log.Error("Failed to send notification to Pagerduty", "error", err, "body", string(body)) pn.log.Error("Failed to send notification to Pagerduty", "error", err, "body", string(body))
return err return err
} }

View File

@ -287,7 +287,7 @@ func (pn *PushoverNotifier) Notify(evalContext *alerting.EvalContext) error {
Body: uploadBody.String(), Body: uploadBody.String(),
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
pn.log.Error("Failed to send pushover notification", "error", err, "webhook", pn.Name) pn.log.Error("Failed to send pushover notification", "error", err, "webhook", pn.Name)
return err return err
} }

View File

@ -146,7 +146,7 @@ func (sn *SensuNotifier) Notify(evalContext *alerting.EvalContext) error {
HttpMethod: "POST", HttpMethod: "POST",
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
sn.log.Error("Failed to send sensu event", "error", err, "sensu", sn.Name) sn.log.Error("Failed to send sensu event", "error", err, "sensu", sn.Name)
return err return err
} }

View File

@ -197,7 +197,7 @@ func (sn *SensuGoNotifier) Notify(evalContext *alerting.EvalContext) error {
"Authorization": fmt.Sprintf("Key %s", sn.APIKey), "Authorization": fmt.Sprintf("Key %s", sn.APIKey),
}, },
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
sn.log.Error("Failed to send Sensu Go event", "error", err, "sensugo", sn.Name) sn.log.Error("Failed to send Sensu Go event", "error", err, "sensugo", sn.Name)
return err return err
} }

View File

@ -418,7 +418,7 @@ func (sn *SlackNotifier) slackFileUpload(evalContext *alerting.EvalContext, log
cmd := &models.SendWebhookSync{ cmd := &models.SendWebhookSync{
Url: "https://slack.com/api/files.upload", Body: uploadBody.String(), HttpHeader: headers, HttpMethod: "POST", Url: "https://slack.com/api/files.upload", Body: uploadBody.String(), HttpHeader: headers, HttpMethod: "POST",
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
log.Error("Failed to upload slack image", "error", err, "webhook", "file.upload") log.Error("Failed to upload slack image", "error", err, "webhook", "file.upload")
return err return err
} }

View File

@ -135,7 +135,7 @@ func (tn *TeamsNotifier) Notify(evalContext *alerting.EvalContext) error {
data, _ := json.Marshal(&body) data, _ := json.Marshal(&body)
cmd := &models.SendWebhookSync{Url: tn.URL, Body: string(data)} cmd := &models.SendWebhookSync{Url: tn.URL, Body: string(data)}
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
tn.log.Error("Failed to send teams notification", "error", err, "webhook", tn.Name) tn.log.Error("Failed to send teams notification", "error", err, "webhook", tn.Name)
return err return err
} }

View File

@ -271,7 +271,7 @@ func (tn *TelegramNotifier) Notify(evalContext *alerting.EvalContext) error {
return err return err
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
tn.log.Error("Failed to send webhook", "error", err, "webhook", tn.Name) tn.log.Error("Failed to send webhook", "error", err, "webhook", tn.Name)
return err return err
} }

View File

@ -158,7 +158,7 @@ func (notifier *ThreemaNotifier) Notify(evalContext *alerting.EvalContext) error
HttpMethod: "POST", HttpMethod: "POST",
HttpHeader: headers, HttpHeader: headers,
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
notifier.log.Error("Failed to send webhook", "error", err, "webhook", notifier.Name) notifier.log.Error("Failed to send webhook", "error", err, "webhook", notifier.Name)
return err return err
} }

View File

@ -156,7 +156,7 @@ func (vn *VictoropsNotifier) Notify(evalContext *alerting.EvalContext) error {
data, _ := bodyJSON.MarshalJSON() data, _ := bodyJSON.MarshalJSON()
cmd := &models.SendWebhookSync{Url: vn.URL, Body: string(data)} cmd := &models.SendWebhookSync{Url: vn.URL, Body: string(data)}
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
vn.log.Error("Failed to send Victorops notification", "error", err, "webhook", vn.Name) vn.log.Error("Failed to send Victorops notification", "error", err, "webhook", vn.Name)
return err return err
} }

View File

@ -153,7 +153,7 @@ func (wn *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
HttpMethod: wn.HTTPMethod, HttpMethod: wn.HTTPMethod,
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
wn.log.Error("Failed to send webhook", "error", err, "webhook", wn.Name) wn.log.Error("Failed to send webhook", "error", err, "webhook", wn.Name)
return err return err
} }

View File

@ -30,7 +30,7 @@ func newRuleReader() *defaultRuleReader {
func (arr *defaultRuleReader) fetch(ctx context.Context) []*Rule { func (arr *defaultRuleReader) fetch(ctx context.Context) []*Rule {
cmd := &models.GetAllAlertsQuery{} cmd := &models.GetAllAlertsQuery{}
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
arr.log.Error("Could not load alerts", "error", err) arr.log.Error("Could not load alerts", "error", err)
return []*Rule{} return []*Rule{}
} }

View File

@ -58,7 +58,7 @@ func (handler *defaultResultHandler) handle(evalContext *EvalContext) error {
EvalData: annotationData, EvalData: annotationData,
} }
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
if errors.Is(err, models.ErrCannotChangeStateOnPausedAlert) { if errors.Is(err, models.ErrCannotChangeStateOnPausedAlert) {
handler.log.Error("Cannot change state on alert that's paused", "error", err) handler.log.Error("Cannot change state on alert that's paused", "error", err)
return err return err

View File

@ -226,7 +226,7 @@ func getAlertNotificationUIDByIDAndOrgID(ctx context.Context, notificationID int
Id: notificationID, Id: notificationID,
} }
if err := bus.DispatchCtx(ctx, query); err != nil { if err := bus.Dispatch(ctx, query); err != nil {
return "", err return "", err
} }

View File

@ -127,7 +127,7 @@ func (srv *CleanUpService) shouldCleanupTempFile(filemtime time.Time, now time.T
func (srv *CleanUpService) deleteExpiredSnapshots(ctx context.Context) { func (srv *CleanUpService) deleteExpiredSnapshots(ctx context.Context) {
cmd := models.DeleteExpiredSnapshotsCommand{} cmd := models.DeleteExpiredSnapshotsCommand{}
if err := bus.DispatchCtx(ctx, &cmd); err != nil { if err := bus.Dispatch(ctx, &cmd); err != nil {
srv.log.Error("Failed to delete expired snapshots", "error", err.Error()) srv.log.Error("Failed to delete expired snapshots", "error", err.Error())
} else { } else {
srv.log.Debug("Deleted expired snapshots", "rows affected", cmd.DeletedRows) srv.log.Debug("Deleted expired snapshots", "rows affected", cmd.DeletedRows)
@ -136,7 +136,7 @@ func (srv *CleanUpService) deleteExpiredSnapshots(ctx context.Context) {
func (srv *CleanUpService) deleteExpiredDashboardVersions(ctx context.Context) { func (srv *CleanUpService) deleteExpiredDashboardVersions(ctx context.Context) {
cmd := models.DeleteExpiredVersionsCommand{} cmd := models.DeleteExpiredVersionsCommand{}
if err := bus.DispatchCtx(ctx, &cmd); err != nil { if err := bus.Dispatch(ctx, &cmd); err != nil {
srv.log.Error("Failed to delete expired dashboard versions", "error", err.Error()) srv.log.Error("Failed to delete expired dashboard versions", "error", err.Error())
} else { } else {
srv.log.Debug("Deleted old/expired dashboard versions", "rows affected", cmd.DeletedRows) srv.log.Debug("Deleted old/expired dashboard versions", "rows affected", cmd.DeletedRows)
@ -151,7 +151,7 @@ func (srv *CleanUpService) deleteOldLoginAttempts(ctx context.Context) {
cmd := models.DeleteOldLoginAttemptsCommand{ cmd := models.DeleteOldLoginAttemptsCommand{
OlderThan: time.Now().Add(time.Minute * -10), OlderThan: time.Now().Add(time.Minute * -10),
} }
if err := bus.DispatchCtx(ctx, &cmd); err != nil { if err := bus.Dispatch(ctx, &cmd); err != nil {
srv.log.Error("Problem deleting expired login attempts", "error", err.Error()) srv.log.Error("Problem deleting expired login attempts", "error", err.Error())
} else { } else {
srv.log.Debug("Deleted expired login attempts", "rows affected", cmd.DeletedRows) srv.log.Debug("Deleted expired login attempts", "rows affected", cmd.DeletedRows)
@ -164,7 +164,7 @@ func (srv *CleanUpService) expireOldUserInvites(ctx context.Context) {
cmd := models.ExpireTempUsersCommand{ cmd := models.ExpireTempUsersCommand{
OlderThan: time.Now().Add(-maxInviteLifetime), OlderThan: time.Now().Add(-maxInviteLifetime),
} }
if err := bus.DispatchCtx(ctx, &cmd); err != nil { if err := bus.Dispatch(ctx, &cmd); err != nil {
srv.log.Error("Problem expiring user invites", "error", err.Error()) srv.log.Error("Problem expiring user invites", "error", err.Error())
} else { } else {
srv.log.Debug("Expired user invites", "rows affected", cmd.NumExpired) srv.log.Debug("Expired user invites", "rows affected", cmd.NumExpired)

View File

@ -42,7 +42,7 @@ func (h *ContextHandler) initContextWithJWT(ctx *models.ReqContext, orgId int64)
return true return true
} }
if err := bus.DispatchCtx(ctx.Req.Context(), &query); err != nil { if err := bus.Dispatch(ctx.Req.Context(), &query); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
ctx.Logger.Debug( ctx.Logger.Debug(
"Failed to find user using JWT claims", "Failed to find user using JWT claims",

View File

@ -248,7 +248,7 @@ func (auth *AuthProxy) LoginViaLDAP() (int64, error) {
SignupAllowed: auth.cfg.LDAPAllowSignup, SignupAllowed: auth.cfg.LDAPAllowSignup,
ExternalUser: extUser, ExternalUser: extUser,
} }
if err := bus.DispatchCtx(auth.ctx.Req.Context(), upsert); err != nil { if err := bus.Dispatch(auth.ctx.Req.Context(), upsert); err != nil {
return 0, err return 0, err
} }
@ -305,7 +305,7 @@ func (auth *AuthProxy) LoginViaHeader() (int64, error) {
ExternalUser: extUser, ExternalUser: extUser,
} }
err := bus.DispatchCtx(auth.ctx.Req.Context(), upsert) err := bus.Dispatch(auth.ctx.Req.Context(), upsert)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -334,7 +334,7 @@ func (auth *AuthProxy) GetSignedInUser(userID int64) (*models.SignedInUser, erro
UserId: userID, UserId: userID,
} }
if err := bus.DispatchCtx(context.Background(), query); err != nil { if err := bus.Dispatch(context.Background(), query); err != nil {
return nil, err return nil, err
} }

View File

@ -146,7 +146,7 @@ func (h *ContextHandler) Middleware(mContext *web.Context) {
// update last seen every 5min // update last seen every 5min
if reqContext.ShouldUpdateLastSeenAt() { if reqContext.ShouldUpdateLastSeenAt() {
reqContext.Logger.Debug("Updating last user_seen_at", "user_id", reqContext.UserId) reqContext.Logger.Debug("Updating last user_seen_at", "user_id", reqContext.UserId)
if err := bus.DispatchCtx(mContext.Req.Context(), &models.UpdateUserLastSeenAtCommand{UserId: reqContext.UserId}); err != nil { if err := bus.Dispatch(mContext.Req.Context(), &models.UpdateUserLastSeenAtCommand{UserId: reqContext.UserId}); err != nil {
reqContext.Logger.Error("Failed to update last_seen_at", "error", err) reqContext.Logger.Error("Failed to update last_seen_at", "error", err)
} }
} }
@ -204,7 +204,7 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo
// fetch key // fetch key
keyQuery := models.GetApiKeyByNameQuery{KeyName: decoded.Name, OrgId: decoded.OrgId} keyQuery := models.GetApiKeyByNameQuery{KeyName: decoded.Name, OrgId: decoded.OrgId}
if err := bus.DispatchCtx(reqContext.Req.Context(), &keyQuery); err != nil { if err := bus.Dispatch(reqContext.Req.Context(), &keyQuery); err != nil {
reqContext.JsonApiErr(401, InvalidAPIKey, err) reqContext.JsonApiErr(401, InvalidAPIKey, err)
return true return true
} }
@ -246,7 +246,7 @@ func (h *ContextHandler) initContextWithAPIKey(reqContext *models.ReqContext) bo
//Use service account linked to API key as the signed in user //Use service account linked to API key as the signed in user
query := models.GetSignedInUserQuery{UserId: apikey.ServiceAccountId, OrgId: apikey.OrgId} query := models.GetSignedInUserQuery{UserId: apikey.ServiceAccountId, OrgId: apikey.OrgId}
if err := bus.DispatchCtx(reqContext.Req.Context(), &query); err != nil { if err := bus.Dispatch(reqContext.Req.Context(), &query); err != nil {
reqContext.Logger.Error( reqContext.Logger.Error(
"Failed to link API key to service account in", "Failed to link API key to service account in",
"id", query.UserId, "id", query.UserId,
@ -286,7 +286,7 @@ func (h *ContextHandler) initContextWithBasicAuth(reqContext *models.ReqContext,
Password: password, Password: password,
Cfg: h.Cfg, Cfg: h.Cfg,
} }
if err := bus.DispatchCtx(reqContext.Req.Context(), &authQuery); err != nil { if err := bus.Dispatch(reqContext.Req.Context(), &authQuery); err != nil {
reqContext.Logger.Debug( reqContext.Logger.Debug(
"Failed to authorize the user", "Failed to authorize the user",
"username", username, "username", username,
@ -303,7 +303,7 @@ func (h *ContextHandler) initContextWithBasicAuth(reqContext *models.ReqContext,
user := authQuery.User user := authQuery.User
query := models.GetSignedInUserQuery{UserId: user.Id, OrgId: orgID} query := models.GetSignedInUserQuery{UserId: user.Id, OrgId: orgID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
reqContext.Logger.Error( reqContext.Logger.Error(
"Failed at user signed in", "Failed at user signed in",
"id", user.Id, "id", user.Id,
@ -339,7 +339,7 @@ func (h *ContextHandler) initContextWithToken(reqContext *models.ReqContext, org
} }
query := models.GetSignedInUserQuery{UserId: token.UserId, OrgId: orgID} query := models.GetSignedInUserQuery{UserId: token.UserId, OrgId: orgID}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
reqContext.Logger.Error("Failed to get user with id", "userId", token.UserId, "error", err) reqContext.Logger.Error("Failed to get user with id", "userId", token.UserId, "error", err)
return false return false
} }

View File

@ -324,7 +324,7 @@ func (dr *dashboardServiceImpl) deleteDashboard(ctx context.Context, dashboardId
} }
} }
cmd := &models.DeleteDashboardCommand{OrgId: orgId, Id: dashboardId} cmd := &models.DeleteDashboardCommand{OrgId: orgId, Id: dashboardId}
return bus.DispatchCtx(ctx, cmd) return bus.Dispatch(ctx, cmd)
} }
func (dr *dashboardServiceImpl) ImportDashboard(ctx context.Context, dto *SaveDashboardDTO) ( func (dr *dashboardServiceImpl) ImportDashboard(ctx context.Context, dto *SaveDashboardDTO) (
@ -353,7 +353,7 @@ func (dr *dashboardServiceImpl) ImportDashboard(ctx context.Context, dto *SaveDa
// and provisioned dashboards are left behind but not deleted. // and provisioned dashboards are left behind but not deleted.
func (dr *dashboardServiceImpl) UnprovisionDashboard(ctx context.Context, dashboardId int64) error { func (dr *dashboardServiceImpl) UnprovisionDashboard(ctx context.Context, dashboardId int64) error {
cmd := &models.UnprovisionDashboardCommand{Id: dashboardId} cmd := &models.UnprovisionDashboardCommand{Id: dashboardId}
return bus.DispatchCtx(ctx, cmd) return bus.Dispatch(ctx, cmd)
} }
type FakeDashboardService struct { type FakeDashboardService struct {

View File

@ -45,7 +45,7 @@ func (dr *dashboardServiceImpl) GetFolders(ctx context.Context, limit int64, pag
Page: page, Page: page,
} }
if err := bus.DispatchCtx(ctx, &searchQuery); err != nil { if err := bus.Dispatch(ctx, &searchQuery); err != nil {
return nil, err return nil, err
} }
@ -209,7 +209,7 @@ func (dr *dashboardServiceImpl) DeleteFolder(ctx context.Context, uid string, fo
} }
deleteCmd := models.DeleteDashboardCommand{OrgId: dr.orgId, Id: dashFolder.Id, ForceDeleteFolderRules: forceDeleteRules} deleteCmd := models.DeleteDashboardCommand{OrgId: dr.orgId, Id: dashFolder.Id, ForceDeleteFolderRules: forceDeleteRules}
if err := bus.DispatchCtx(ctx, &deleteCmd); err != nil { if err := bus.Dispatch(ctx, &deleteCmd); err != nil {
return nil, toFolderError(err) return nil, toFolderError(err)
} }
@ -217,7 +217,7 @@ func (dr *dashboardServiceImpl) DeleteFolder(ctx context.Context, uid string, fo
} }
func getFolder(ctx context.Context, query models.GetDashboardQuery) (*models.Dashboard, error) { func getFolder(ctx context.Context, query models.GetDashboardQuery) (*models.Dashboard, error) {
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
return nil, toFolderError(err) return nil, toFolderError(err)
} }

View File

@ -204,7 +204,7 @@ func (g *dashboardGuardianImpl) GetAcl() ([]*models.DashboardAclInfoDTO, error)
} }
query := models.GetDashboardAclInfoListQuery{DashboardID: g.dashId, OrgID: g.orgId} query := models.GetDashboardAclInfoListQuery{DashboardID: g.dashId, OrgID: g.orgId}
if err := bus.DispatchCtx(g.ctx, &query); err != nil { if err := bus.Dispatch(g.ctx, &query); err != nil {
return nil, err return nil, err
} }
@ -254,8 +254,8 @@ func (g *dashboardGuardianImpl) getTeams(ctx context.Context) ([]*models.TeamDTO
} }
query := models.GetTeamsByUserQuery{OrgId: g.orgId, UserId: g.user.UserId} query := models.GetTeamsByUserQuery{OrgId: g.orgId, UserId: g.user.UserId}
// TODO: Use bus.DispatchCtx(g.Ctx, &query) when GetTeamsByUserQuery supports context. // TODO: Use bus.Dispatch(g.Ctx, &query) when GetTeamsByUserQuery supports context.
err := bus.DispatchCtx(ctx, &query) err := bus.Dispatch(ctx, &query)
g.teams = query.Result g.teams = query.Result
return query.Result, err return query.Result, err

View File

@ -62,7 +62,7 @@ func (h *DashboardHandler) OnSubscribe(ctx context.Context, user *models.SignedI
// make sure can view this dashboard // make sure can view this dashboard
if len(parts) == 2 && parts[0] == "uid" { if len(parts) == 2 && parts[0] == "uid" {
query := models.GetDashboardQuery{Uid: parts[1], OrgId: user.OrgId} query := models.GetDashboardQuery{Uid: parts[1], OrgId: user.OrgId}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
logger.Error("Error getting dashboard", "query", query, "error", err) logger.Error("Error getting dashboard", "query", query, "error", err)
return models.SubscribeReply{}, backend.SubscribeStreamStatusNotFound, nil return models.SubscribeReply{}, backend.SubscribeStreamStatusNotFound, nil
} }
@ -109,7 +109,7 @@ func (h *DashboardHandler) OnPublish(ctx context.Context, user *models.SignedInU
return models.PublishReply{}, backend.PublishStreamStatusNotFound, fmt.Errorf("ignore???") return models.PublishReply{}, backend.PublishStreamStatusNotFound, fmt.Errorf("ignore???")
} }
query := models.GetDashboardQuery{Uid: parts[1], OrgId: user.OrgId} query := models.GetDashboardQuery{Uid: parts[1], OrgId: user.OrgId}
if err := bus.DispatchCtx(ctx, &query); err != nil { if err := bus.Dispatch(ctx, &query); err != nil {
logger.Error("Unknown dashboard", "query", query) logger.Error("Unknown dashboard", "query", query)
return models.PublishReply{}, backend.PublishStreamStatusNotFound, nil return models.PublishReply{}, backend.PublishStreamStatusNotFound, nil
} }

View File

@ -15,13 +15,13 @@ var getTime = time.Now
func (s *Implementation) GetExternalUserInfoByLogin(ctx context.Context, query *models.GetExternalUserInfoByLoginQuery) error { func (s *Implementation) GetExternalUserInfoByLogin(ctx context.Context, query *models.GetExternalUserInfoByLoginQuery) error {
userQuery := models.GetUserByLoginQuery{LoginOrEmail: query.LoginOrEmail} userQuery := models.GetUserByLoginQuery{LoginOrEmail: query.LoginOrEmail}
err := s.Bus.DispatchCtx(ctx, &userQuery) err := s.Bus.Dispatch(ctx, &userQuery)
if err != nil { if err != nil {
return err return err
} }
authInfoQuery := &models.GetAuthInfoQuery{UserId: userQuery.Result.Id} authInfoQuery := &models.GetAuthInfoQuery{UserId: userQuery.Result.Id}
if err := s.Bus.DispatchCtx(ctx, authInfoQuery); err != nil { if err := s.Bus.Dispatch(ctx, authInfoQuery); err != nil {
return err return err
} }

View File

@ -81,7 +81,7 @@ func (ls *Implementation) UpsertUser(ctx context.Context, cmd *models.UpsertUser
AuthId: extUser.AuthId, AuthId: extUser.AuthId,
OAuthToken: extUser.OAuthToken, OAuthToken: extUser.OAuthToken,
} }
if err := ls.Bus.DispatchCtx(ctx, cmd2); err != nil { if err := ls.Bus.Dispatch(ctx, cmd2); err != nil {
return err return err
} }
} }
@ -103,7 +103,7 @@ func (ls *Implementation) UpsertUser(ctx context.Context, cmd *models.UpsertUser
if extUser.AuthModule == models.AuthModuleLDAP && user.IsDisabled { if extUser.AuthModule == models.AuthModuleLDAP && user.IsDisabled {
// Re-enable user when it found in LDAP // Re-enable user when it found in LDAP
if err := ls.Bus.DispatchCtx(ctx, &models.DisableUserCommand{UserId: cmd.Result.Id, IsDisabled: false}); err != nil { if err := ls.Bus.Dispatch(ctx, &models.DisableUserCommand{UserId: cmd.Result.Id, IsDisabled: false}); err != nil {
return err return err
} }
} }
@ -176,7 +176,7 @@ func updateUser(ctx context.Context, user *models.User, extUser *models.External
} }
logger.Debug("Syncing user info", "id", user.Id, "update", updateCmd) logger.Debug("Syncing user info", "id", user.Id, "update", updateCmd)
return bus.DispatchCtx(ctx, updateCmd) return bus.Dispatch(ctx, updateCmd)
} }
func updateUserAuth(ctx context.Context, user *models.User, extUser *models.ExternalUserInfo) error { func updateUserAuth(ctx context.Context, user *models.User, extUser *models.ExternalUserInfo) error {
@ -188,7 +188,7 @@ func updateUserAuth(ctx context.Context, user *models.User, extUser *models.Exte
} }
logger.Debug("Updating user_auth info", "user_id", user.Id) logger.Debug("Updating user_auth info", "user_id", user.Id)
return bus.DispatchCtx(ctx, updateCmd) return bus.Dispatch(ctx, updateCmd)
} }
func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.ExternalUserInfo) error { func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.ExternalUserInfo) error {
@ -201,7 +201,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
} }
orgsQuery := &models.GetUserOrgListQuery{UserId: user.Id} orgsQuery := &models.GetUserOrgListQuery{UserId: user.Id}
if err := bus.DispatchCtx(ctx, orgsQuery); err != nil { if err := bus.Dispatch(ctx, orgsQuery); err != nil {
return err return err
} }
@ -218,7 +218,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
} else if extRole != org.Role { } else if extRole != org.Role {
// update role // update role
cmd := &models.UpdateOrgUserCommand{OrgId: org.OrgId, UserId: user.Id, Role: extRole} cmd := &models.UpdateOrgUserCommand{OrgId: org.OrgId, UserId: user.Id, Role: extRole}
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return err return err
} }
} }
@ -232,7 +232,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
// add role // add role
cmd := &models.AddOrgUserCommand{UserId: user.Id, Role: orgRole, OrgId: orgId} cmd := &models.AddOrgUserCommand{UserId: user.Id, Role: orgRole, OrgId: orgId}
err := bus.DispatchCtx(ctx, cmd) err := bus.Dispatch(ctx, cmd)
if err != nil && !errors.Is(err, models.ErrOrgNotFound) { if err != nil && !errors.Is(err, models.ErrOrgNotFound) {
return err return err
} }
@ -243,7 +243,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
logger.Debug("Removing user's organization membership as part of syncing with OAuth login", logger.Debug("Removing user's organization membership as part of syncing with OAuth login",
"userId", user.Id, "orgId", orgId) "userId", user.Id, "orgId", orgId)
cmd := &models.RemoveOrgUserCommand{OrgId: orgId, UserId: user.Id} cmd := &models.RemoveOrgUserCommand{OrgId: orgId, UserId: user.Id}
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
if errors.Is(err, models.ErrLastOrgAdmin) { if errors.Is(err, models.ErrLastOrgAdmin) {
logger.Error(err.Error(), "userId", cmd.UserId, "orgId", cmd.OrgId) logger.Error(err.Error(), "userId", cmd.UserId, "orgId", cmd.OrgId)
continue continue
@ -260,7 +260,7 @@ func syncOrgRoles(ctx context.Context, user *models.User, extUser *models.Extern
break break
} }
return bus.DispatchCtx(ctx, &models.SetUsingOrgCommand{ return bus.Dispatch(ctx, &models.SetUsingOrgCommand{
UserId: user.Id, UserId: user.Id,
OrgId: user.OrgId, OrgId: user.OrgId,
}) })

View File

@ -115,7 +115,7 @@ func (dd *DingDingNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
Body: string(body), Body: string(body),
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return false, fmt.Errorf("send notification to dingding: %w", err) return false, fmt.Errorf("send notification to dingding: %w", err)
} }

View File

@ -114,7 +114,7 @@ func (d DiscordNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
Body: string(body), Body: string(body),
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
d.log.Error("Failed to send notification to Discord", "error", err) d.log.Error("Failed to send notification to Discord", "error", err)
return false, err return false, err
} }

View File

@ -103,7 +103,7 @@ func (en *EmailNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
en.log.Debug("failed to template email message", "err", tmplErr.Error()) en.log.Debug("failed to template email message", "err", tmplErr.Error())
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return false, err return false, err
} }

View File

@ -128,7 +128,7 @@ func (gcn *GoogleChatNotifier) Notify(ctx context.Context, as ...*types.Alert) (
Body: string(body), Body: string(body),
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
gcn.log.Error("Failed to send Google Hangouts Chat alert", "error", err, "webhook", gcn.Name) gcn.log.Error("Failed to send Google Hangouts Chat alert", "error", err, "webhook", gcn.Name)
return false, err return false, err
} }

View File

@ -112,7 +112,7 @@ func (kn *KafkaNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
}, },
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
kn.log.Error("Failed to send notification to Kafka", "error", err, "body", string(body)) kn.log.Error("Failed to send notification to Kafka", "error", err, "body", string(body))
return false, err return false, err
} }

View File

@ -86,7 +86,7 @@ func (ln *LineNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, e
Body: form.Encode(), Body: form.Encode(),
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
ln.log.Error("Failed to send notification to LINE", "error", err, "body", body) ln.log.Error("Failed to send notification to LINE", "error", err, "body", body)
return false, err return false, err
} }

View File

@ -120,7 +120,7 @@ func (on *OpsgenieNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
}, },
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return false, fmt.Errorf("send notification to Opsgenie: %w", err) return false, fmt.Errorf("send notification to Opsgenie: %w", err)
} }

View File

@ -105,7 +105,7 @@ func (pn *PagerdutyNotifier) Notify(ctx context.Context, as ...*types.Alert) (bo
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return false, fmt.Errorf("send notification to Pagerduty: %w", err) return false, fmt.Errorf("send notification to Pagerduty: %w", err)
} }

View File

@ -110,7 +110,7 @@ func (pn *PushoverNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
Body: uploadBody.String(), Body: uploadBody.String(),
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
pn.log.Error("Failed to send pushover notification", "error", err, "webhook", pn.Name) pn.log.Error("Failed to send pushover notification", "error", err, "webhook", pn.Name)
return false, err return false, err
} }

View File

@ -145,7 +145,7 @@ func (sn *SensuGoNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool
"Authorization": fmt.Sprintf("Key %s", sn.APIKey), "Authorization": fmt.Sprintf("Key %s", sn.APIKey),
}, },
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
sn.log.Error("Failed to send Sensu Go event", "error", err, "sensugo", sn.Name) sn.log.Error("Failed to send Sensu Go event", "error", err, "sensugo", sn.Name)
return false, err return false, err
} }

View File

@ -97,7 +97,7 @@ func (tn *TeamsNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
} }
cmd := &models.SendWebhookSync{Url: u, Body: string(b)} cmd := &models.SendWebhookSync{Url: u, Body: string(b)}
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return false, errors.Wrap(err, "send notification to Teams") return false, errors.Wrap(err, "send notification to Teams")
} }

View File

@ -109,7 +109,7 @@ func (tn *TelegramNotifier) Notify(ctx context.Context, as ...*types.Alert) (boo
}, },
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
tn.log.Error("Failed to send webhook", "error", err, "webhook", tn.Name) tn.log.Error("Failed to send webhook", "error", err, "webhook", tn.Name)
return false, err return false, err
} }

View File

@ -119,7 +119,7 @@ func (tn *ThreemaNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
}, },
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
tn.log.Error("Failed to send threema notification", "error", err, "webhook", tn.Name) tn.log.Error("Failed to send threema notification", "error", err, "webhook", tn.Name)
return false, err return false, err
} }

View File

@ -109,7 +109,7 @@ func (vn *VictoropsNotifier) Notify(ctx context.Context, as ...*types.Alert) (bo
Body: string(b), Body: string(b),
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
vn.log.Error("Failed to send Victorops notification", "error", err, "webhook", vn.Name) vn.log.Error("Failed to send Victorops notification", "error", err, "webhook", vn.Name)
return false, err return false, err
} }

View File

@ -118,7 +118,7 @@ func (wn *WebhookNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool
HttpMethod: wn.HTTPMethod, HttpMethod: wn.HTTPMethod,
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return false, err return false, err
} }

View File

@ -74,7 +74,7 @@ func (w *WeComNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool, e
Body: string(body), Body: string(body),
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
w.log.Error("failed to send WeCom webhook", "error", err, "notification", w.Name) w.log.Error("failed to send WeCom webhook", "error", err, "notification", w.Name)
return false, err return false, err
} }

View File

@ -170,7 +170,7 @@ func (ns *NotificationService) validateResetPasswordCode(ctx context.Context, qu
} }
userQuery := models.GetUserByLoginQuery{LoginOrEmail: login} userQuery := models.GetUserByLoginQuery{LoginOrEmail: login}
if err := bus.DispatchCtx(ctx, &userQuery); err != nil { if err := bus.Dispatch(ctx, &userQuery); err != nil {
return err return err
} }
@ -212,7 +212,7 @@ func (ns *NotificationService) signUpStartedHandler(ctx context.Context, evt *ev
} }
emailSentCmd := models.UpdateTempUserWithEmailSentCommand{Code: evt.Code} emailSentCmd := models.UpdateTempUserWithEmailSentCommand{Code: evt.Code}
return bus.DispatchCtx(ctx, &emailSentCmd) return bus.Dispatch(ctx, &emailSentCmd)
} }
func (ns *NotificationService) signUpCompletedHandler(ctx context.Context, evt *events.SignUpCompleted) error { func (ns *NotificationService) signUpCompletedHandler(ctx context.Context, evt *events.SignUpCompleted) error {

View File

@ -38,7 +38,7 @@ func (o *Service) GetCurrentOAuthToken(ctx context.Context, user *models.SignedI
} }
authInfoQuery := &models.GetAuthInfoQuery{UserId: user.UserId} authInfoQuery := &models.GetAuthInfoQuery{UserId: user.UserId}
if err := bus.DispatchCtx(ctx, authInfoQuery); err != nil { if err := bus.Dispatch(ctx, authInfoQuery); err != nil {
if errors.Is(err, models.ErrUserNotFound) { if errors.Is(err, models.ErrUserNotFound) {
// Not necessarily an error. User may be logged in another way. // Not necessarily an error. User may be logged in another way.
logger.Debug("no OAuth token for user found", "userId", user.UserId, "username", user.Login) logger.Debug("no OAuth token for user found", "userId", user.UserId, "username", user.Login)
@ -88,7 +88,7 @@ func (o *Service) GetCurrentOAuthToken(ctx context.Context, user *models.SignedI
AuthId: authInfoQuery.Result.AuthId, AuthId: authInfoQuery.Result.AuthId,
OAuthToken: token, OAuthToken: token,
} }
if err := bus.DispatchCtx(ctx, updateAuthCommand); err != nil { if err := bus.Dispatch(ctx, updateAuthCommand); err != nil {
logger.Error("failed to update auth info during token refresh", "userId", user.UserId, "username", user.Login, "error", err) logger.Error("failed to update auth info during token refresh", "userId", user.UserId, "username", user.Login, "error", err)
return nil return nil
} }

View File

@ -84,7 +84,7 @@ func (provider *Provisioner) CleanUpOrphanedDashboards(ctx context.Context) {
currentReaders[index] = reader.Cfg.Name currentReaders[index] = reader.Cfg.Name
} }
if err := bus.DispatchCtx(ctx, &models.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: currentReaders}); err != nil { if err := bus.Dispatch(ctx, &models.DeleteOrphanedProvisionedDashboardsCommand{ReaderNames: currentReaders}); err != nil {
provider.log.Warn("Failed to delete orphaned provisioned dashboards", "err", err) provider.log.Warn("Failed to delete orphaned provisioned dashboards", "err", err)
} }
} }

View File

@ -297,7 +297,7 @@ func getOrCreateFolderID(ctx context.Context, cfg *config, service dashboards.Da
} }
cmd := &models.GetDashboardQuery{Slug: models.SlugifyTitle(folderName), OrgId: cfg.OrgID} cmd := &models.GetDashboardQuery{Slug: models.SlugifyTitle(folderName), OrgId: cfg.OrgID}
err := bus.DispatchCtx(ctx, cmd) err := bus.Dispatch(ctx, cmd)
if err != nil && !errors.Is(err, models.ErrDashboardNotFound) { if err != nil && !errors.Is(err, models.ErrDashboardNotFound) {
return 0, err return 0, err

View File

@ -45,7 +45,7 @@ func (dc *DatasourceProvisioner) apply(ctx context.Context, cfg *configs) error
for _, ds := range cfg.Datasources { for _, ds := range cfg.Datasources {
cmd := &models.GetDataSourceQuery{OrgId: ds.OrgID, Name: ds.Name} cmd := &models.GetDataSourceQuery{OrgId: ds.OrgID, Name: ds.Name}
err := bus.DispatchCtx(ctx, cmd) err := bus.Dispatch(ctx, cmd)
if err != nil && !errors.Is(err, models.ErrDataSourceNotFound) { if err != nil && !errors.Is(err, models.ErrDataSourceNotFound) {
return err return err
} }
@ -53,13 +53,13 @@ func (dc *DatasourceProvisioner) apply(ctx context.Context, cfg *configs) error
if errors.Is(err, models.ErrDataSourceNotFound) { if errors.Is(err, models.ErrDataSourceNotFound) {
insertCmd := createInsertCommand(ds) insertCmd := createInsertCommand(ds)
dc.log.Info("inserting datasource from configuration ", "name", insertCmd.Name, "uid", insertCmd.Uid) dc.log.Info("inserting datasource from configuration ", "name", insertCmd.Name, "uid", insertCmd.Uid)
if err := bus.DispatchCtx(ctx, insertCmd); err != nil { if err := bus.Dispatch(ctx, insertCmd); err != nil {
return err return err
} }
} else { } else {
updateCmd := createUpdateCommand(ds, cmd.Result.Id) updateCmd := createUpdateCommand(ds, cmd.Result.Id)
dc.log.Debug("updating datasource from configuration", "name", updateCmd.Name, "uid", updateCmd.Uid) dc.log.Debug("updating datasource from configuration", "name", updateCmd.Name, "uid", updateCmd.Uid)
if err := bus.DispatchCtx(ctx, updateCmd); err != nil { if err := bus.Dispatch(ctx, updateCmd); err != nil {
return err return err
} }
} }
@ -86,7 +86,7 @@ func (dc *DatasourceProvisioner) applyChanges(ctx context.Context, configPath st
func (dc *DatasourceProvisioner) deleteDatasources(ctx context.Context, dsToDelete []*deleteDatasourceConfig) error { func (dc *DatasourceProvisioner) deleteDatasources(ctx context.Context, dsToDelete []*deleteDatasourceConfig) error {
for _, ds := range dsToDelete { for _, ds := range dsToDelete {
cmd := &models.DeleteDataSourceCommand{OrgID: ds.OrgID, Name: ds.Name} cmd := &models.DeleteDataSourceCommand{OrgID: ds.OrgID, Name: ds.Name}
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return err return err
} }

View File

@ -48,7 +48,7 @@ func (dc *NotificationProvisioner) deleteNotifications(ctx context.Context, noti
if notification.OrgID == 0 && notification.OrgName != "" { if notification.OrgID == 0 && notification.OrgName != "" {
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName} getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
if err := bus.DispatchCtx(ctx, getOrg); err != nil { if err := bus.Dispatch(ctx, getOrg); err != nil {
return err return err
} }
notification.OrgID = getOrg.Result.Id notification.OrgID = getOrg.Result.Id
@ -58,13 +58,13 @@ func (dc *NotificationProvisioner) deleteNotifications(ctx context.Context, noti
getNotification := &models.GetAlertNotificationsWithUidQuery{Uid: notification.UID, OrgId: notification.OrgID} getNotification := &models.GetAlertNotificationsWithUidQuery{Uid: notification.UID, OrgId: notification.OrgID}
if err := bus.DispatchCtx(ctx, getNotification); err != nil { if err := bus.Dispatch(ctx, getNotification); err != nil {
return err return err
} }
if getNotification.Result != nil { if getNotification.Result != nil {
cmd := &models.DeleteAlertNotificationWithUidCommand{Uid: getNotification.Result.Uid, OrgId: getNotification.OrgId} cmd := &models.DeleteAlertNotificationWithUidCommand{Uid: getNotification.Result.Uid, OrgId: getNotification.OrgId}
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return err return err
} }
} }
@ -77,7 +77,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
for _, notification := range notificationToMerge { for _, notification := range notificationToMerge {
if notification.OrgID == 0 && notification.OrgName != "" { if notification.OrgID == 0 && notification.OrgName != "" {
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName} getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
if err := bus.DispatchCtx(ctx, getOrg); err != nil { if err := bus.Dispatch(ctx, getOrg); err != nil {
return err return err
} }
notification.OrgID = getOrg.Result.Id notification.OrgID = getOrg.Result.Id
@ -86,7 +86,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
} }
cmd := &models.GetAlertNotificationsWithUidQuery{OrgId: notification.OrgID, Uid: notification.UID} cmd := &models.GetAlertNotificationsWithUidQuery{OrgId: notification.OrgID, Uid: notification.UID}
err := bus.DispatchCtx(ctx, cmd) err := bus.Dispatch(ctx, cmd)
if err != nil { if err != nil {
return err return err
} }
@ -106,7 +106,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
SendReminder: notification.SendReminder, SendReminder: notification.SendReminder,
} }
if err := bus.DispatchCtx(ctx, insertCmd); err != nil { if err := bus.Dispatch(ctx, insertCmd); err != nil {
return err return err
} }
} else { } else {
@ -124,7 +124,7 @@ func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notif
SendReminder: notification.SendReminder, SendReminder: notification.SendReminder,
} }
if err := bus.DispatchCtx(ctx, updateCmd); err != nil { if err := bus.Dispatch(ctx, updateCmd); err != nil {
return err return err
} }
} }

View File

@ -32,7 +32,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
for _, app := range cfg.Apps { for _, app := range cfg.Apps {
if app.OrgID == 0 && app.OrgName != "" { if app.OrgID == 0 && app.OrgName != "" {
getOrgQuery := &models.GetOrgByNameQuery{Name: app.OrgName} getOrgQuery := &models.GetOrgByNameQuery{Name: app.OrgName}
if err := bus.DispatchCtx(ctx, getOrgQuery); err != nil { if err := bus.Dispatch(ctx, getOrgQuery); err != nil {
return err return err
} }
app.OrgID = getOrgQuery.Result.Id app.OrgID = getOrgQuery.Result.Id
@ -41,7 +41,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
} }
query := &models.GetPluginSettingByIdQuery{OrgId: app.OrgID, PluginId: app.PluginID} query := &models.GetPluginSettingByIdQuery{OrgId: app.OrgID, PluginId: app.PluginID}
err := bus.DispatchCtx(ctx, query) err := bus.Dispatch(ctx, query)
if err != nil { if err != nil {
if !errors.Is(err, models.ErrPluginSettingNotFound) { if !errors.Is(err, models.ErrPluginSettingNotFound) {
return err return err
@ -60,7 +60,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
SecureJsonData: app.SecureJSONData, SecureJsonData: app.SecureJSONData,
PluginVersion: app.PluginVersion, PluginVersion: app.PluginVersion,
} }
if err := bus.DispatchCtx(ctx, cmd); err != nil { if err := bus.Dispatch(ctx, cmd); err != nil {
return err return err
} }
} }

Some files were not shown because too many files have changed in this diff Show More