Skip to content

Commit 8e6d6af

Browse files
authored
Rename DispatchCtx to Dispatch (grafana#43563)
1 parent 7936c4c commit 8e6d6af

File tree

107 files changed

+291
-291
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+291
-291
lines changed

pkg/api/admin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (hs *HTTPServer) AdminGetSettings(c *models.ReqContext) response.Response {
2222
func AdminGetStats(c *models.ReqContext) response.Response {
2323
statsQuery := models.GetAdminStatsQuery{}
2424

25-
if err := bus.DispatchCtx(c.Req.Context(), &statsQuery); err != nil {
25+
if err := bus.Dispatch(c.Req.Context(), &statsQuery); err != nil {
2626
return response.Error(500, "Failed to get admin stats from database", err)
2727
}
2828

pkg/api/admin_users.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func AdminUpdateUserPassword(c *models.ReqContext) response.Response {
7575

7676
userQuery := models.GetUserByIdQuery{Id: userID}
7777

78-
if err := bus.DispatchCtx(c.Req.Context(), &userQuery); err != nil {
78+
if err := bus.Dispatch(c.Req.Context(), &userQuery); err != nil {
7979
return response.Error(500, "Could not read user from database", err)
8080
}
8181

@@ -89,7 +89,7 @@ func AdminUpdateUserPassword(c *models.ReqContext) response.Response {
8989
NewPassword: passwordHashed,
9090
}
9191

92-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
92+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
9393
return response.Error(500, "Failed to update user password", err)
9494
}
9595

@@ -121,7 +121,7 @@ func AdminDeleteUser(c *models.ReqContext) response.Response {
121121

122122
cmd := models.DeleteUserCommand{UserId: userID}
123123

124-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
124+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
125125
if errors.Is(err, models.ErrUserNotFound) {
126126
return response.Error(404, models.ErrUserNotFound.Error(), nil)
127127
}
@@ -137,12 +137,12 @@ func (hs *HTTPServer) AdminDisableUser(c *models.ReqContext) response.Response {
137137

138138
// External users shouldn't be disabled from API
139139
authInfoQuery := &models.GetAuthInfoQuery{UserId: userID}
140-
if err := bus.DispatchCtx(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) {
140+
if err := bus.Dispatch(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) {
141141
return response.Error(500, "Could not disable external user", nil)
142142
}
143143

144144
disableCmd := models.DisableUserCommand{UserId: userID, IsDisabled: true}
145-
if err := bus.DispatchCtx(c.Req.Context(), &disableCmd); err != nil {
145+
if err := bus.Dispatch(c.Req.Context(), &disableCmd); err != nil {
146146
if errors.Is(err, models.ErrUserNotFound) {
147147
return response.Error(404, models.ErrUserNotFound.Error(), nil)
148148
}
@@ -163,12 +163,12 @@ func AdminEnableUser(c *models.ReqContext) response.Response {
163163

164164
// External users shouldn't be disabled from API
165165
authInfoQuery := &models.GetAuthInfoQuery{UserId: userID}
166-
if err := bus.DispatchCtx(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) {
166+
if err := bus.Dispatch(c.Req.Context(), authInfoQuery); !errors.Is(err, models.ErrUserNotFound) {
167167
return response.Error(500, "Could not enable external user", nil)
168168
}
169169

170170
disableCmd := models.DisableUserCommand{UserId: userID, IsDisabled: false}
171-
if err := bus.DispatchCtx(c.Req.Context(), &disableCmd); err != nil {
171+
if err := bus.Dispatch(c.Req.Context(), &disableCmd); err != nil {
172172
if errors.Is(err, models.ErrUserNotFound) {
173173
return response.Error(404, models.ErrUserNotFound.Error(), nil)
174174
}

pkg/api/alerting.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func ValidateOrgAlert(c *models.ReqContext) {
2424
id := c.ParamsInt64(":alertId")
2525
query := models.GetAlertByIdQuery{Id: id}
2626

27-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
27+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
2828
c.JsonApiErr(404, "Alert not found", nil)
2929
return
3030
}
@@ -47,7 +47,7 @@ func GetAlertStatesForDashboard(c *models.ReqContext) response.Response {
4747
DashboardId: c.QueryInt64("dashboardId"),
4848
}
4949

50-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
50+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
5151
return response.Error(500, "Failed to fetch alert states", err)
5252
}
5353

@@ -90,7 +90,7 @@ func GetAlerts(c *models.ReqContext) response.Response {
9090
Permission: models.PERMISSION_VIEW,
9191
}
9292

93-
err := bus.DispatchCtx(c.Req.Context(), &searchQuery)
93+
err := bus.Dispatch(c.Req.Context(), &searchQuery)
9494
if err != nil {
9595
return response.Error(500, "List alerts failed", err)
9696
}
@@ -121,7 +121,7 @@ func GetAlerts(c *models.ReqContext) response.Response {
121121
query.State = states
122122
}
123123

124-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
124+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
125125
return response.Error(500, "List alerts failed", err)
126126
}
127127

@@ -181,7 +181,7 @@ func GetAlert(c *models.ReqContext) response.Response {
181181
id := c.ParamsInt64(":alertId")
182182
query := models.GetAlertByIdQuery{Id: id}
183183

184-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
184+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
185185
return response.Error(500, "List alerts failed", err)
186186
}
187187

@@ -232,7 +232,7 @@ func GetAlertNotifications(c *models.ReqContext) response.Response {
232232
func getAlertNotificationsInternal(c *models.ReqContext) ([]*models.AlertNotification, error) {
233233
query := &models.GetAllAlertNotificationsQuery{OrgId: c.OrgId}
234234

235-
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil {
235+
if err := bus.Dispatch(c.Req.Context(), query); err != nil {
236236
return nil, err
237237
}
238238

@@ -249,7 +249,7 @@ func GetAlertNotificationByID(c *models.ReqContext) response.Response {
249249
return response.Error(404, "Alert notification not found", nil)
250250
}
251251

252-
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil {
252+
if err := bus.Dispatch(c.Req.Context(), query); err != nil {
253253
return response.Error(500, "Failed to get alert notifications", err)
254254
}
255255

@@ -270,7 +270,7 @@ func GetAlertNotificationByUID(c *models.ReqContext) response.Response {
270270
return response.Error(404, "Alert notification not found", nil)
271271
}
272272

273-
if err := bus.DispatchCtx(c.Req.Context(), query); err != nil {
273+
if err := bus.Dispatch(c.Req.Context(), query); err != nil {
274274
return response.Error(500, "Failed to get alert notifications", err)
275275
}
276276

@@ -288,7 +288,7 @@ func CreateAlertNotification(c *models.ReqContext) response.Response {
288288
}
289289
cmd.OrgId = c.OrgId
290290

291-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
291+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
292292
if errors.Is(err, models.ErrAlertNotificationWithSameNameExists) || errors.Is(err, models.ErrAlertNotificationWithSameUIDExists) {
293293
return response.Error(409, "Failed to create alert notification", err)
294294
}
@@ -314,7 +314,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res
314314
return response.Error(500, "Failed to update alert notification", err)
315315
}
316316

317-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
317+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
318318
if errors.Is(err, models.ErrAlertNotificationNotFound) {
319319
return response.Error(404, err.Error(), err)
320320
}
@@ -330,7 +330,7 @@ func (hs *HTTPServer) UpdateAlertNotification(c *models.ReqContext) response.Res
330330
Id: cmd.Id,
331331
}
332332

333-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
333+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
334334
return response.Error(500, "Failed to get alert notification", err)
335335
}
336336

@@ -350,7 +350,7 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons
350350
return response.Error(500, "Failed to update alert notification", err)
351351
}
352352

353-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
353+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
354354
if errors.Is(err, models.ErrAlertNotificationNotFound) {
355355
return response.Error(404, err.Error(), nil)
356356
}
@@ -362,7 +362,7 @@ func (hs *HTTPServer) UpdateAlertNotificationByUID(c *models.ReqContext) respons
362362
Uid: cmd.Uid,
363363
}
364364

365-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
365+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
366366
return response.Error(500, "Failed to get alert notification", err)
367367
}
368368

@@ -379,7 +379,7 @@ func (hs *HTTPServer) fillWithSecureSettingsData(ctx context.Context, cmd *model
379379
Id: cmd.Id,
380380
}
381381

382-
if err := bus.DispatchCtx(ctx, query); err != nil {
382+
if err := bus.Dispatch(ctx, query); err != nil {
383383
return err
384384
}
385385

@@ -407,7 +407,7 @@ func (hs *HTTPServer) fillWithSecureSettingsDataByUID(ctx context.Context, cmd *
407407
Uid: cmd.Uid,
408408
}
409409

410-
if err := bus.DispatchCtx(ctx, query); err != nil {
410+
if err := bus.Dispatch(ctx, query); err != nil {
411411
return err
412412
}
413413

@@ -431,7 +431,7 @@ func DeleteAlertNotification(c *models.ReqContext) response.Response {
431431
Id: c.ParamsInt64(":notificationId"),
432432
}
433433

434-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
434+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
435435
if errors.Is(err, models.ErrAlertNotificationNotFound) {
436436
return response.Error(404, err.Error(), nil)
437437
}
@@ -447,7 +447,7 @@ func DeleteAlertNotificationByUID(c *models.ReqContext) response.Response {
447447
Uid: web.Params(c.Req)[":uid"],
448448
}
449449

450-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
450+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
451451
if errors.Is(err, models.ErrAlertNotificationNotFound) {
452452
return response.Error(404, err.Error(), nil)
453453
}
@@ -475,7 +475,7 @@ func NotificationTest(c *models.ReqContext) response.Response {
475475
SecureSettings: dto.SecureSettings,
476476
}
477477

478-
if err := bus.DispatchCtx(c.Req.Context(), cmd); err != nil {
478+
if err := bus.Dispatch(c.Req.Context(), cmd); err != nil {
479479
if errors.Is(err, models.ErrSmtpNotEnabled) {
480480
return response.Error(412, err.Error(), err)
481481
}
@@ -501,7 +501,7 @@ func PauseAlert(c *models.ReqContext) response.Response {
501501
result["alertId"] = alertID
502502

503503
query := models.GetAlertByIdQuery{Id: alertID}
504-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
504+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
505505
return response.Error(500, "Get Alert failed", err)
506506
}
507507

@@ -531,7 +531,7 @@ func PauseAlert(c *models.ReqContext) response.Response {
531531
Paused: dto.Paused,
532532
}
533533

534-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
534+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
535535
return response.Error(500, "", err)
536536
}
537537

@@ -557,7 +557,7 @@ func PauseAllAlerts(c *models.ReqContext) response.Response {
557557
Paused: dto.Paused,
558558
}
559559

560-
if err := bus.DispatchCtx(c.Req.Context(), &updateCmd); err != nil {
560+
if err := bus.Dispatch(c.Req.Context(), &updateCmd); err != nil {
561561
return response.Error(500, "Failed to pause alerts", err)
562562
}
563563

pkg/api/apikey.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func GetAPIKeys(c *models.ReqContext) response.Response {
1818
query := models.GetApiKeysQuery{OrgId: c.OrgId, IncludeExpired: c.QueryBool("includeExpired")}
1919

20-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
20+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
2121
return response.Error(500, "Failed to list api keys", err)
2222
}
2323

@@ -45,7 +45,7 @@ func DeleteAPIKey(c *models.ReqContext) response.Response {
4545

4646
cmd := &models.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId}
4747

48-
err := bus.DispatchCtx(c.Req.Context(), cmd)
48+
err := bus.Dispatch(c.Req.Context(), cmd)
4949
if err != nil {
5050
var status int
5151
if errors.Is(err, models.ErrApiKeyNotFound) {
@@ -94,7 +94,7 @@ func (hs *HTTPServer) AddAPIKey(c *models.ReqContext) response.Response {
9494

9595
//Check if user and service account are in the same org
9696
query := models.GetUserByIdQuery{Id: cmd.ServiceAccountId}
97-
err = bus.DispatchCtx(c.Req.Context(), &query)
97+
err = bus.Dispatch(c.Req.Context(), &query)
9898
if err != nil {
9999
hs.log.Warn("Unable to link new API key to existing service account", "err", err, "query", query)
100100
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 {
118118

119119
cmd.Key = newKeyInfo.HashedKey
120120

121-
if err := bus.DispatchCtx(c.Req.Context(), &cmd); err != nil {
121+
if err := bus.Dispatch(c.Req.Context(), &cmd); err != nil {
122122
if errors.Is(err, models.ErrInvalidApiKeyExpiration) {
123123
return response.Error(400, err.Error(), nil)
124124
}

pkg/api/dashboard.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func isDashboardStarredByUser(c *models.ReqContext, dashID int64) (bool, error)
3434
}
3535

3636
query := models.IsStarredByUserQuery{UserId: c.UserId, DashboardId: dashID}
37-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
37+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
3838
return false, err
3939
}
4040

@@ -142,7 +142,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
142142
// lookup folder title
143143
if dash.FolderId > 0 {
144144
query := models.GetDashboardQuery{Id: dash.FolderId, OrgId: c.OrgId}
145-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
145+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
146146
if errors.Is(err, models.ErrFolderNotFound) {
147147
return response.Error(404, "Folder not found", err)
148148
}
@@ -196,7 +196,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response {
196196

197197
func getUserLogin(ctx context.Context, userID int64) string {
198198
query := models.GetUserByIdQuery{Id: userID}
199-
err := bus.DispatchCtx(ctx, &query)
199+
err := bus.Dispatch(ctx, &query)
200200
if err != nil {
201201
return anonString
202202
}
@@ -212,7 +212,7 @@ func getDashboardHelper(ctx context.Context, orgID int64, id int64, uid string)
212212
query = models.GetDashboardQuery{Id: id, OrgId: orgID}
213213
}
214214

215-
if err := bus.DispatchCtx(ctx, &query); err != nil {
215+
if err := bus.Dispatch(ctx, &query); err != nil {
216216
return nil, response.Error(404, "Dashboard not found", err)
217217
}
218218

@@ -222,7 +222,7 @@ func getDashboardHelper(ctx context.Context, orgID int64, id int64, uid string)
222222
func (hs *HTTPServer) DeleteDashboardBySlug(c *models.ReqContext) response.Response {
223223
query := models.GetDashboardsBySlugQuery{OrgId: c.OrgId, Slug: web.Params(c.Req)[":slug"]}
224224

225-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
225+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
226226
return response.Error(500, "Failed to retrieve dashboards by slug", err)
227227
}
228228

@@ -448,7 +448,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
448448
prefsQuery := models.GetPreferencesWithDefaultsQuery{User: c.SignedInUser}
449449
homePage := hs.Cfg.HomePage
450450

451-
if err := hs.Bus.DispatchCtx(c.Req.Context(), &prefsQuery); err != nil {
451+
if err := hs.Bus.Dispatch(c.Req.Context(), &prefsQuery); err != nil {
452452
return response.Error(500, "Failed to get preferences", err)
453453
}
454454

@@ -459,7 +459,7 @@ func (hs *HTTPServer) GetHomeDashboard(c *models.ReqContext) response.Response {
459459

460460
if prefsQuery.Result.HomeDashboardId != 0 {
461461
slugQuery := models.GetDashboardRefByIdQuery{Id: prefsQuery.Result.HomeDashboardId}
462-
err := hs.Bus.DispatchCtx(c.Req.Context(), &slugQuery)
462+
err := hs.Bus.Dispatch(c.Req.Context(), &slugQuery)
463463
if err == nil {
464464
url := models.GetDashboardUrl(slugQuery.Result.Uid, slugQuery.Result.Slug)
465465
dashRedirect := dtos.DashboardRedirect{RedirectUri: url}
@@ -543,7 +543,7 @@ func GetDashboardVersions(c *models.ReqContext) response.Response {
543543
Start: c.QueryInt("start"),
544544
}
545545

546-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
546+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
547547
return response.Error(404, fmt.Sprintf("No versions found for dashboardId %d", dashID), err)
548548
}
549549

@@ -582,7 +582,7 @@ func GetDashboardVersion(c *models.ReqContext) response.Response {
582582
Version: int(version),
583583
}
584584

585-
if err := bus.DispatchCtx(c.Req.Context(), &query); err != nil {
585+
if err := bus.Dispatch(c.Req.Context(), &query); err != nil {
586586
return response.Error(500, fmt.Sprintf("Dashboard version %d not found for dashboardId %d", query.Version, dashID), err)
587587
}
588588

@@ -671,7 +671,7 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext) response.Res
671671
}
672672

673673
versionQuery := models.GetDashboardVersionQuery{DashboardId: dash.Id, Version: apiCmd.Version, OrgId: c.OrgId}
674-
if err := bus.DispatchCtx(c.Req.Context(), &versionQuery); err != nil {
674+
if err := bus.Dispatch(c.Req.Context(), &versionQuery); err != nil {
675675
return response.Error(404, "Dashboard version not found", nil)
676676
}
677677

@@ -692,7 +692,7 @@ func (hs *HTTPServer) RestoreDashboardVersion(c *models.ReqContext) response.Res
692692

693693
func GetDashboardTags(c *models.ReqContext) {
694694
query := models.GetDashboardTagsQuery{OrgId: c.OrgId}
695-
err := bus.DispatchCtx(c.Req.Context(), &query)
695+
err := bus.Dispatch(c.Req.Context(), &query)
696696
if err != nil {
697697
c.JsonApiErr(500, "Failed to get tags from database", err)
698698
return

0 commit comments

Comments
 (0)