Skip to content

Commit c0ecdee

Browse files
committed
rename Context to ReqContext
1 parent 338655d commit c0ecdee

Some content is hidden

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

63 files changed

+241
-241
lines changed

pkg/api/admin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/grafana/grafana/pkg/setting"
99
)
1010

11-
func AdminGetSettings(c *m.Context) {
11+
func AdminGetSettings(c *m.ReqContext) {
1212
settings := make(map[string]interface{})
1313

1414
for _, section := range setting.Cfg.Sections() {
@@ -29,7 +29,7 @@ func AdminGetSettings(c *m.Context) {
2929
c.JSON(200, settings)
3030
}
3131

32-
func AdminGetStats(c *m.Context) {
32+
func AdminGetStats(c *m.ReqContext) {
3333

3434
statsQuery := m.GetAdminStatsQuery{}
3535

pkg/api/admin_users.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/grafana/grafana/pkg/util"
99
)
1010

11-
func AdminCreateUser(c *m.Context, form dtos.AdminCreateUserForm) {
11+
func AdminCreateUser(c *m.ReqContext, form dtos.AdminCreateUserForm) {
1212
cmd := m.CreateUserCommand{
1313
Login: form.Login,
1414
Email: form.Email,
@@ -46,7 +46,7 @@ func AdminCreateUser(c *m.Context, form dtos.AdminCreateUserForm) {
4646
c.JSON(200, result)
4747
}
4848

49-
func AdminUpdateUserPassword(c *m.Context, form dtos.AdminUpdateUserPasswordForm) {
49+
func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordForm) {
5050
userId := c.ParamsInt64(":id")
5151

5252
if len(form.Password) < 4 {
@@ -76,7 +76,7 @@ func AdminUpdateUserPassword(c *m.Context, form dtos.AdminUpdateUserPasswordForm
7676
c.JsonOK("User password updated")
7777
}
7878

79-
func AdminUpdateUserPermissions(c *m.Context, form dtos.AdminUpdateUserPermissionsForm) {
79+
func AdminUpdateUserPermissions(c *m.ReqContext, form dtos.AdminUpdateUserPermissionsForm) {
8080
userId := c.ParamsInt64(":id")
8181

8282
cmd := m.UpdateUserPermissionsCommand{
@@ -92,7 +92,7 @@ func AdminUpdateUserPermissions(c *m.Context, form dtos.AdminUpdateUserPermissio
9292
c.JsonOK("User permissions updated")
9393
}
9494

95-
func AdminDeleteUser(c *m.Context) {
95+
func AdminDeleteUser(c *m.ReqContext) {
9696
userId := c.ParamsInt64(":id")
9797

9898
cmd := m.DeleteUserCommand{UserId: userId}

pkg/api/alerting.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/grafana/grafana/pkg/services/guardian"
1111
)
1212

13-
func ValidateOrgAlert(c *m.Context) {
13+
func ValidateOrgAlert(c *m.ReqContext) {
1414
id := c.ParamsInt64(":alertId")
1515
query := m.GetAlertByIdQuery{Id: id}
1616

@@ -25,7 +25,7 @@ func ValidateOrgAlert(c *m.Context) {
2525
}
2626
}
2727

28-
func GetAlertStatesForDashboard(c *m.Context) Response {
28+
func GetAlertStatesForDashboard(c *m.ReqContext) Response {
2929
dashboardId := c.QueryInt64("dashboardId")
3030

3131
if dashboardId == 0 {
@@ -45,7 +45,7 @@ func GetAlertStatesForDashboard(c *m.Context) Response {
4545
}
4646

4747
// GET /api/alerts
48-
func GetAlerts(c *m.Context) Response {
48+
func GetAlerts(c *m.ReqContext) Response {
4949
query := m.GetAlertsQuery{
5050
OrgId: c.OrgId,
5151
DashboardId: c.QueryInt64("dashboardId"),
@@ -71,7 +71,7 @@ func GetAlerts(c *m.Context) Response {
7171
}
7272

7373
// POST /api/alerts/test
74-
func AlertTest(c *m.Context, dto dtos.AlertTestCommand) Response {
74+
func AlertTest(c *m.ReqContext, dto dtos.AlertTestCommand) Response {
7575
if _, idErr := dto.Dashboard.Get("id").Int64(); idErr != nil {
7676
return ApiError(400, "The dashboard needs to be saved at least once before you can test an alert rule", nil)
7777
}
@@ -113,7 +113,7 @@ func AlertTest(c *m.Context, dto dtos.AlertTestCommand) Response {
113113
}
114114

115115
// GET /api/alerts/:id
116-
func GetAlert(c *m.Context) Response {
116+
func GetAlert(c *m.ReqContext) Response {
117117
id := c.ParamsInt64(":alertId")
118118
query := m.GetAlertByIdQuery{Id: id}
119119

@@ -124,11 +124,11 @@ func GetAlert(c *m.Context) Response {
124124
return Json(200, &query.Result)
125125
}
126126

127-
func GetAlertNotifiers(c *m.Context) Response {
127+
func GetAlertNotifiers(c *m.ReqContext) Response {
128128
return Json(200, alerting.GetNotifiers())
129129
}
130130

131-
func GetAlertNotifications(c *m.Context) Response {
131+
func GetAlertNotifications(c *m.ReqContext) Response {
132132
query := &m.GetAllAlertNotificationsQuery{OrgId: c.OrgId}
133133

134134
if err := bus.Dispatch(query); err != nil {
@@ -151,7 +151,7 @@ func GetAlertNotifications(c *m.Context) Response {
151151
return Json(200, result)
152152
}
153153

154-
func GetAlertNotificationById(c *m.Context) Response {
154+
func GetAlertNotificationById(c *m.ReqContext) Response {
155155
query := &m.GetAlertNotificationsQuery{
156156
OrgId: c.OrgId,
157157
Id: c.ParamsInt64("notificationId"),
@@ -164,7 +164,7 @@ func GetAlertNotificationById(c *m.Context) Response {
164164
return Json(200, query.Result)
165165
}
166166

167-
func CreateAlertNotification(c *m.Context, cmd m.CreateAlertNotificationCommand) Response {
167+
func CreateAlertNotification(c *m.ReqContext, cmd m.CreateAlertNotificationCommand) Response {
168168
cmd.OrgId = c.OrgId
169169

170170
if err := bus.Dispatch(&cmd); err != nil {
@@ -174,7 +174,7 @@ func CreateAlertNotification(c *m.Context, cmd m.CreateAlertNotificationCommand)
174174
return Json(200, cmd.Result)
175175
}
176176

177-
func UpdateAlertNotification(c *m.Context, cmd m.UpdateAlertNotificationCommand) Response {
177+
func UpdateAlertNotification(c *m.ReqContext, cmd m.UpdateAlertNotificationCommand) Response {
178178
cmd.OrgId = c.OrgId
179179

180180
if err := bus.Dispatch(&cmd); err != nil {
@@ -184,7 +184,7 @@ func UpdateAlertNotification(c *m.Context, cmd m.UpdateAlertNotificationCommand)
184184
return Json(200, cmd.Result)
185185
}
186186

187-
func DeleteAlertNotification(c *m.Context) Response {
187+
func DeleteAlertNotification(c *m.ReqContext) Response {
188188
cmd := m.DeleteAlertNotificationCommand{
189189
OrgId: c.OrgId,
190190
Id: c.ParamsInt64("notificationId"),
@@ -198,7 +198,7 @@ func DeleteAlertNotification(c *m.Context) Response {
198198
}
199199

200200
//POST /api/alert-notifications/test
201-
func NotificationTest(c *m.Context, dto dtos.NotificationTestCommand) Response {
201+
func NotificationTest(c *m.ReqContext, dto dtos.NotificationTestCommand) Response {
202202
cmd := &alerting.NotificationTestCommand{
203203
Name: dto.Name,
204204
Type: dto.Type,
@@ -216,7 +216,7 @@ func NotificationTest(c *m.Context, dto dtos.NotificationTestCommand) Response {
216216
}
217217

218218
//POST /api/alerts/:alertId/pause
219-
func PauseAlert(c *m.Context, dto dtos.PauseAlertCommand) Response {
219+
func PauseAlert(c *m.ReqContext, dto dtos.PauseAlertCommand) Response {
220220
alertId := c.ParamsInt64("alertId")
221221

222222
query := m.GetAlertByIdQuery{Id: alertId}
@@ -261,7 +261,7 @@ func PauseAlert(c *m.Context, dto dtos.PauseAlertCommand) Response {
261261
}
262262

263263
//POST /api/admin/pause-all-alerts
264-
func PauseAllAlerts(c *m.Context, dto dtos.PauseAllAlertsCommand) Response {
264+
func PauseAllAlerts(c *m.ReqContext, dto dtos.PauseAllAlertsCommand) Response {
265265
updateCmd := m.PauseAllAlertCommand{
266266
Paused: dto.Paused,
267267
}

pkg/api/alerting_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func postAlertScenario(desc string, url string, routePattern string, role m.Role
8080
defer bus.ClearBusHandlers()
8181

8282
sc := setupScenarioContext(url)
83-
sc.defaultHandler = wrap(func(c *m.Context) Response {
83+
sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
8484
sc.context = c
8585
sc.context.UserId = TestUserID
8686
sc.context.OrgId = TestOrgID

pkg/api/annotations.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/grafana/grafana/pkg/util"
1313
)
1414

15-
func GetAnnotations(c *m.Context) Response {
15+
func GetAnnotations(c *m.ReqContext) Response {
1616

1717
query := &annotations.ItemQuery{
1818
From: c.QueryInt64("from") / 1000,
@@ -51,7 +51,7 @@ func (e *CreateAnnotationError) Error() string {
5151
return e.message
5252
}
5353

54-
func PostAnnotation(c *m.Context, cmd dtos.PostAnnotationsCmd) Response {
54+
func PostAnnotation(c *m.ReqContext, cmd dtos.PostAnnotationsCmd) Response {
5555
if canSave, err := canSaveByDashboardId(c, cmd.DashboardId); err != nil || !canSave {
5656
return dashboardGuardianResponse(err)
5757
}
@@ -124,7 +124,7 @@ func formatGraphiteAnnotation(what string, data string) string {
124124
return text
125125
}
126126

127-
func PostGraphiteAnnotation(c *m.Context, cmd dtos.PostGraphiteAnnotationsCmd) Response {
127+
func PostGraphiteAnnotation(c *m.ReqContext, cmd dtos.PostGraphiteAnnotationsCmd) Response {
128128
repo := annotations.GetRepository()
129129

130130
if cmd.What == "" {
@@ -178,7 +178,7 @@ func PostGraphiteAnnotation(c *m.Context, cmd dtos.PostGraphiteAnnotationsCmd) R
178178
})
179179
}
180180

181-
func UpdateAnnotation(c *m.Context, cmd dtos.UpdateAnnotationsCmd) Response {
181+
func UpdateAnnotation(c *m.ReqContext, cmd dtos.UpdateAnnotationsCmd) Response {
182182
annotationId := c.ParamsInt64(":annotationId")
183183

184184
repo := annotations.GetRepository()
@@ -217,7 +217,7 @@ func UpdateAnnotation(c *m.Context, cmd dtos.UpdateAnnotationsCmd) Response {
217217
return ApiSuccess("Annotation updated")
218218
}
219219

220-
func DeleteAnnotations(c *m.Context, cmd dtos.DeleteAnnotationsCmd) Response {
220+
func DeleteAnnotations(c *m.ReqContext, cmd dtos.DeleteAnnotationsCmd) Response {
221221
repo := annotations.GetRepository()
222222

223223
err := repo.Delete(&annotations.DeleteParams{
@@ -233,7 +233,7 @@ func DeleteAnnotations(c *m.Context, cmd dtos.DeleteAnnotationsCmd) Response {
233233
return ApiSuccess("Annotations deleted")
234234
}
235235

236-
func DeleteAnnotationById(c *m.Context) Response {
236+
func DeleteAnnotationById(c *m.ReqContext) Response {
237237
repo := annotations.GetRepository()
238238
annotationId := c.ParamsInt64(":annotationId")
239239

@@ -252,7 +252,7 @@ func DeleteAnnotationById(c *m.Context) Response {
252252
return ApiSuccess("Annotation deleted")
253253
}
254254

255-
func DeleteAnnotationRegion(c *m.Context) Response {
255+
func DeleteAnnotationRegion(c *m.ReqContext) Response {
256256
repo := annotations.GetRepository()
257257
regionId := c.ParamsInt64(":regionId")
258258

@@ -271,7 +271,7 @@ func DeleteAnnotationRegion(c *m.Context) Response {
271271
return ApiSuccess("Annotation region deleted")
272272
}
273273

274-
func canSaveByDashboardId(c *m.Context, dashboardId int64) (bool, error) {
274+
func canSaveByDashboardId(c *m.ReqContext, dashboardId int64) (bool, error) {
275275
if dashboardId == 0 && !c.SignedInUser.HasRole(m.ROLE_EDITOR) {
276276
return false, nil
277277
}
@@ -286,7 +286,7 @@ func canSaveByDashboardId(c *m.Context, dashboardId int64) (bool, error) {
286286
return true, nil
287287
}
288288

289-
func canSave(c *m.Context, repo annotations.Repository, annotationId int64) Response {
289+
func canSave(c *m.ReqContext, repo annotations.Repository, annotationId int64) Response {
290290
items, err := repo.Find(&annotations.ItemQuery{AnnotationId: annotationId, OrgId: c.OrgId})
291291

292292
if err != nil || len(items) == 0 {
@@ -302,7 +302,7 @@ func canSave(c *m.Context, repo annotations.Repository, annotationId int64) Resp
302302
return nil
303303
}
304304

305-
func canSaveByRegionId(c *m.Context, repo annotations.Repository, regionId int64) Response {
305+
func canSaveByRegionId(c *m.ReqContext, repo annotations.Repository, regionId int64) Response {
306306
items, err := repo.Find(&annotations.ItemQuery{RegionId: regionId, OrgId: c.OrgId})
307307

308308
if err != nil || len(items) == 0 {

pkg/api/annotations_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func postAnnotationScenario(desc string, url string, routePattern string, role m
199199
defer bus.ClearBusHandlers()
200200

201201
sc := setupScenarioContext(url)
202-
sc.defaultHandler = wrap(func(c *m.Context) Response {
202+
sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
203203
sc.context = c
204204
sc.context.UserId = TestUserID
205205
sc.context.OrgId = TestOrgID
@@ -222,7 +222,7 @@ func putAnnotationScenario(desc string, url string, routePattern string, role m.
222222
defer bus.ClearBusHandlers()
223223

224224
sc := setupScenarioContext(url)
225-
sc.defaultHandler = wrap(func(c *m.Context) Response {
225+
sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
226226
sc.context = c
227227
sc.context.UserId = TestUserID
228228
sc.context.OrgId = TestOrgID

pkg/api/apikey.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
m "github.com/grafana/grafana/pkg/models"
88
)
99

10-
func GetApiKeys(c *m.Context) Response {
10+
func GetApiKeys(c *m.ReqContext) Response {
1111
query := m.GetApiKeysQuery{OrgId: c.OrgId}
1212

1313
if err := bus.Dispatch(&query); err != nil {
@@ -26,7 +26,7 @@ func GetApiKeys(c *m.Context) Response {
2626
return Json(200, result)
2727
}
2828

29-
func DeleteApiKey(c *m.Context) Response {
29+
func DeleteApiKey(c *m.ReqContext) Response {
3030
id := c.ParamsInt64(":id")
3131

3232
cmd := &m.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId}
@@ -39,7 +39,7 @@ func DeleteApiKey(c *m.Context) Response {
3939
return ApiSuccess("API key deleted")
4040
}
4141

42-
func AddApiKey(c *m.Context, cmd m.AddApiKeyCommand) Response {
42+
func AddApiKey(c *m.ReqContext, cmd m.AddApiKeyCommand) Response {
4343
if !cmd.Role.IsValid() {
4444
return ApiError(400, "Invalid role specified", nil)
4545
}

pkg/api/app_routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func InitAppPluginRoutes(r *macaron.Macaron) {
5656
}
5757

5858
func AppPluginRoute(route *plugins.AppPluginRoute, appId string) macaron.Handler {
59-
return func(c *m.Context) {
59+
return func(c *m.ReqContext) {
6060
path := c.Params("*")
6161

6262
proxy := pluginproxy.NewApiPluginProxy(c, path, route, appId)

pkg/api/common.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
)
2020

2121
type Response interface {
22-
WriteTo(ctx *m.Context)
22+
WriteTo(ctx *m.ReqContext)
2323
}
2424

2525
type NormalResponse struct {
@@ -32,7 +32,7 @@ type NormalResponse struct {
3232

3333
func wrap(action interface{}) macaron.Handler {
3434

35-
return func(c *m.Context) {
35+
return func(c *m.ReqContext) {
3636
var res Response
3737
val, err := c.Invoke(action)
3838
if err == nil && val != nil && len(val) > 0 {
@@ -45,7 +45,7 @@ func wrap(action interface{}) macaron.Handler {
4545
}
4646
}
4747

48-
func (r *NormalResponse) WriteTo(ctx *m.Context) {
48+
func (r *NormalResponse) WriteTo(ctx *m.ReqContext) {
4949
if r.err != nil {
5050
ctx.Logger.Error(r.errMessage, "error", r.err)
5151
}

pkg/api/common_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func loggedInUserScenarioWithRole(desc string, method string, url string, routeP
2323
defer bus.ClearBusHandlers()
2424

2525
sc := setupScenarioContext(url)
26-
sc.defaultHandler = wrap(func(c *m.Context) Response {
26+
sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
2727
sc.context = c
2828
sc.context.UserId = TestUserID
2929
sc.context.OrgId = TestOrgID
@@ -71,7 +71,7 @@ func (sc *scenarioContext) fakeReqWithParams(method, url string, queryParams map
7171

7272
type scenarioContext struct {
7373
m *macaron.Macaron
74-
context *m.Context
74+
context *m.ReqContext
7575
resp *httptest.ResponseRecorder
7676
handlerFunc handlerFunc
7777
defaultHandler macaron.Handler
@@ -84,7 +84,7 @@ func (sc *scenarioContext) exec() {
8484
}
8585

8686
type scenarioFunc func(c *scenarioContext)
87-
type handlerFunc func(c *m.Context) Response
87+
type handlerFunc func(c *m.ReqContext) Response
8888

8989
func setupScenarioContext(url string) *scenarioContext {
9090
sc := &scenarioContext{

0 commit comments

Comments
 (0)