Browse Source

rename Context to ReqContext

Dan Cech 7 năm trước cách đây
mục cha
commit
c0ecdee375
63 tập tin đã thay đổi với 241 bổ sung241 xóa
  1. 2 2
      pkg/api/admin.go
  2. 4 4
      pkg/api/admin_users.go
  3. 14 14
      pkg/api/alerting.go
  4. 1 1
      pkg/api/alerting_test.go
  5. 10 10
      pkg/api/annotations.go
  6. 2 2
      pkg/api/annotations_test.go
  7. 3 3
      pkg/api/apikey.go
  8. 1 1
      pkg/api/app_routes.go
  9. 3 3
      pkg/api/common.go
  10. 3 3
      pkg/api/common_test.go
  11. 11 11
      pkg/api/dashboard.go
  12. 2 2
      pkg/api/dashboard_permission.go
  13. 1 1
      pkg/api/dashboard_permission_test.go
  14. 5 5
      pkg/api/dashboard_snapshot.go
  15. 2 2
      pkg/api/dashboard_test.go
  16. 1 1
      pkg/api/dataproxy.go
  17. 8 8
      pkg/api/datasources.go
  18. 6 6
      pkg/api/folder.go
  19. 2 2
      pkg/api/folder_permission.go
  20. 1 1
      pkg/api/folder_permission_test.go
  21. 2 2
      pkg/api/folder_test.go
  22. 2 2
      pkg/api/frontendsettings.go
  23. 1 1
      pkg/api/grafana_com_proxy.go
  24. 3 3
      pkg/api/index.go
  25. 6 6
      pkg/api/login.go
  26. 2 2
      pkg/api/login_oauth.go
  27. 5 5
      pkg/api/metrics.go
  28. 10 10
      pkg/api/org.go
  29. 6 6
      pkg/api/org_invite.go
  30. 8 8
      pkg/api/org_users.go
  31. 2 2
      pkg/api/password.go
  32. 8 8
      pkg/api/playlist.go
  33. 3 3
      pkg/api/pluginproxy/ds_proxy.go
  34. 5 5
      pkg/api/pluginproxy/ds_proxy_test.go
  35. 1 1
      pkg/api/pluginproxy/pluginproxy.go
  36. 6 6
      pkg/api/plugins.go
  37. 5 5
      pkg/api/preferences.go
  38. 4 4
      pkg/api/quota.go
  39. 1 1
      pkg/api/render.go
  40. 1 1
      pkg/api/search.go
  41. 3 3
      pkg/api/signup.go
  42. 2 2
      pkg/api/stars.go
  43. 5 5
      pkg/api/team.go
  44. 3 3
      pkg/api/team_members.go
  45. 16 16
      pkg/api/user.go
  46. 6 6
      pkg/middleware/auth.go
  47. 3 3
      pkg/middleware/auth_proxy.go
  48. 3 3
      pkg/middleware/auth_proxy_test.go
  49. 2 2
      pkg/middleware/dashboard_redirect.go
  50. 1 1
      pkg/middleware/logger.go
  51. 6 6
      pkg/middleware/middleware.go
  52. 6 6
      pkg/middleware/middleware_test.go
  53. 1 1
      pkg/middleware/org_redirect.go
  54. 2 2
      pkg/middleware/org_redirect_test.go
  55. 1 1
      pkg/middleware/perf.go
  56. 2 2
      pkg/middleware/quota.go
  57. 1 1
      pkg/middleware/quota_test.go
  58. 2 2
      pkg/middleware/recovery.go
  59. 2 2
      pkg/middleware/recovery_test.go
  60. 1 1
      pkg/middleware/render_auth.go
  61. 1 1
      pkg/middleware/session.go
  62. 1 1
      pkg/middleware/validate_host.go
  63. 8 8
      pkg/models/context.go

+ 2 - 2
pkg/api/admin.go

@@ -8,7 +8,7 @@ import (
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
 
 
-func AdminGetSettings(c *m.Context) {
+func AdminGetSettings(c *m.ReqContext) {
 	settings := make(map[string]interface{})
 	settings := make(map[string]interface{})
 
 
 	for _, section := range setting.Cfg.Sections() {
 	for _, section := range setting.Cfg.Sections() {
@@ -29,7 +29,7 @@ func AdminGetSettings(c *m.Context) {
 	c.JSON(200, settings)
 	c.JSON(200, settings)
 }
 }
 
 
-func AdminGetStats(c *m.Context) {
+func AdminGetStats(c *m.ReqContext) {
 
 
 	statsQuery := m.GetAdminStatsQuery{}
 	statsQuery := m.GetAdminStatsQuery{}
 
 

+ 4 - 4
pkg/api/admin_users.go

@@ -8,7 +8,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func AdminCreateUser(c *m.Context, form dtos.AdminCreateUserForm) {
+func AdminCreateUser(c *m.ReqContext, form dtos.AdminCreateUserForm) {
 	cmd := m.CreateUserCommand{
 	cmd := m.CreateUserCommand{
 		Login:    form.Login,
 		Login:    form.Login,
 		Email:    form.Email,
 		Email:    form.Email,
@@ -46,7 +46,7 @@ func AdminCreateUser(c *m.Context, form dtos.AdminCreateUserForm) {
 	c.JSON(200, result)
 	c.JSON(200, result)
 }
 }
 
 
-func AdminUpdateUserPassword(c *m.Context, form dtos.AdminUpdateUserPasswordForm) {
+func AdminUpdateUserPassword(c *m.ReqContext, form dtos.AdminUpdateUserPasswordForm) {
 	userId := c.ParamsInt64(":id")
 	userId := c.ParamsInt64(":id")
 
 
 	if len(form.Password) < 4 {
 	if len(form.Password) < 4 {
@@ -76,7 +76,7 @@ func AdminUpdateUserPassword(c *m.Context, form dtos.AdminUpdateUserPasswordForm
 	c.JsonOK("User password updated")
 	c.JsonOK("User password updated")
 }
 }
 
 
-func AdminUpdateUserPermissions(c *m.Context, form dtos.AdminUpdateUserPermissionsForm) {
+func AdminUpdateUserPermissions(c *m.ReqContext, form dtos.AdminUpdateUserPermissionsForm) {
 	userId := c.ParamsInt64(":id")
 	userId := c.ParamsInt64(":id")
 
 
 	cmd := m.UpdateUserPermissionsCommand{
 	cmd := m.UpdateUserPermissionsCommand{
@@ -92,7 +92,7 @@ func AdminUpdateUserPermissions(c *m.Context, form dtos.AdminUpdateUserPermissio
 	c.JsonOK("User permissions updated")
 	c.JsonOK("User permissions updated")
 }
 }
 
 
-func AdminDeleteUser(c *m.Context) {
+func AdminDeleteUser(c *m.ReqContext) {
 	userId := c.ParamsInt64(":id")
 	userId := c.ParamsInt64(":id")
 
 
 	cmd := m.DeleteUserCommand{UserId: userId}
 	cmd := m.DeleteUserCommand{UserId: userId}

+ 14 - 14
pkg/api/alerting.go

@@ -10,7 +10,7 @@ import (
 	"github.com/grafana/grafana/pkg/services/guardian"
 	"github.com/grafana/grafana/pkg/services/guardian"
 )
 )
 
 
-func ValidateOrgAlert(c *m.Context) {
+func ValidateOrgAlert(c *m.ReqContext) {
 	id := c.ParamsInt64(":alertId")
 	id := c.ParamsInt64(":alertId")
 	query := m.GetAlertByIdQuery{Id: id}
 	query := m.GetAlertByIdQuery{Id: id}
 
 
@@ -25,7 +25,7 @@ func ValidateOrgAlert(c *m.Context) {
 	}
 	}
 }
 }
 
 
-func GetAlertStatesForDashboard(c *m.Context) Response {
+func GetAlertStatesForDashboard(c *m.ReqContext) Response {
 	dashboardId := c.QueryInt64("dashboardId")
 	dashboardId := c.QueryInt64("dashboardId")
 
 
 	if dashboardId == 0 {
 	if dashboardId == 0 {
@@ -45,7 +45,7 @@ func GetAlertStatesForDashboard(c *m.Context) Response {
 }
 }
 
 
 // GET /api/alerts
 // GET /api/alerts
-func GetAlerts(c *m.Context) Response {
+func GetAlerts(c *m.ReqContext) Response {
 	query := m.GetAlertsQuery{
 	query := m.GetAlertsQuery{
 		OrgId:       c.OrgId,
 		OrgId:       c.OrgId,
 		DashboardId: c.QueryInt64("dashboardId"),
 		DashboardId: c.QueryInt64("dashboardId"),
@@ -71,7 +71,7 @@ func GetAlerts(c *m.Context) Response {
 }
 }
 
 
 // POST /api/alerts/test
 // POST /api/alerts/test
-func AlertTest(c *m.Context, dto dtos.AlertTestCommand) Response {
+func AlertTest(c *m.ReqContext, dto dtos.AlertTestCommand) Response {
 	if _, idErr := dto.Dashboard.Get("id").Int64(); idErr != nil {
 	if _, idErr := dto.Dashboard.Get("id").Int64(); idErr != nil {
 		return ApiError(400, "The dashboard needs to be saved at least once before you can test an alert rule", nil)
 		return ApiError(400, "The dashboard needs to be saved at least once before you can test an alert rule", nil)
 	}
 	}
@@ -113,7 +113,7 @@ func AlertTest(c *m.Context, dto dtos.AlertTestCommand) Response {
 }
 }
 
 
 // GET /api/alerts/:id
 // GET /api/alerts/:id
-func GetAlert(c *m.Context) Response {
+func GetAlert(c *m.ReqContext) Response {
 	id := c.ParamsInt64(":alertId")
 	id := c.ParamsInt64(":alertId")
 	query := m.GetAlertByIdQuery{Id: id}
 	query := m.GetAlertByIdQuery{Id: id}
 
 
@@ -124,11 +124,11 @@ func GetAlert(c *m.Context) Response {
 	return Json(200, &query.Result)
 	return Json(200, &query.Result)
 }
 }
 
 
-func GetAlertNotifiers(c *m.Context) Response {
+func GetAlertNotifiers(c *m.ReqContext) Response {
 	return Json(200, alerting.GetNotifiers())
 	return Json(200, alerting.GetNotifiers())
 }
 }
 
 
-func GetAlertNotifications(c *m.Context) Response {
+func GetAlertNotifications(c *m.ReqContext) Response {
 	query := &m.GetAllAlertNotificationsQuery{OrgId: c.OrgId}
 	query := &m.GetAllAlertNotificationsQuery{OrgId: c.OrgId}
 
 
 	if err := bus.Dispatch(query); err != nil {
 	if err := bus.Dispatch(query); err != nil {
@@ -151,7 +151,7 @@ func GetAlertNotifications(c *m.Context) Response {
 	return Json(200, result)
 	return Json(200, result)
 }
 }
 
 
-func GetAlertNotificationById(c *m.Context) Response {
+func GetAlertNotificationById(c *m.ReqContext) Response {
 	query := &m.GetAlertNotificationsQuery{
 	query := &m.GetAlertNotificationsQuery{
 		OrgId: c.OrgId,
 		OrgId: c.OrgId,
 		Id:    c.ParamsInt64("notificationId"),
 		Id:    c.ParamsInt64("notificationId"),
@@ -164,7 +164,7 @@ func GetAlertNotificationById(c *m.Context) Response {
 	return Json(200, query.Result)
 	return Json(200, query.Result)
 }
 }
 
 
-func CreateAlertNotification(c *m.Context, cmd m.CreateAlertNotificationCommand) Response {
+func CreateAlertNotification(c *m.ReqContext, cmd m.CreateAlertNotificationCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 
 
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {
@@ -174,7 +174,7 @@ func CreateAlertNotification(c *m.Context, cmd m.CreateAlertNotificationCommand)
 	return Json(200, cmd.Result)
 	return Json(200, cmd.Result)
 }
 }
 
 
-func UpdateAlertNotification(c *m.Context, cmd m.UpdateAlertNotificationCommand) Response {
+func UpdateAlertNotification(c *m.ReqContext, cmd m.UpdateAlertNotificationCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 
 
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {
@@ -184,7 +184,7 @@ func UpdateAlertNotification(c *m.Context, cmd m.UpdateAlertNotificationCommand)
 	return Json(200, cmd.Result)
 	return Json(200, cmd.Result)
 }
 }
 
 
-func DeleteAlertNotification(c *m.Context) Response {
+func DeleteAlertNotification(c *m.ReqContext) Response {
 	cmd := m.DeleteAlertNotificationCommand{
 	cmd := m.DeleteAlertNotificationCommand{
 		OrgId: c.OrgId,
 		OrgId: c.OrgId,
 		Id:    c.ParamsInt64("notificationId"),
 		Id:    c.ParamsInt64("notificationId"),
@@ -198,7 +198,7 @@ func DeleteAlertNotification(c *m.Context) Response {
 }
 }
 
 
 //POST /api/alert-notifications/test
 //POST /api/alert-notifications/test
-func NotificationTest(c *m.Context, dto dtos.NotificationTestCommand) Response {
+func NotificationTest(c *m.ReqContext, dto dtos.NotificationTestCommand) Response {
 	cmd := &alerting.NotificationTestCommand{
 	cmd := &alerting.NotificationTestCommand{
 		Name:     dto.Name,
 		Name:     dto.Name,
 		Type:     dto.Type,
 		Type:     dto.Type,
@@ -216,7 +216,7 @@ func NotificationTest(c *m.Context, dto dtos.NotificationTestCommand) Response {
 }
 }
 
 
 //POST /api/alerts/:alertId/pause
 //POST /api/alerts/:alertId/pause
-func PauseAlert(c *m.Context, dto dtos.PauseAlertCommand) Response {
+func PauseAlert(c *m.ReqContext, dto dtos.PauseAlertCommand) Response {
 	alertId := c.ParamsInt64("alertId")
 	alertId := c.ParamsInt64("alertId")
 
 
 	query := m.GetAlertByIdQuery{Id: alertId}
 	query := m.GetAlertByIdQuery{Id: alertId}
@@ -261,7 +261,7 @@ func PauseAlert(c *m.Context, dto dtos.PauseAlertCommand) Response {
 }
 }
 
 
 //POST /api/admin/pause-all-alerts
 //POST /api/admin/pause-all-alerts
-func PauseAllAlerts(c *m.Context, dto dtos.PauseAllAlertsCommand) Response {
+func PauseAllAlerts(c *m.ReqContext, dto dtos.PauseAllAlertsCommand) Response {
 	updateCmd := m.PauseAllAlertCommand{
 	updateCmd := m.PauseAllAlertCommand{
 		Paused: dto.Paused,
 		Paused: dto.Paused,
 	}
 	}

+ 1 - 1
pkg/api/alerting_test.go

@@ -80,7 +80,7 @@ func postAlertScenario(desc string, url string, routePattern string, role m.Role
 		defer bus.ClearBusHandlers()
 		defer bus.ClearBusHandlers()
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.UserId = TestUserID
 			sc.context.UserId = TestUserID
 			sc.context.OrgId = TestOrgID
 			sc.context.OrgId = TestOrgID

+ 10 - 10
pkg/api/annotations.go

@@ -12,7 +12,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func GetAnnotations(c *m.Context) Response {
+func GetAnnotations(c *m.ReqContext) Response {
 
 
 	query := &annotations.ItemQuery{
 	query := &annotations.ItemQuery{
 		From:        c.QueryInt64("from") / 1000,
 		From:        c.QueryInt64("from") / 1000,
@@ -51,7 +51,7 @@ func (e *CreateAnnotationError) Error() string {
 	return e.message
 	return e.message
 }
 }
 
 
-func PostAnnotation(c *m.Context, cmd dtos.PostAnnotationsCmd) Response {
+func PostAnnotation(c *m.ReqContext, cmd dtos.PostAnnotationsCmd) Response {
 	if canSave, err := canSaveByDashboardId(c, cmd.DashboardId); err != nil || !canSave {
 	if canSave, err := canSaveByDashboardId(c, cmd.DashboardId); err != nil || !canSave {
 		return dashboardGuardianResponse(err)
 		return dashboardGuardianResponse(err)
 	}
 	}
@@ -124,7 +124,7 @@ func formatGraphiteAnnotation(what string, data string) string {
 	return text
 	return text
 }
 }
 
 
-func PostGraphiteAnnotation(c *m.Context, cmd dtos.PostGraphiteAnnotationsCmd) Response {
+func PostGraphiteAnnotation(c *m.ReqContext, cmd dtos.PostGraphiteAnnotationsCmd) Response {
 	repo := annotations.GetRepository()
 	repo := annotations.GetRepository()
 
 
 	if cmd.What == "" {
 	if cmd.What == "" {
@@ -178,7 +178,7 @@ func PostGraphiteAnnotation(c *m.Context, cmd dtos.PostGraphiteAnnotationsCmd) R
 	})
 	})
 }
 }
 
 
-func UpdateAnnotation(c *m.Context, cmd dtos.UpdateAnnotationsCmd) Response {
+func UpdateAnnotation(c *m.ReqContext, cmd dtos.UpdateAnnotationsCmd) Response {
 	annotationId := c.ParamsInt64(":annotationId")
 	annotationId := c.ParamsInt64(":annotationId")
 
 
 	repo := annotations.GetRepository()
 	repo := annotations.GetRepository()
@@ -217,7 +217,7 @@ func UpdateAnnotation(c *m.Context, cmd dtos.UpdateAnnotationsCmd) Response {
 	return ApiSuccess("Annotation updated")
 	return ApiSuccess("Annotation updated")
 }
 }
 
 
-func DeleteAnnotations(c *m.Context, cmd dtos.DeleteAnnotationsCmd) Response {
+func DeleteAnnotations(c *m.ReqContext, cmd dtos.DeleteAnnotationsCmd) Response {
 	repo := annotations.GetRepository()
 	repo := annotations.GetRepository()
 
 
 	err := repo.Delete(&annotations.DeleteParams{
 	err := repo.Delete(&annotations.DeleteParams{
@@ -233,7 +233,7 @@ func DeleteAnnotations(c *m.Context, cmd dtos.DeleteAnnotationsCmd) Response {
 	return ApiSuccess("Annotations deleted")
 	return ApiSuccess("Annotations deleted")
 }
 }
 
 
-func DeleteAnnotationById(c *m.Context) Response {
+func DeleteAnnotationById(c *m.ReqContext) Response {
 	repo := annotations.GetRepository()
 	repo := annotations.GetRepository()
 	annotationId := c.ParamsInt64(":annotationId")
 	annotationId := c.ParamsInt64(":annotationId")
 
 
@@ -252,7 +252,7 @@ func DeleteAnnotationById(c *m.Context) Response {
 	return ApiSuccess("Annotation deleted")
 	return ApiSuccess("Annotation deleted")
 }
 }
 
 
-func DeleteAnnotationRegion(c *m.Context) Response {
+func DeleteAnnotationRegion(c *m.ReqContext) Response {
 	repo := annotations.GetRepository()
 	repo := annotations.GetRepository()
 	regionId := c.ParamsInt64(":regionId")
 	regionId := c.ParamsInt64(":regionId")
 
 
@@ -271,7 +271,7 @@ func DeleteAnnotationRegion(c *m.Context) Response {
 	return ApiSuccess("Annotation region deleted")
 	return ApiSuccess("Annotation region deleted")
 }
 }
 
 
-func canSaveByDashboardId(c *m.Context, dashboardId int64) (bool, error) {
+func canSaveByDashboardId(c *m.ReqContext, dashboardId int64) (bool, error) {
 	if dashboardId == 0 && !c.SignedInUser.HasRole(m.ROLE_EDITOR) {
 	if dashboardId == 0 && !c.SignedInUser.HasRole(m.ROLE_EDITOR) {
 		return false, nil
 		return false, nil
 	}
 	}
@@ -286,7 +286,7 @@ func canSaveByDashboardId(c *m.Context, dashboardId int64) (bool, error) {
 	return true, nil
 	return true, nil
 }
 }
 
 
-func canSave(c *m.Context, repo annotations.Repository, annotationId int64) Response {
+func canSave(c *m.ReqContext, repo annotations.Repository, annotationId int64) Response {
 	items, err := repo.Find(&annotations.ItemQuery{AnnotationId: annotationId, OrgId: c.OrgId})
 	items, err := repo.Find(&annotations.ItemQuery{AnnotationId: annotationId, OrgId: c.OrgId})
 
 
 	if err != nil || len(items) == 0 {
 	if err != nil || len(items) == 0 {
@@ -302,7 +302,7 @@ func canSave(c *m.Context, repo annotations.Repository, annotationId int64) Resp
 	return nil
 	return nil
 }
 }
 
 
-func canSaveByRegionId(c *m.Context, repo annotations.Repository, regionId int64) Response {
+func canSaveByRegionId(c *m.ReqContext, repo annotations.Repository, regionId int64) Response {
 	items, err := repo.Find(&annotations.ItemQuery{RegionId: regionId, OrgId: c.OrgId})
 	items, err := repo.Find(&annotations.ItemQuery{RegionId: regionId, OrgId: c.OrgId})
 
 
 	if err != nil || len(items) == 0 {
 	if err != nil || len(items) == 0 {

+ 2 - 2
pkg/api/annotations_test.go

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

+ 3 - 3
pkg/api/apikey.go

@@ -7,7 +7,7 @@ import (
 	m "github.com/grafana/grafana/pkg/models"
 	m "github.com/grafana/grafana/pkg/models"
 )
 )
 
 
-func GetApiKeys(c *m.Context) Response {
+func GetApiKeys(c *m.ReqContext) Response {
 	query := m.GetApiKeysQuery{OrgId: c.OrgId}
 	query := m.GetApiKeysQuery{OrgId: c.OrgId}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
@@ -26,7 +26,7 @@ func GetApiKeys(c *m.Context) Response {
 	return Json(200, result)
 	return Json(200, result)
 }
 }
 
 
-func DeleteApiKey(c *m.Context) Response {
+func DeleteApiKey(c *m.ReqContext) Response {
 	id := c.ParamsInt64(":id")
 	id := c.ParamsInt64(":id")
 
 
 	cmd := &m.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId}
 	cmd := &m.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId}
@@ -39,7 +39,7 @@ func DeleteApiKey(c *m.Context) Response {
 	return ApiSuccess("API key deleted")
 	return ApiSuccess("API key deleted")
 }
 }
 
 
-func AddApiKey(c *m.Context, cmd m.AddApiKeyCommand) Response {
+func AddApiKey(c *m.ReqContext, cmd m.AddApiKeyCommand) Response {
 	if !cmd.Role.IsValid() {
 	if !cmd.Role.IsValid() {
 		return ApiError(400, "Invalid role specified", nil)
 		return ApiError(400, "Invalid role specified", nil)
 	}
 	}

+ 1 - 1
pkg/api/app_routes.go

@@ -56,7 +56,7 @@ func InitAppPluginRoutes(r *macaron.Macaron) {
 }
 }
 
 
 func AppPluginRoute(route *plugins.AppPluginRoute, appId string) macaron.Handler {
 func AppPluginRoute(route *plugins.AppPluginRoute, appId string) macaron.Handler {
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		path := c.Params("*")
 		path := c.Params("*")
 
 
 		proxy := pluginproxy.NewApiPluginProxy(c, path, route, appId)
 		proxy := pluginproxy.NewApiPluginProxy(c, path, route, appId)

+ 3 - 3
pkg/api/common.go

@@ -19,7 +19,7 @@ var (
 )
 )
 
 
 type Response interface {
 type Response interface {
-	WriteTo(ctx *m.Context)
+	WriteTo(ctx *m.ReqContext)
 }
 }
 
 
 type NormalResponse struct {
 type NormalResponse struct {
@@ -32,7 +32,7 @@ type NormalResponse struct {
 
 
 func wrap(action interface{}) macaron.Handler {
 func wrap(action interface{}) macaron.Handler {
 
 
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		var res Response
 		var res Response
 		val, err := c.Invoke(action)
 		val, err := c.Invoke(action)
 		if err == nil && val != nil && len(val) > 0 {
 		if err == nil && val != nil && len(val) > 0 {
@@ -45,7 +45,7 @@ func wrap(action interface{}) macaron.Handler {
 	}
 	}
 }
 }
 
 
-func (r *NormalResponse) WriteTo(ctx *m.Context) {
+func (r *NormalResponse) WriteTo(ctx *m.ReqContext) {
 	if r.err != nil {
 	if r.err != nil {
 		ctx.Logger.Error(r.errMessage, "error", r.err)
 		ctx.Logger.Error(r.errMessage, "error", r.err)
 	}
 	}

+ 3 - 3
pkg/api/common_test.go

@@ -23,7 +23,7 @@ func loggedInUserScenarioWithRole(desc string, method string, url string, routeP
 		defer bus.ClearBusHandlers()
 		defer bus.ClearBusHandlers()
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.UserId = TestUserID
 			sc.context.UserId = TestUserID
 			sc.context.OrgId = TestOrgID
 			sc.context.OrgId = TestOrgID
@@ -71,7 +71,7 @@ func (sc *scenarioContext) fakeReqWithParams(method, url string, queryParams map
 
 
 type scenarioContext struct {
 type scenarioContext struct {
 	m              *macaron.Macaron
 	m              *macaron.Macaron
-	context        *m.Context
+	context        *m.ReqContext
 	resp           *httptest.ResponseRecorder
 	resp           *httptest.ResponseRecorder
 	handlerFunc    handlerFunc
 	handlerFunc    handlerFunc
 	defaultHandler macaron.Handler
 	defaultHandler macaron.Handler
@@ -84,7 +84,7 @@ func (sc *scenarioContext) exec() {
 }
 }
 
 
 type scenarioFunc func(c *scenarioContext)
 type scenarioFunc func(c *scenarioContext)
-type handlerFunc func(c *m.Context) Response
+type handlerFunc func(c *m.ReqContext) Response
 
 
 func setupScenarioContext(url string) *scenarioContext {
 func setupScenarioContext(url string) *scenarioContext {
 	sc := &scenarioContext{
 	sc := &scenarioContext{

+ 11 - 11
pkg/api/dashboard.go

@@ -22,7 +22,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func isDashboardStarredByUser(c *m.Context, dashId int64) (bool, error) {
+func isDashboardStarredByUser(c *m.ReqContext, dashId int64) (bool, error) {
 	if !c.IsSignedIn {
 	if !c.IsSignedIn {
 		return false, nil
 		return false, nil
 	}
 	}
@@ -43,7 +43,7 @@ func dashboardGuardianResponse(err error) Response {
 	return ApiError(403, "Access denied to this dashboard", nil)
 	return ApiError(403, "Access denied to this dashboard", nil)
 }
 }
 
 
-func GetDashboard(c *m.Context) Response {
+func GetDashboard(c *m.ReqContext) Response {
 	dash, rsp := getDashboardHelper(c.OrgId, c.Params(":slug"), 0, c.Params(":uid"))
 	dash, rsp := getDashboardHelper(c.OrgId, c.Params(":slug"), 0, c.Params(":uid"))
 	if rsp != nil {
 	if rsp != nil {
 		return rsp
 		return rsp
@@ -141,7 +141,7 @@ func getDashboardHelper(orgId int64, slug string, id int64, uid string) (*m.Dash
 	return query.Result, nil
 	return query.Result, nil
 }
 }
 
 
-func DeleteDashboard(c *m.Context) Response {
+func DeleteDashboard(c *m.ReqContext) Response {
 	query := m.GetDashboardsBySlugQuery{OrgId: c.OrgId, Slug: c.Params(":slug")}
 	query := m.GetDashboardsBySlugQuery{OrgId: c.OrgId, Slug: c.Params(":slug")}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
@@ -173,7 +173,7 @@ func DeleteDashboard(c *m.Context) Response {
 	})
 	})
 }
 }
 
 
-func DeleteDashboardByUid(c *m.Context) Response {
+func DeleteDashboardByUid(c *m.ReqContext) Response {
 	dash, rsp := getDashboardHelper(c.OrgId, "", 0, c.Params(":uid"))
 	dash, rsp := getDashboardHelper(c.OrgId, "", 0, c.Params(":uid"))
 	if rsp != nil {
 	if rsp != nil {
 		return rsp
 		return rsp
@@ -195,7 +195,7 @@ func DeleteDashboardByUid(c *m.Context) Response {
 	})
 	})
 }
 }
 
 
-func PostDashboard(c *m.Context, cmd m.SaveDashboardCommand) Response {
+func PostDashboard(c *m.ReqContext, cmd m.SaveDashboardCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 	cmd.UserId = c.UserId
 	cmd.UserId = c.UserId
 
 
@@ -278,7 +278,7 @@ func PostDashboard(c *m.Context, cmd m.SaveDashboardCommand) Response {
 	})
 	})
 }
 }
 
 
-func GetHomeDashboard(c *m.Context) Response {
+func GetHomeDashboard(c *m.ReqContext) Response {
 	prefsQuery := m.GetPreferencesWithDefaultsQuery{OrgId: c.OrgId, UserId: c.UserId}
 	prefsQuery := m.GetPreferencesWithDefaultsQuery{OrgId: c.OrgId, UserId: c.UserId}
 	if err := bus.Dispatch(&prefsQuery); err != nil {
 	if err := bus.Dispatch(&prefsQuery); err != nil {
 		return ApiError(500, "Failed to get preferences", err)
 		return ApiError(500, "Failed to get preferences", err)
@@ -338,7 +338,7 @@ func addGettingStartedPanelToHomeDashboard(dash *simplejson.Json) {
 }
 }
 
 
 // GetDashboardVersions returns all dashboard versions as JSON
 // GetDashboardVersions returns all dashboard versions as JSON
-func GetDashboardVersions(c *m.Context) Response {
+func GetDashboardVersions(c *m.ReqContext) Response {
 	dashId := c.ParamsInt64(":dashboardId")
 	dashId := c.ParamsInt64(":dashboardId")
 
 
 	guardian := guardian.New(dashId, c.OrgId, c.SignedInUser)
 	guardian := guardian.New(dashId, c.OrgId, c.SignedInUser)
@@ -377,7 +377,7 @@ func GetDashboardVersions(c *m.Context) Response {
 }
 }
 
 
 // GetDashboardVersion returns the dashboard version with the given ID.
 // GetDashboardVersion returns the dashboard version with the given ID.
-func GetDashboardVersion(c *m.Context) Response {
+func GetDashboardVersion(c *m.ReqContext) Response {
 	dashId := c.ParamsInt64(":dashboardId")
 	dashId := c.ParamsInt64(":dashboardId")
 
 
 	guardian := guardian.New(dashId, c.OrgId, c.SignedInUser)
 	guardian := guardian.New(dashId, c.OrgId, c.SignedInUser)
@@ -409,7 +409,7 @@ func GetDashboardVersion(c *m.Context) Response {
 }
 }
 
 
 // POST /api/dashboards/calculate-diff performs diffs on two dashboards
 // POST /api/dashboards/calculate-diff performs diffs on two dashboards
-func CalculateDashboardDiff(c *m.Context, apiOptions dtos.CalculateDiffOptions) Response {
+func CalculateDashboardDiff(c *m.ReqContext, apiOptions dtos.CalculateDiffOptions) Response {
 
 
 	guardianBase := guardian.New(apiOptions.Base.DashboardId, c.OrgId, c.SignedInUser)
 	guardianBase := guardian.New(apiOptions.Base.DashboardId, c.OrgId, c.SignedInUser)
 	if canSave, err := guardianBase.CanSave(); err != nil || !canSave {
 	if canSave, err := guardianBase.CanSave(); err != nil || !canSave {
@@ -454,7 +454,7 @@ func CalculateDashboardDiff(c *m.Context, apiOptions dtos.CalculateDiffOptions)
 }
 }
 
 
 // RestoreDashboardVersion restores a dashboard to the given version.
 // RestoreDashboardVersion restores a dashboard to the given version.
-func RestoreDashboardVersion(c *m.Context, apiCmd dtos.RestoreDashboardVersionCommand) Response {
+func RestoreDashboardVersion(c *m.ReqContext, apiCmd dtos.RestoreDashboardVersionCommand) Response {
 	dash, rsp := getDashboardHelper(c.OrgId, "", c.ParamsInt64(":dashboardId"), "")
 	dash, rsp := getDashboardHelper(c.OrgId, "", c.ParamsInt64(":dashboardId"), "")
 	if rsp != nil {
 	if rsp != nil {
 		return rsp
 		return rsp
@@ -484,7 +484,7 @@ func RestoreDashboardVersion(c *m.Context, apiCmd dtos.RestoreDashboardVersionCo
 	return PostDashboard(c, saveCmd)
 	return PostDashboard(c, saveCmd)
 }
 }
 
 
-func GetDashboardTags(c *m.Context) {
+func GetDashboardTags(c *m.ReqContext) {
 	query := m.GetDashboardTagsQuery{OrgId: c.OrgId}
 	query := m.GetDashboardTagsQuery{OrgId: c.OrgId}
 	err := bus.Dispatch(&query)
 	err := bus.Dispatch(&query)
 	if err != nil {
 	if err != nil {

+ 2 - 2
pkg/api/dashboard_permission.go

@@ -9,7 +9,7 @@ import (
 	"github.com/grafana/grafana/pkg/services/guardian"
 	"github.com/grafana/grafana/pkg/services/guardian"
 )
 )
 
 
-func GetDashboardPermissionList(c *m.Context) Response {
+func GetDashboardPermissionList(c *m.ReqContext) Response {
 	dashId := c.ParamsInt64(":dashboardId")
 	dashId := c.ParamsInt64(":dashboardId")
 
 
 	_, rsp := getDashboardHelper(c.OrgId, "", dashId, "")
 	_, rsp := getDashboardHelper(c.OrgId, "", dashId, "")
@@ -37,7 +37,7 @@ func GetDashboardPermissionList(c *m.Context) Response {
 	return Json(200, acl)
 	return Json(200, acl)
 }
 }
 
 
-func UpdateDashboardPermissions(c *m.Context, apiCmd dtos.UpdateDashboardAclCommand) Response {
+func UpdateDashboardPermissions(c *m.ReqContext, apiCmd dtos.UpdateDashboardAclCommand) Response {
 	dashId := c.ParamsInt64(":dashboardId")
 	dashId := c.ParamsInt64(":dashboardId")
 
 
 	_, rsp := getDashboardHelper(c.OrgId, "", dashId, "")
 	_, rsp := getDashboardHelper(c.OrgId, "", dashId, "")

+ 1 - 1
pkg/api/dashboard_permission_test.go

@@ -194,7 +194,7 @@ func updateDashboardPermissionScenario(desc string, url string, routePattern str
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
 
 
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.OrgId = TestOrgID
 			sc.context.OrgId = TestOrgID
 			sc.context.UserId = TestUserID
 			sc.context.UserId = TestUserID

+ 5 - 5
pkg/api/dashboard_snapshot.go

@@ -12,7 +12,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func GetSharingOptions(c *m.Context) {
+func GetSharingOptions(c *m.ReqContext) {
 	c.JSON(200, util.DynMap{
 	c.JSON(200, util.DynMap{
 		"externalSnapshotURL":  setting.ExternalSnapshotUrl,
 		"externalSnapshotURL":  setting.ExternalSnapshotUrl,
 		"externalSnapshotName": setting.ExternalSnapshotName,
 		"externalSnapshotName": setting.ExternalSnapshotName,
@@ -20,7 +20,7 @@ func GetSharingOptions(c *m.Context) {
 	})
 	})
 }
 }
 
 
-func CreateDashboardSnapshot(c *m.Context, cmd m.CreateDashboardSnapshotCommand) {
+func CreateDashboardSnapshot(c *m.ReqContext, cmd m.CreateDashboardSnapshotCommand) {
 	if cmd.Name == "" {
 	if cmd.Name == "" {
 		cmd.Name = "Unnamed snapshot"
 		cmd.Name = "Unnamed snapshot"
 	}
 	}
@@ -57,7 +57,7 @@ func CreateDashboardSnapshot(c *m.Context, cmd m.CreateDashboardSnapshotCommand)
 }
 }
 
 
 // GET /api/snapshots/:key
 // GET /api/snapshots/:key
-func GetDashboardSnapshot(c *m.Context) {
+func GetDashboardSnapshot(c *m.ReqContext) {
 	key := c.Params(":key")
 	key := c.Params(":key")
 	query := &m.GetDashboardSnapshotQuery{Key: key}
 	query := &m.GetDashboardSnapshotQuery{Key: key}
 
 
@@ -92,7 +92,7 @@ func GetDashboardSnapshot(c *m.Context) {
 }
 }
 
 
 // GET /api/snapshots-delete/:key
 // GET /api/snapshots-delete/:key
-func DeleteDashboardSnapshot(c *m.Context) Response {
+func DeleteDashboardSnapshot(c *m.ReqContext) Response {
 	key := c.Params(":key")
 	key := c.Params(":key")
 
 
 	query := &m.GetDashboardSnapshotQuery{DeleteKey: key}
 	query := &m.GetDashboardSnapshotQuery{DeleteKey: key}
@@ -128,7 +128,7 @@ func DeleteDashboardSnapshot(c *m.Context) Response {
 }
 }
 
 
 // GET /api/dashboard/snapshots
 // GET /api/dashboard/snapshots
-func SearchDashboardSnapshots(c *m.Context) Response {
+func SearchDashboardSnapshots(c *m.ReqContext) Response {
 	query := c.Query("query")
 	query := c.Query("query")
 	limit := c.QueryInt("limit")
 	limit := c.QueryInt("limit")
 
 

+ 2 - 2
pkg/api/dashboard_test.go

@@ -861,7 +861,7 @@ func postDashboardScenario(desc string, url string, routePattern string, mock *d
 		defer bus.ClearBusHandlers()
 		defer bus.ClearBusHandlers()
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.SignedInUser = &m.SignedInUser{OrgId: cmd.OrgId, UserId: cmd.UserId}
 			sc.context.SignedInUser = &m.SignedInUser{OrgId: cmd.OrgId, UserId: cmd.UserId}
 
 
@@ -886,7 +886,7 @@ func postDiffScenario(desc string, url string, routePattern string, cmd dtos.Cal
 		defer bus.ClearBusHandlers()
 		defer bus.ClearBusHandlers()
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.SignedInUser = &m.SignedInUser{
 			sc.context.SignedInUser = &m.SignedInUser{
 				OrgId:  TestOrgID,
 				OrgId:  TestOrgID,

+ 1 - 1
pkg/api/dataproxy.go

@@ -34,7 +34,7 @@ func (hs *HttpServer) getDatasourceById(id int64, orgId int64, nocache bool) (*m
 	return query.Result, nil
 	return query.Result, nil
 }
 }
 
 
-func (hs *HttpServer) ProxyDataSourceRequest(c *m.Context) {
+func (hs *HttpServer) ProxyDataSourceRequest(c *m.ReqContext) {
 	c.TimeRequest(metrics.M_DataSource_ProxyReq_Timer)
 	c.TimeRequest(metrics.M_DataSource_ProxyReq_Timer)
 
 
 	nocache := c.Req.Header.Get(HeaderNameNoBackendCache) == "true"
 	nocache := c.Req.Header.Get(HeaderNameNoBackendCache) == "true"

+ 8 - 8
pkg/api/datasources.go

@@ -10,7 +10,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func GetDataSources(c *m.Context) Response {
+func GetDataSources(c *m.ReqContext) Response {
 	query := m.GetDataSourcesQuery{OrgId: c.OrgId}
 	query := m.GetDataSourcesQuery{OrgId: c.OrgId}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
@@ -49,7 +49,7 @@ func GetDataSources(c *m.Context) Response {
 	return Json(200, &result)
 	return Json(200, &result)
 }
 }
 
 
-func GetDataSourceById(c *m.Context) Response {
+func GetDataSourceById(c *m.ReqContext) Response {
 	query := m.GetDataSourceByIdQuery{
 	query := m.GetDataSourceByIdQuery{
 		Id:    c.ParamsInt64(":id"),
 		Id:    c.ParamsInt64(":id"),
 		OrgId: c.OrgId,
 		OrgId: c.OrgId,
@@ -68,7 +68,7 @@ func GetDataSourceById(c *m.Context) Response {
 	return Json(200, &dtos)
 	return Json(200, &dtos)
 }
 }
 
 
-func DeleteDataSourceById(c *m.Context) Response {
+func DeleteDataSourceById(c *m.ReqContext) Response {
 	id := c.ParamsInt64(":id")
 	id := c.ParamsInt64(":id")
 
 
 	if id <= 0 {
 	if id <= 0 {
@@ -94,7 +94,7 @@ func DeleteDataSourceById(c *m.Context) Response {
 	return ApiSuccess("Data source deleted")
 	return ApiSuccess("Data source deleted")
 }
 }
 
 
-func DeleteDataSourceByName(c *m.Context) Response {
+func DeleteDataSourceByName(c *m.ReqContext) Response {
 	name := c.Params(":name")
 	name := c.Params(":name")
 
 
 	if name == "" {
 	if name == "" {
@@ -119,7 +119,7 @@ func DeleteDataSourceByName(c *m.Context) Response {
 	return ApiSuccess("Data source deleted")
 	return ApiSuccess("Data source deleted")
 }
 }
 
 
-func AddDataSource(c *m.Context, cmd m.AddDataSourceCommand) Response {
+func AddDataSource(c *m.ReqContext, cmd m.AddDataSourceCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 
 
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {
@@ -139,7 +139,7 @@ func AddDataSource(c *m.Context, cmd m.AddDataSourceCommand) Response {
 	})
 	})
 }
 }
 
 
-func UpdateDataSource(c *m.Context, cmd m.UpdateDataSourceCommand) Response {
+func UpdateDataSource(c *m.ReqContext, cmd m.UpdateDataSourceCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 	cmd.Id = c.ParamsInt64(":id")
 	cmd.Id = c.ParamsInt64(":id")
 
 
@@ -204,7 +204,7 @@ func getRawDataSourceById(id int64, orgId int64) (*m.DataSource, error) {
 }
 }
 
 
 // Get /api/datasources/name/:name
 // Get /api/datasources/name/:name
-func GetDataSourceByName(c *m.Context) Response {
+func GetDataSourceByName(c *m.ReqContext) Response {
 	query := m.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
 	query := m.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
@@ -220,7 +220,7 @@ func GetDataSourceByName(c *m.Context) Response {
 }
 }
 
 
 // Get /api/datasources/id/:name
 // Get /api/datasources/id/:name
-func GetDataSourceIdByName(c *m.Context) Response {
+func GetDataSourceIdByName(c *m.ReqContext) Response {
 	query := m.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
 	query := m.GetDataSourceByNameQuery{Name: c.Params(":name"), OrgId: c.OrgId}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {

+ 6 - 6
pkg/api/folder.go

@@ -10,7 +10,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func GetFolders(c *m.Context) Response {
+func GetFolders(c *m.ReqContext) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	folders, err := s.GetFolders(c.QueryInt("limit"))
 	folders, err := s.GetFolders(c.QueryInt("limit"))
 
 
@@ -31,7 +31,7 @@ func GetFolders(c *m.Context) Response {
 	return Json(200, result)
 	return Json(200, result)
 }
 }
 
 
-func GetFolderByUid(c *m.Context) Response {
+func GetFolderByUid(c *m.ReqContext) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	folder, err := s.GetFolderByUid(c.Params(":uid"))
 	folder, err := s.GetFolderByUid(c.Params(":uid"))
 
 
@@ -43,7 +43,7 @@ func GetFolderByUid(c *m.Context) Response {
 	return Json(200, toFolderDto(g, folder))
 	return Json(200, toFolderDto(g, folder))
 }
 }
 
 
-func GetFolderById(c *m.Context) Response {
+func GetFolderById(c *m.ReqContext) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	folder, err := s.GetFolderById(c.ParamsInt64(":id"))
 	folder, err := s.GetFolderById(c.ParamsInt64(":id"))
 	if err != nil {
 	if err != nil {
@@ -54,7 +54,7 @@ func GetFolderById(c *m.Context) Response {
 	return Json(200, toFolderDto(g, folder))
 	return Json(200, toFolderDto(g, folder))
 }
 }
 
 
-func CreateFolder(c *m.Context, cmd m.CreateFolderCommand) Response {
+func CreateFolder(c *m.ReqContext, cmd m.CreateFolderCommand) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	err := s.CreateFolder(&cmd)
 	err := s.CreateFolder(&cmd)
 	if err != nil {
 	if err != nil {
@@ -65,7 +65,7 @@ func CreateFolder(c *m.Context, cmd m.CreateFolderCommand) Response {
 	return Json(200, toFolderDto(g, cmd.Result))
 	return Json(200, toFolderDto(g, cmd.Result))
 }
 }
 
 
-func UpdateFolder(c *m.Context, cmd m.UpdateFolderCommand) Response {
+func UpdateFolder(c *m.ReqContext, cmd m.UpdateFolderCommand) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	err := s.UpdateFolder(c.Params(":uid"), &cmd)
 	err := s.UpdateFolder(c.Params(":uid"), &cmd)
 	if err != nil {
 	if err != nil {
@@ -76,7 +76,7 @@ func UpdateFolder(c *m.Context, cmd m.UpdateFolderCommand) Response {
 	return Json(200, toFolderDto(g, cmd.Result))
 	return Json(200, toFolderDto(g, cmd.Result))
 }
 }
 
 
-func DeleteFolder(c *m.Context) Response {
+func DeleteFolder(c *m.ReqContext) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	f, err := s.DeleteFolder(c.Params(":uid"))
 	f, err := s.DeleteFolder(c.Params(":uid"))
 	if err != nil {
 	if err != nil {

+ 2 - 2
pkg/api/folder_permission.go

@@ -10,7 +10,7 @@ import (
 	"github.com/grafana/grafana/pkg/services/guardian"
 	"github.com/grafana/grafana/pkg/services/guardian"
 )
 )
 
 
-func GetFolderPermissionList(c *m.Context) Response {
+func GetFolderPermissionList(c *m.ReqContext) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	folder, err := s.GetFolderByUid(c.Params(":uid"))
 	folder, err := s.GetFolderByUid(c.Params(":uid"))
 
 
@@ -41,7 +41,7 @@ func GetFolderPermissionList(c *m.Context) Response {
 	return Json(200, acl)
 	return Json(200, acl)
 }
 }
 
 
-func UpdateFolderPermissions(c *m.Context, apiCmd dtos.UpdateDashboardAclCommand) Response {
+func UpdateFolderPermissions(c *m.ReqContext, apiCmd dtos.UpdateDashboardAclCommand) Response {
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
 	folder, err := s.GetFolderByUid(c.Params(":uid"))
 	folder, err := s.GetFolderByUid(c.Params(":uid"))
 
 

+ 1 - 1
pkg/api/folder_permission_test.go

@@ -226,7 +226,7 @@ func updateFolderPermissionScenario(desc string, url string, routePattern string
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
 
 
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.OrgId = TestOrgID
 			sc.context.OrgId = TestOrgID
 			sc.context.UserId = TestUserID
 			sc.context.UserId = TestUserID

+ 2 - 2
pkg/api/folder_test.go

@@ -152,7 +152,7 @@ func createFolderScenario(desc string, url string, routePattern string, mock *fa
 		defer bus.ClearBusHandlers()
 		defer bus.ClearBusHandlers()
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.SignedInUser = &m.SignedInUser{OrgId: TestOrgID, UserId: TestUserID}
 			sc.context.SignedInUser = &m.SignedInUser{OrgId: TestOrgID, UserId: TestUserID}
 
 
@@ -181,7 +181,7 @@ func updateFolderScenario(desc string, url string, routePattern string, mock *fa
 		defer bus.ClearBusHandlers()
 		defer bus.ClearBusHandlers()
 
 
 		sc := setupScenarioContext(url)
 		sc := setupScenarioContext(url)
-		sc.defaultHandler = wrap(func(c *m.Context) Response {
+		sc.defaultHandler = wrap(func(c *m.ReqContext) Response {
 			sc.context = c
 			sc.context = c
 			sc.context.SignedInUser = &m.SignedInUser{OrgId: TestOrgID, UserId: TestUserID}
 			sc.context.SignedInUser = &m.SignedInUser{OrgId: TestOrgID, UserId: TestUserID}
 
 

+ 2 - 2
pkg/api/frontendsettings.go

@@ -11,7 +11,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func getFrontendSettingsMap(c *m.Context) (map[string]interface{}, error) {
+func getFrontendSettingsMap(c *m.ReqContext) (map[string]interface{}, error) {
 	orgDataSources := make([]*m.DataSource, 0)
 	orgDataSources := make([]*m.DataSource, 0)
 
 
 	if c.OrgId != 0 {
 	if c.OrgId != 0 {
@@ -179,7 +179,7 @@ func getPanelSort(id string) int {
 	return sort
 	return sort
 }
 }
 
 
-func GetFrontendSettings(c *m.Context) {
+func GetFrontendSettings(c *m.ReqContext) {
 	settings, err := getFrontendSettingsMap(c)
 	settings, err := getFrontendSettingsMap(c)
 	if err != nil {
 	if err != nil {
 		c.JsonApiErr(400, "Failed to get frontend settings", err)
 		c.JsonApiErr(400, "Failed to get frontend settings", err)

+ 1 - 1
pkg/api/grafana_com_proxy.go

@@ -41,7 +41,7 @@ func ReverseProxyGnetReq(proxyPath string) *httputil.ReverseProxy {
 	return &httputil.ReverseProxy{Director: director}
 	return &httputil.ReverseProxy{Director: director}
 }
 }
 
 
-func ProxyGnetRequest(c *m.Context) {
+func ProxyGnetRequest(c *m.ReqContext) {
 	proxyPath := c.Params("*")
 	proxyPath := c.Params("*")
 	proxy := ReverseProxyGnetReq(proxyPath)
 	proxy := ReverseProxyGnetReq(proxyPath)
 	proxy.Transport = grafanaComProxyTransport
 	proxy.Transport = grafanaComProxyTransport

+ 3 - 3
pkg/api/index.go

@@ -11,7 +11,7 @@ import (
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
 
 
-func setIndexViewData(c *m.Context) (*dtos.IndexViewData, error) {
+func setIndexViewData(c *m.ReqContext) (*dtos.IndexViewData, error) {
 	settings, err := getFrontendSettingsMap(c)
 	settings, err := getFrontendSettingsMap(c)
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
@@ -298,7 +298,7 @@ func setIndexViewData(c *m.Context) (*dtos.IndexViewData, error) {
 	return &data, nil
 	return &data, nil
 }
 }
 
 
-func Index(c *m.Context) {
+func Index(c *m.ReqContext) {
 	if data, err := setIndexViewData(c); err != nil {
 	if data, err := setIndexViewData(c); err != nil {
 		c.Handle(500, "Failed to get settings", err)
 		c.Handle(500, "Failed to get settings", err)
 		return
 		return
@@ -307,7 +307,7 @@ func Index(c *m.Context) {
 	}
 	}
 }
 }
 
 
-func NotFoundHandler(c *m.Context) {
+func NotFoundHandler(c *m.ReqContext) {
 	if c.IsApiRequest() {
 	if c.IsApiRequest() {
 		c.JsonApiErr(404, "Not found", nil)
 		c.JsonApiErr(404, "Not found", nil)
 		return
 		return

+ 6 - 6
pkg/api/login.go

@@ -17,7 +17,7 @@ const (
 	VIEW_INDEX = "index"
 	VIEW_INDEX = "index"
 )
 )
 
 
-func LoginView(c *m.Context) {
+func LoginView(c *m.ReqContext) {
 	viewData, err := setIndexViewData(c)
 	viewData, err := setIndexViewData(c)
 	if err != nil {
 	if err != nil {
 		c.Handle(500, "Failed to get settings", err)
 		c.Handle(500, "Failed to get settings", err)
@@ -53,7 +53,7 @@ func LoginView(c *m.Context) {
 	c.Redirect(setting.AppSubUrl + "/")
 	c.Redirect(setting.AppSubUrl + "/")
 }
 }
 
 
-func tryLoginUsingRememberCookie(c *m.Context) bool {
+func tryLoginUsingRememberCookie(c *m.ReqContext) bool {
 	// Check auto-login.
 	// Check auto-login.
 	uname := c.GetCookie(setting.CookieUserName)
 	uname := c.GetCookie(setting.CookieUserName)
 	if len(uname) == 0 {
 	if len(uname) == 0 {
@@ -87,7 +87,7 @@ func tryLoginUsingRememberCookie(c *m.Context) bool {
 	return true
 	return true
 }
 }
 
 
-func LoginApiPing(c *m.Context) {
+func LoginApiPing(c *m.ReqContext) {
 	if !tryLoginUsingRememberCookie(c) {
 	if !tryLoginUsingRememberCookie(c) {
 		c.JsonApiErr(401, "Unauthorized", nil)
 		c.JsonApiErr(401, "Unauthorized", nil)
 		return
 		return
@@ -96,7 +96,7 @@ func LoginApiPing(c *m.Context) {
 	c.JsonOK("Logged in")
 	c.JsonOK("Logged in")
 }
 }
 
 
-func LoginPost(c *m.Context, cmd dtos.LoginCommand) Response {
+func LoginPost(c *m.ReqContext, cmd dtos.LoginCommand) Response {
 	if setting.DisableLoginForm {
 	if setting.DisableLoginForm {
 		return ApiError(401, "Login is disabled", nil)
 		return ApiError(401, "Login is disabled", nil)
 	}
 	}
@@ -133,7 +133,7 @@ func LoginPost(c *m.Context, cmd dtos.LoginCommand) Response {
 	return Json(200, result)
 	return Json(200, result)
 }
 }
 
 
-func loginUserWithUser(user *m.User, c *m.Context) {
+func loginUserWithUser(user *m.User, c *m.ReqContext) {
 	if user == nil {
 	if user == nil {
 		log.Error(3, "User login with nil user")
 		log.Error(3, "User login with nil user")
 	}
 	}
@@ -150,7 +150,7 @@ func loginUserWithUser(user *m.User, c *m.Context) {
 	c.Session.Set(session.SESS_KEY_USERID, user.Id)
 	c.Session.Set(session.SESS_KEY_USERID, user.Id)
 }
 }
 
 
-func Logout(c *m.Context) {
+func Logout(c *m.ReqContext) {
 	c.SetCookie(setting.CookieUserName, "", -1, setting.AppSubUrl+"/")
 	c.SetCookie(setting.CookieUserName, "", -1, setting.AppSubUrl+"/")
 	c.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubUrl+"/")
 	c.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubUrl+"/")
 	c.Session.Destory(c.Context)
 	c.Session.Destory(c.Context)

+ 2 - 2
pkg/api/login_oauth.go

@@ -39,7 +39,7 @@ func GenStateString() string {
 	return base64.URLEncoding.EncodeToString(rnd)
 	return base64.URLEncoding.EncodeToString(rnd)
 }
 }
 
 
-func OAuthLogin(ctx *m.Context) {
+func OAuthLogin(ctx *m.ReqContext) {
 	if setting.OAuthService == nil {
 	if setting.OAuthService == nil {
 		ctx.Handle(404, "OAuth not enabled", nil)
 		ctx.Handle(404, "OAuth not enabled", nil)
 		return
 		return
@@ -209,7 +209,7 @@ func OAuthLogin(ctx *m.Context) {
 	ctx.Redirect(setting.AppSubUrl + "/")
 	ctx.Redirect(setting.AppSubUrl + "/")
 }
 }
 
 
-func redirectWithError(ctx *m.Context, err error, v ...interface{}) {
+func redirectWithError(ctx *m.ReqContext, err error, v ...interface{}) {
 	ctx.Logger.Error(err.Error(), v...)
 	ctx.Logger.Error(err.Error(), v...)
 	ctx.Session.Set("loginError", err.Error())
 	ctx.Session.Set("loginError", err.Error())
 	ctx.Redirect(setting.AppSubUrl + "/login")
 	ctx.Redirect(setting.AppSubUrl + "/login")

+ 5 - 5
pkg/api/metrics.go

@@ -13,7 +13,7 @@ import (
 )
 )
 
 
 // POST /api/tsdb/query
 // POST /api/tsdb/query
-func QueryMetrics(c *m.Context, reqDto dtos.MetricRequest) Response {
+func QueryMetrics(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
 	timeRange := tsdb.NewTimeRange(reqDto.From, reqDto.To)
 	timeRange := tsdb.NewTimeRange(reqDto.From, reqDto.To)
 
 
 	if len(reqDto.Queries) == 0 {
 	if len(reqDto.Queries) == 0 {
@@ -60,7 +60,7 @@ func QueryMetrics(c *m.Context, reqDto dtos.MetricRequest) Response {
 }
 }
 
 
 // GET /api/tsdb/testdata/scenarios
 // GET /api/tsdb/testdata/scenarios
-func GetTestDataScenarios(c *m.Context) Response {
+func GetTestDataScenarios(c *m.ReqContext) Response {
 	result := make([]interface{}, 0)
 	result := make([]interface{}, 0)
 
 
 	for _, scenario := range testdata.ScenarioRegistry {
 	for _, scenario := range testdata.ScenarioRegistry {
@@ -76,13 +76,13 @@ func GetTestDataScenarios(c *m.Context) Response {
 }
 }
 
 
 // Genereates a index out of range error
 // Genereates a index out of range error
-func GenerateError(c *m.Context) Response {
+func GenerateError(c *m.ReqContext) Response {
 	var array []string
 	var array []string
 	return Json(200, array[20])
 	return Json(200, array[20])
 }
 }
 
 
 // GET /api/tsdb/testdata/gensql
 // GET /api/tsdb/testdata/gensql
-func GenerateSqlTestData(c *m.Context) Response {
+func GenerateSqlTestData(c *m.ReqContext) Response {
 	if err := bus.Dispatch(&m.InsertSqlTestDataCommand{}); err != nil {
 	if err := bus.Dispatch(&m.InsertSqlTestDataCommand{}); err != nil {
 		return ApiError(500, "Failed to insert test data", err)
 		return ApiError(500, "Failed to insert test data", err)
 	}
 	}
@@ -91,7 +91,7 @@ func GenerateSqlTestData(c *m.Context) Response {
 }
 }
 
 
 // GET /api/tsdb/testdata/random-walk
 // GET /api/tsdb/testdata/random-walk
-func GetTestDataRandomWalk(c *m.Context) Response {
+func GetTestDataRandomWalk(c *m.ReqContext) Response {
 	from := c.Query("from")
 	from := c.Query("from")
 	to := c.Query("to")
 	to := c.Query("to")
 	intervalMs := c.QueryInt64("intervalMs")
 	intervalMs := c.QueryInt64("intervalMs")

+ 10 - 10
pkg/api/org.go

@@ -10,17 +10,17 @@ import (
 )
 )
 
 
 // GET /api/org
 // GET /api/org
-func GetOrgCurrent(c *m.Context) Response {
+func GetOrgCurrent(c *m.ReqContext) Response {
 	return getOrgHelper(c.OrgId)
 	return getOrgHelper(c.OrgId)
 }
 }
 
 
 // GET /api/orgs/:orgId
 // GET /api/orgs/:orgId
-func GetOrgById(c *m.Context) Response {
+func GetOrgById(c *m.ReqContext) Response {
 	return getOrgHelper(c.ParamsInt64(":orgId"))
 	return getOrgHelper(c.ParamsInt64(":orgId"))
 }
 }
 
 
 // Get /api/orgs/name/:name
 // Get /api/orgs/name/:name
-func GetOrgByName(c *m.Context) Response {
+func GetOrgByName(c *m.ReqContext) Response {
 	query := m.GetOrgByNameQuery{Name: c.Params(":name")}
 	query := m.GetOrgByNameQuery{Name: c.Params(":name")}
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
 		if err == m.ErrOrgNotFound {
 		if err == m.ErrOrgNotFound {
@@ -75,7 +75,7 @@ func getOrgHelper(orgId int64) Response {
 }
 }
 
 
 // POST /api/orgs
 // POST /api/orgs
-func CreateOrg(c *m.Context, cmd m.CreateOrgCommand) Response {
+func CreateOrg(c *m.ReqContext, cmd m.CreateOrgCommand) Response {
 	if !c.IsSignedIn || (!setting.AllowUserOrgCreate && !c.IsGrafanaAdmin) {
 	if !c.IsSignedIn || (!setting.AllowUserOrgCreate && !c.IsGrafanaAdmin) {
 		return ApiError(403, "Access denied", nil)
 		return ApiError(403, "Access denied", nil)
 	}
 	}
@@ -97,12 +97,12 @@ func CreateOrg(c *m.Context, cmd m.CreateOrgCommand) Response {
 }
 }
 
 
 // PUT /api/org
 // PUT /api/org
-func UpdateOrgCurrent(c *m.Context, form dtos.UpdateOrgForm) Response {
+func UpdateOrgCurrent(c *m.ReqContext, form dtos.UpdateOrgForm) Response {
 	return updateOrgHelper(form, c.OrgId)
 	return updateOrgHelper(form, c.OrgId)
 }
 }
 
 
 // PUT /api/orgs/:orgId
 // PUT /api/orgs/:orgId
-func UpdateOrg(c *m.Context, form dtos.UpdateOrgForm) Response {
+func UpdateOrg(c *m.ReqContext, form dtos.UpdateOrgForm) Response {
 	return updateOrgHelper(form, c.ParamsInt64(":orgId"))
 	return updateOrgHelper(form, c.ParamsInt64(":orgId"))
 }
 }
 
 
@@ -119,12 +119,12 @@ func updateOrgHelper(form dtos.UpdateOrgForm, orgId int64) Response {
 }
 }
 
 
 // PUT /api/org/address
 // PUT /api/org/address
-func UpdateOrgAddressCurrent(c *m.Context, form dtos.UpdateOrgAddressForm) Response {
+func UpdateOrgAddressCurrent(c *m.ReqContext, form dtos.UpdateOrgAddressForm) Response {
 	return updateOrgAddressHelper(form, c.OrgId)
 	return updateOrgAddressHelper(form, c.OrgId)
 }
 }
 
 
 // PUT /api/orgs/:orgId/address
 // PUT /api/orgs/:orgId/address
-func UpdateOrgAddress(c *m.Context, form dtos.UpdateOrgAddressForm) Response {
+func UpdateOrgAddress(c *m.ReqContext, form dtos.UpdateOrgAddressForm) Response {
 	return updateOrgAddressHelper(form, c.ParamsInt64(":orgId"))
 	return updateOrgAddressHelper(form, c.ParamsInt64(":orgId"))
 }
 }
 
 
@@ -149,7 +149,7 @@ func updateOrgAddressHelper(form dtos.UpdateOrgAddressForm, orgId int64) Respons
 }
 }
 
 
 // GET /api/orgs/:orgId
 // GET /api/orgs/:orgId
-func DeleteOrgById(c *m.Context) Response {
+func DeleteOrgById(c *m.ReqContext) Response {
 	if err := bus.Dispatch(&m.DeleteOrgCommand{Id: c.ParamsInt64(":orgId")}); err != nil {
 	if err := bus.Dispatch(&m.DeleteOrgCommand{Id: c.ParamsInt64(":orgId")}); err != nil {
 		if err == m.ErrOrgNotFound {
 		if err == m.ErrOrgNotFound {
 			return ApiError(404, "Failed to delete organization. ID not found", nil)
 			return ApiError(404, "Failed to delete organization. ID not found", nil)
@@ -159,7 +159,7 @@ func DeleteOrgById(c *m.Context) Response {
 	return ApiSuccess("Organization deleted")
 	return ApiSuccess("Organization deleted")
 }
 }
 
 
-func SearchOrgs(c *m.Context) Response {
+func SearchOrgs(c *m.ReqContext) Response {
 	query := m.SearchOrgsQuery{
 	query := m.SearchOrgsQuery{
 		Query: c.Query("query"),
 		Query: c.Query("query"),
 		Name:  c.Query("name"),
 		Name:  c.Query("name"),

+ 6 - 6
pkg/api/org_invite.go

@@ -12,7 +12,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func GetPendingOrgInvites(c *m.Context) Response {
+func GetPendingOrgInvites(c *m.ReqContext) Response {
 	query := m.GetTempUsersQuery{OrgId: c.OrgId, Status: m.TmpUserInvitePending}
 	query := m.GetTempUsersQuery{OrgId: c.OrgId, Status: m.TmpUserInvitePending}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
@@ -26,7 +26,7 @@ func GetPendingOrgInvites(c *m.Context) Response {
 	return Json(200, query.Result)
 	return Json(200, query.Result)
 }
 }
 
 
-func AddOrgInvite(c *m.Context, inviteDto dtos.AddInviteForm) Response {
+func AddOrgInvite(c *m.ReqContext, inviteDto dtos.AddInviteForm) Response {
 	if !inviteDto.Role.IsValid() {
 	if !inviteDto.Role.IsValid() {
 		return ApiError(400, "Invalid role specified", nil)
 		return ApiError(400, "Invalid role specified", nil)
 	}
 	}
@@ -88,7 +88,7 @@ func AddOrgInvite(c *m.Context, inviteDto dtos.AddInviteForm) Response {
 	return ApiSuccess(fmt.Sprintf("Created invite for %s", inviteDto.LoginOrEmail))
 	return ApiSuccess(fmt.Sprintf("Created invite for %s", inviteDto.LoginOrEmail))
 }
 }
 
 
-func inviteExistingUserToOrg(c *m.Context, user *m.User, inviteDto *dtos.AddInviteForm) Response {
+func inviteExistingUserToOrg(c *m.ReqContext, user *m.User, inviteDto *dtos.AddInviteForm) Response {
 	// user exists, add org role
 	// user exists, add org role
 	createOrgUserCmd := m.AddOrgUserCommand{OrgId: c.OrgId, UserId: user.Id, Role: inviteDto.Role}
 	createOrgUserCmd := m.AddOrgUserCommand{OrgId: c.OrgId, UserId: user.Id, Role: inviteDto.Role}
 	if err := bus.Dispatch(&createOrgUserCmd); err != nil {
 	if err := bus.Dispatch(&createOrgUserCmd); err != nil {
@@ -118,7 +118,7 @@ func inviteExistingUserToOrg(c *m.Context, user *m.User, inviteDto *dtos.AddInvi
 	}
 	}
 }
 }
 
 
-func RevokeInvite(c *m.Context) Response {
+func RevokeInvite(c *m.ReqContext) Response {
 	if ok, rsp := updateTempUserStatus(c.Params(":code"), m.TmpUserRevoked); !ok {
 	if ok, rsp := updateTempUserStatus(c.Params(":code"), m.TmpUserRevoked); !ok {
 		return rsp
 		return rsp
 	}
 	}
@@ -126,7 +126,7 @@ func RevokeInvite(c *m.Context) Response {
 	return ApiSuccess("Invite revoked")
 	return ApiSuccess("Invite revoked")
 }
 }
 
 
-func GetInviteInfoByCode(c *m.Context) Response {
+func GetInviteInfoByCode(c *m.ReqContext) Response {
 	query := m.GetTempUserByCodeQuery{Code: c.Params(":code")}
 	query := m.GetTempUserByCodeQuery{Code: c.Params(":code")}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
@@ -146,7 +146,7 @@ func GetInviteInfoByCode(c *m.Context) Response {
 	})
 	})
 }
 }
 
 
-func CompleteInvite(c *m.Context, completeInvite dtos.CompleteInviteForm) Response {
+func CompleteInvite(c *m.ReqContext, completeInvite dtos.CompleteInviteForm) Response {
 	query := m.GetTempUserByCodeQuery{Code: completeInvite.InviteCode}
 	query := m.GetTempUserByCodeQuery{Code: completeInvite.InviteCode}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {

+ 8 - 8
pkg/api/org_users.go

@@ -7,13 +7,13 @@ import (
 )
 )
 
 
 // POST /api/org/users
 // POST /api/org/users
-func AddOrgUserToCurrentOrg(c *m.Context, cmd m.AddOrgUserCommand) Response {
+func AddOrgUserToCurrentOrg(c *m.ReqContext, cmd m.AddOrgUserCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 	return addOrgUserHelper(cmd)
 	return addOrgUserHelper(cmd)
 }
 }
 
 
 // POST /api/orgs/:orgId/users
 // POST /api/orgs/:orgId/users
-func AddOrgUser(c *m.Context, cmd m.AddOrgUserCommand) Response {
+func AddOrgUser(c *m.ReqContext, cmd m.AddOrgUserCommand) Response {
 	cmd.OrgId = c.ParamsInt64(":orgId")
 	cmd.OrgId = c.ParamsInt64(":orgId")
 	return addOrgUserHelper(cmd)
 	return addOrgUserHelper(cmd)
 }
 }
@@ -44,12 +44,12 @@ func addOrgUserHelper(cmd m.AddOrgUserCommand) Response {
 }
 }
 
 
 // GET /api/org/users
 // GET /api/org/users
-func GetOrgUsersForCurrentOrg(c *m.Context) Response {
+func GetOrgUsersForCurrentOrg(c *m.ReqContext) Response {
 	return getOrgUsersHelper(c.OrgId, c.Params("query"), c.ParamsInt("limit"))
 	return getOrgUsersHelper(c.OrgId, c.Params("query"), c.ParamsInt("limit"))
 }
 }
 
 
 // GET /api/orgs/:orgId/users
 // GET /api/orgs/:orgId/users
-func GetOrgUsers(c *m.Context) Response {
+func GetOrgUsers(c *m.ReqContext) Response {
 	return getOrgUsersHelper(c.ParamsInt64(":orgId"), "", 0)
 	return getOrgUsersHelper(c.ParamsInt64(":orgId"), "", 0)
 }
 }
 
 
@@ -72,14 +72,14 @@ func getOrgUsersHelper(orgId int64, query string, limit int) Response {
 }
 }
 
 
 // PATCH /api/org/users/:userId
 // PATCH /api/org/users/:userId
-func UpdateOrgUserForCurrentOrg(c *m.Context, cmd m.UpdateOrgUserCommand) Response {
+func UpdateOrgUserForCurrentOrg(c *m.ReqContext, cmd m.UpdateOrgUserCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 	cmd.UserId = c.ParamsInt64(":userId")
 	cmd.UserId = c.ParamsInt64(":userId")
 	return updateOrgUserHelper(cmd)
 	return updateOrgUserHelper(cmd)
 }
 }
 
 
 // PATCH /api/orgs/:orgId/users/:userId
 // PATCH /api/orgs/:orgId/users/:userId
-func UpdateOrgUser(c *m.Context, cmd m.UpdateOrgUserCommand) Response {
+func UpdateOrgUser(c *m.ReqContext, cmd m.UpdateOrgUserCommand) Response {
 	cmd.OrgId = c.ParamsInt64(":orgId")
 	cmd.OrgId = c.ParamsInt64(":orgId")
 	cmd.UserId = c.ParamsInt64(":userId")
 	cmd.UserId = c.ParamsInt64(":userId")
 	return updateOrgUserHelper(cmd)
 	return updateOrgUserHelper(cmd)
@@ -101,13 +101,13 @@ func updateOrgUserHelper(cmd m.UpdateOrgUserCommand) Response {
 }
 }
 
 
 // DELETE /api/org/users/:userId
 // DELETE /api/org/users/:userId
-func RemoveOrgUserForCurrentOrg(c *m.Context) Response {
+func RemoveOrgUserForCurrentOrg(c *m.ReqContext) Response {
 	userId := c.ParamsInt64(":userId")
 	userId := c.ParamsInt64(":userId")
 	return removeOrgUserHelper(c.OrgId, userId)
 	return removeOrgUserHelper(c.OrgId, userId)
 }
 }
 
 
 // DELETE /api/orgs/:orgId/users/:userId
 // DELETE /api/orgs/:orgId/users/:userId
-func RemoveOrgUser(c *m.Context) Response {
+func RemoveOrgUser(c *m.ReqContext) Response {
 	userId := c.ParamsInt64(":userId")
 	userId := c.ParamsInt64(":userId")
 	orgId := c.ParamsInt64(":orgId")
 	orgId := c.ParamsInt64(":orgId")
 	return removeOrgUserHelper(orgId, userId)
 	return removeOrgUserHelper(orgId, userId)

+ 2 - 2
pkg/api/password.go

@@ -7,7 +7,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func SendResetPasswordEmail(c *m.Context, form dtos.SendResetPasswordEmailForm) Response {
+func SendResetPasswordEmail(c *m.ReqContext, form dtos.SendResetPasswordEmailForm) Response {
 	userQuery := m.GetUserByLoginQuery{LoginOrEmail: form.UserOrEmail}
 	userQuery := m.GetUserByLoginQuery{LoginOrEmail: form.UserOrEmail}
 
 
 	if err := bus.Dispatch(&userQuery); err != nil {
 	if err := bus.Dispatch(&userQuery); err != nil {
@@ -23,7 +23,7 @@ func SendResetPasswordEmail(c *m.Context, form dtos.SendResetPasswordEmailForm)
 	return ApiSuccess("Email sent")
 	return ApiSuccess("Email sent")
 }
 }
 
 
-func ResetPassword(c *m.Context, form dtos.ResetUserPasswordForm) Response {
+func ResetPassword(c *m.ReqContext, form dtos.ResetUserPasswordForm) Response {
 	query := m.ValidateResetPasswordCodeQuery{Code: form.Code}
 	query := m.ValidateResetPasswordCodeQuery{Code: form.Code}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {

+ 8 - 8
pkg/api/playlist.go

@@ -6,7 +6,7 @@ import (
 	m "github.com/grafana/grafana/pkg/models"
 	m "github.com/grafana/grafana/pkg/models"
 )
 )
 
 
-func ValidateOrgPlaylist(c *m.Context) {
+func ValidateOrgPlaylist(c *m.ReqContext) {
 	id := c.ParamsInt64(":id")
 	id := c.ParamsInt64(":id")
 	query := m.GetPlaylistByIdQuery{Id: id}
 	query := m.GetPlaylistByIdQuery{Id: id}
 	err := bus.Dispatch(&query)
 	err := bus.Dispatch(&query)
@@ -39,7 +39,7 @@ func ValidateOrgPlaylist(c *m.Context) {
 	}
 	}
 }
 }
 
 
-func SearchPlaylists(c *m.Context) Response {
+func SearchPlaylists(c *m.ReqContext) Response {
 	query := c.Query("query")
 	query := c.Query("query")
 	limit := c.QueryInt("limit")
 	limit := c.QueryInt("limit")
 
 
@@ -61,7 +61,7 @@ func SearchPlaylists(c *m.Context) Response {
 	return Json(200, searchQuery.Result)
 	return Json(200, searchQuery.Result)
 }
 }
 
 
-func GetPlaylist(c *m.Context) Response {
+func GetPlaylist(c *m.ReqContext) Response {
 	id := c.ParamsInt64(":id")
 	id := c.ParamsInt64(":id")
 	cmd := m.GetPlaylistByIdQuery{Id: id}
 	cmd := m.GetPlaylistByIdQuery{Id: id}
 
 
@@ -114,7 +114,7 @@ func LoadPlaylistItems(id int64) ([]m.PlaylistItem, error) {
 	return *itemQuery.Result, nil
 	return *itemQuery.Result, nil
 }
 }
 
 
-func GetPlaylistItems(c *m.Context) Response {
+func GetPlaylistItems(c *m.ReqContext) Response {
 	id := c.ParamsInt64(":id")
 	id := c.ParamsInt64(":id")
 
 
 	playlistDTOs, err := LoadPlaylistItemDTOs(id)
 	playlistDTOs, err := LoadPlaylistItemDTOs(id)
@@ -126,7 +126,7 @@ func GetPlaylistItems(c *m.Context) Response {
 	return Json(200, playlistDTOs)
 	return Json(200, playlistDTOs)
 }
 }
 
 
-func GetPlaylistDashboards(c *m.Context) Response {
+func GetPlaylistDashboards(c *m.ReqContext) Response {
 	playlistId := c.ParamsInt64(":id")
 	playlistId := c.ParamsInt64(":id")
 
 
 	playlists, err := LoadPlaylistDashboards(c.OrgId, c.SignedInUser, playlistId)
 	playlists, err := LoadPlaylistDashboards(c.OrgId, c.SignedInUser, playlistId)
@@ -137,7 +137,7 @@ func GetPlaylistDashboards(c *m.Context) Response {
 	return Json(200, playlists)
 	return Json(200, playlists)
 }
 }
 
 
-func DeletePlaylist(c *m.Context) Response {
+func DeletePlaylist(c *m.ReqContext) Response {
 	id := c.ParamsInt64(":id")
 	id := c.ParamsInt64(":id")
 
 
 	cmd := m.DeletePlaylistCommand{Id: id, OrgId: c.OrgId}
 	cmd := m.DeletePlaylistCommand{Id: id, OrgId: c.OrgId}
@@ -148,7 +148,7 @@ func DeletePlaylist(c *m.Context) Response {
 	return Json(200, "")
 	return Json(200, "")
 }
 }
 
 
-func CreatePlaylist(c *m.Context, cmd m.CreatePlaylistCommand) Response {
+func CreatePlaylist(c *m.ReqContext, cmd m.CreatePlaylistCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 
 
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {
@@ -158,7 +158,7 @@ func CreatePlaylist(c *m.Context, cmd m.CreatePlaylistCommand) Response {
 	return Json(200, cmd.Result)
 	return Json(200, cmd.Result)
 }
 }
 
 
-func UpdatePlaylist(c *m.Context, cmd m.UpdatePlaylistCommand) Response {
+func UpdatePlaylist(c *m.ReqContext, cmd m.UpdatePlaylistCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 
 
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {

+ 3 - 3
pkg/api/pluginproxy/ds_proxy.go

@@ -41,14 +41,14 @@ type jwtToken struct {
 
 
 type DataSourceProxy struct {
 type DataSourceProxy struct {
 	ds        *m.DataSource
 	ds        *m.DataSource
-	ctx       *m.Context
+	ctx       *m.ReqContext
 	targetUrl *url.URL
 	targetUrl *url.URL
 	proxyPath string
 	proxyPath string
 	route     *plugins.AppPluginRoute
 	route     *plugins.AppPluginRoute
 	plugin    *plugins.DataSourcePlugin
 	plugin    *plugins.DataSourcePlugin
 }
 }
 
 
-func NewDataSourceProxy(ds *m.DataSource, plugin *plugins.DataSourcePlugin, ctx *m.Context, proxyPath string) *DataSourceProxy {
+func NewDataSourceProxy(ds *m.DataSource, plugin *plugins.DataSourcePlugin, ctx *m.ReqContext, proxyPath string) *DataSourceProxy {
 	targetUrl, _ := url.Parse(ds.Url)
 	targetUrl, _ := url.Parse(ds.Url)
 
 
 	return &DataSourceProxy{
 	return &DataSourceProxy{
@@ -254,7 +254,7 @@ func (proxy *DataSourceProxy) logRequest() {
 		"body", body)
 		"body", body)
 }
 }
 
 
-func checkWhiteList(c *m.Context, host string) bool {
+func checkWhiteList(c *m.ReqContext, host string) bool {
 	if host != "" && len(setting.DataProxyWhiteList) > 0 {
 	if host != "" && len(setting.DataProxyWhiteList) > 0 {
 		if _, exists := setting.DataProxyWhiteList[host]; !exists {
 		if _, exists := setting.DataProxyWhiteList[host]; !exists {
 			c.JsonApiErr(403, "Data proxy hostname and ip are not included in whitelist", nil)
 			c.JsonApiErr(403, "Data proxy hostname and ip are not included in whitelist", nil)

+ 5 - 5
pkg/api/pluginproxy/ds_proxy_test.go

@@ -60,7 +60,7 @@ func TestDSRouteRule(t *testing.T) {
 			}
 			}
 
 
 			req, _ := http.NewRequest("GET", "http://localhost/asd", nil)
 			req, _ := http.NewRequest("GET", "http://localhost/asd", nil)
-			ctx := &m.Context{
+			ctx := &m.ReqContext{
 				Context: &macaron.Context{
 				Context: &macaron.Context{
 					Req: macaron.Request{Request: req},
 					Req: macaron.Request{Request: req},
 				},
 				},
@@ -103,7 +103,7 @@ func TestDSRouteRule(t *testing.T) {
 		Convey("When proxying graphite", func() {
 		Convey("When proxying graphite", func() {
 			plugin := &plugins.DataSourcePlugin{}
 			plugin := &plugins.DataSourcePlugin{}
 			ds := &m.DataSource{Url: "htttp://graphite:8080", Type: m.DS_GRAPHITE}
 			ds := &m.DataSource{Url: "htttp://graphite:8080", Type: m.DS_GRAPHITE}
-			ctx := &m.Context{}
+			ctx := &m.ReqContext{}
 
 
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "/render")
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "/render")
 
 
@@ -129,7 +129,7 @@ func TestDSRouteRule(t *testing.T) {
 				Password: "password",
 				Password: "password",
 			}
 			}
 
 
-			ctx := &m.Context{}
+			ctx := &m.ReqContext{}
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "")
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "")
 
 
 			requestUrl, _ := url.Parse("http://grafana.com/sub")
 			requestUrl, _ := url.Parse("http://grafana.com/sub")
@@ -159,7 +159,7 @@ func TestDSRouteRule(t *testing.T) {
 				JsonData: json,
 				JsonData: json,
 			}
 			}
 
 
-			ctx := &m.Context{}
+			ctx := &m.ReqContext{}
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "")
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "")
 
 
 			requestUrl, _ := url.Parse("http://grafana.com/sub")
 			requestUrl, _ := url.Parse("http://grafana.com/sub")
@@ -185,7 +185,7 @@ func TestDSRouteRule(t *testing.T) {
 				JsonData: json,
 				JsonData: json,
 			}
 			}
 
 
-			ctx := &m.Context{}
+			ctx := &m.ReqContext{}
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "")
 			proxy := NewDataSourceProxy(ds, plugin, ctx, "")
 
 
 			requestUrl, _ := url.Parse("http://grafana.com/sub")
 			requestUrl, _ := url.Parse("http://grafana.com/sub")

+ 1 - 1
pkg/api/pluginproxy/pluginproxy.go

@@ -37,7 +37,7 @@ func getHeaders(route *plugins.AppPluginRoute, orgId int64, appId string) (http.
 	return result, err
 	return result, err
 }
 }
 
 
-func NewApiPluginProxy(ctx *m.Context, proxyPath string, route *plugins.AppPluginRoute, appId string) *httputil.ReverseProxy {
+func NewApiPluginProxy(ctx *m.ReqContext, proxyPath string, route *plugins.AppPluginRoute, appId string) *httputil.ReverseProxy {
 	targetUrl, _ := url.Parse(route.Url)
 	targetUrl, _ := url.Parse(route.Url)
 
 
 	director := func(req *http.Request) {
 	director := func(req *http.Request) {

+ 6 - 6
pkg/api/plugins.go

@@ -10,7 +10,7 @@ import (
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
 
 
-func GetPluginList(c *m.Context) Response {
+func GetPluginList(c *m.ReqContext) Response {
 	typeFilter := c.Query("type")
 	typeFilter := c.Query("type")
 	enabledFilter := c.Query("enabled")
 	enabledFilter := c.Query("enabled")
 	embeddedFilter := c.Query("embedded")
 	embeddedFilter := c.Query("embedded")
@@ -78,7 +78,7 @@ func GetPluginList(c *m.Context) Response {
 	return Json(200, result)
 	return Json(200, result)
 }
 }
 
 
-func GetPluginSettingById(c *m.Context) Response {
+func GetPluginSettingById(c *m.ReqContext) Response {
 	pluginId := c.Params(":pluginId")
 	pluginId := c.Params(":pluginId")
 
 
 	if def, exists := plugins.Plugins[pluginId]; !exists {
 	if def, exists := plugins.Plugins[pluginId]; !exists {
@@ -115,7 +115,7 @@ func GetPluginSettingById(c *m.Context) Response {
 	}
 	}
 }
 }
 
 
-func UpdatePluginSetting(c *m.Context, cmd m.UpdatePluginSettingCmd) Response {
+func UpdatePluginSetting(c *m.ReqContext, cmd m.UpdatePluginSettingCmd) Response {
 	pluginId := c.Params(":pluginId")
 	pluginId := c.Params(":pluginId")
 
 
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
@@ -132,7 +132,7 @@ func UpdatePluginSetting(c *m.Context, cmd m.UpdatePluginSettingCmd) Response {
 	return ApiSuccess("Plugin settings updated")
 	return ApiSuccess("Plugin settings updated")
 }
 }
 
 
-func GetPluginDashboards(c *m.Context) Response {
+func GetPluginDashboards(c *m.ReqContext) Response {
 	pluginId := c.Params(":pluginId")
 	pluginId := c.Params(":pluginId")
 
 
 	if list, err := plugins.GetPluginDashboards(c.OrgId, pluginId); err != nil {
 	if list, err := plugins.GetPluginDashboards(c.OrgId, pluginId); err != nil {
@@ -146,7 +146,7 @@ func GetPluginDashboards(c *m.Context) Response {
 	}
 	}
 }
 }
 
 
-func GetPluginMarkdown(c *m.Context) Response {
+func GetPluginMarkdown(c *m.ReqContext) Response {
 	pluginId := c.Params(":pluginId")
 	pluginId := c.Params(":pluginId")
 	name := c.Params(":name")
 	name := c.Params(":name")
 
 
@@ -163,7 +163,7 @@ func GetPluginMarkdown(c *m.Context) Response {
 	}
 	}
 }
 }
 
 
-func ImportDashboard(c *m.Context, apiCmd dtos.ImportDashboardCommand) Response {
+func ImportDashboard(c *m.ReqContext, apiCmd dtos.ImportDashboardCommand) Response {
 
 
 	cmd := plugins.ImportDashboardCommand{
 	cmd := plugins.ImportDashboardCommand{
 		OrgId:     c.OrgId,
 		OrgId:     c.OrgId,

+ 5 - 5
pkg/api/preferences.go

@@ -7,7 +7,7 @@ import (
 )
 )
 
 
 // POST /api/preferences/set-home-dash
 // POST /api/preferences/set-home-dash
-func SetHomeDashboard(c *m.Context, cmd m.SavePreferencesCommand) Response {
+func SetHomeDashboard(c *m.ReqContext, cmd m.SavePreferencesCommand) Response {
 
 
 	cmd.UserId = c.UserId
 	cmd.UserId = c.UserId
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
@@ -20,7 +20,7 @@ func SetHomeDashboard(c *m.Context, cmd m.SavePreferencesCommand) Response {
 }
 }
 
 
 // GET /api/user/preferences
 // GET /api/user/preferences
-func GetUserPreferences(c *m.Context) Response {
+func GetUserPreferences(c *m.ReqContext) Response {
 	return getPreferencesFor(c.OrgId, c.UserId)
 	return getPreferencesFor(c.OrgId, c.UserId)
 }
 }
 
 
@@ -41,7 +41,7 @@ func getPreferencesFor(orgId int64, userId int64) Response {
 }
 }
 
 
 // PUT /api/user/preferences
 // PUT /api/user/preferences
-func UpdateUserPreferences(c *m.Context, dtoCmd dtos.UpdatePrefsCmd) Response {
+func UpdateUserPreferences(c *m.ReqContext, dtoCmd dtos.UpdatePrefsCmd) Response {
 	return updatePreferencesFor(c.OrgId, c.UserId, &dtoCmd)
 	return updatePreferencesFor(c.OrgId, c.UserId, &dtoCmd)
 }
 }
 
 
@@ -62,11 +62,11 @@ func updatePreferencesFor(orgId int64, userId int64, dtoCmd *dtos.UpdatePrefsCmd
 }
 }
 
 
 // GET /api/org/preferences
 // GET /api/org/preferences
-func GetOrgPreferences(c *m.Context) Response {
+func GetOrgPreferences(c *m.ReqContext) Response {
 	return getPreferencesFor(c.OrgId, 0)
 	return getPreferencesFor(c.OrgId, 0)
 }
 }
 
 
 // PUT /api/org/preferences
 // PUT /api/org/preferences
-func UpdateOrgPreferences(c *m.Context, dtoCmd dtos.UpdatePrefsCmd) Response {
+func UpdateOrgPreferences(c *m.ReqContext, dtoCmd dtos.UpdatePrefsCmd) Response {
 	return updatePreferencesFor(c.OrgId, 0, &dtoCmd)
 	return updatePreferencesFor(c.OrgId, 0, &dtoCmd)
 }
 }

+ 4 - 4
pkg/api/quota.go

@@ -6,7 +6,7 @@ import (
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
 
 
-func GetOrgQuotas(c *m.Context) Response {
+func GetOrgQuotas(c *m.ReqContext) Response {
 	if !setting.Quota.Enabled {
 	if !setting.Quota.Enabled {
 		return ApiError(404, "Quotas not enabled", nil)
 		return ApiError(404, "Quotas not enabled", nil)
 	}
 	}
@@ -19,7 +19,7 @@ func GetOrgQuotas(c *m.Context) Response {
 	return Json(200, query.Result)
 	return Json(200, query.Result)
 }
 }
 
 
-func UpdateOrgQuota(c *m.Context, cmd m.UpdateOrgQuotaCmd) Response {
+func UpdateOrgQuota(c *m.ReqContext, cmd m.UpdateOrgQuotaCmd) Response {
 	if !setting.Quota.Enabled {
 	if !setting.Quota.Enabled {
 		return ApiError(404, "Quotas not enabled", nil)
 		return ApiError(404, "Quotas not enabled", nil)
 	}
 	}
@@ -36,7 +36,7 @@ func UpdateOrgQuota(c *m.Context, cmd m.UpdateOrgQuotaCmd) Response {
 	return ApiSuccess("Organization quota updated")
 	return ApiSuccess("Organization quota updated")
 }
 }
 
 
-func GetUserQuotas(c *m.Context) Response {
+func GetUserQuotas(c *m.ReqContext) Response {
 	if !setting.Quota.Enabled {
 	if !setting.Quota.Enabled {
 		return ApiError(404, "Quotas not enabled", nil)
 		return ApiError(404, "Quotas not enabled", nil)
 	}
 	}
@@ -49,7 +49,7 @@ func GetUserQuotas(c *m.Context) Response {
 	return Json(200, query.Result)
 	return Json(200, query.Result)
 }
 }
 
 
-func UpdateUserQuota(c *m.Context, cmd m.UpdateUserQuotaCmd) Response {
+func UpdateUserQuota(c *m.ReqContext, cmd m.UpdateUserQuotaCmd) Response {
 	if !setting.Quota.Enabled {
 	if !setting.Quota.Enabled {
 		return ApiError(404, "Quotas not enabled", nil)
 		return ApiError(404, "Quotas not enabled", nil)
 	}
 	}

+ 1 - 1
pkg/api/render.go

@@ -9,7 +9,7 @@ import (
 	"github.com/grafana/grafana/pkg/util"
 	"github.com/grafana/grafana/pkg/util"
 )
 )
 
 
-func RenderToPng(c *m.Context) {
+func RenderToPng(c *m.ReqContext) {
 	queryReader, err := util.NewUrlQueryReader(c.Req.URL)
 	queryReader, err := util.NewUrlQueryReader(c.Req.URL)
 	if err != nil {
 	if err != nil {
 		c.Handle(400, "Render parameters error", err)
 		c.Handle(400, "Render parameters error", err)

+ 1 - 1
pkg/api/search.go

@@ -9,7 +9,7 @@ import (
 	"github.com/grafana/grafana/pkg/services/search"
 	"github.com/grafana/grafana/pkg/services/search"
 )
 )
 
 
-func Search(c *m.Context) {
+func Search(c *m.ReqContext) {
 	query := c.Query("query")
 	query := c.Query("query")
 	tags := c.QueryStrings("tag")
 	tags := c.QueryStrings("tag")
 	starred := c.Query("starred")
 	starred := c.Query("starred")

+ 3 - 3
pkg/api/signup.go

@@ -11,7 +11,7 @@ import (
 )
 )
 
 
 // GET /api/user/signup/options
 // GET /api/user/signup/options
-func GetSignUpOptions(c *m.Context) Response {
+func GetSignUpOptions(c *m.ReqContext) Response {
 	return Json(200, util.DynMap{
 	return Json(200, util.DynMap{
 		"verifyEmailEnabled": setting.VerifyEmailEnabled,
 		"verifyEmailEnabled": setting.VerifyEmailEnabled,
 		"autoAssignOrg":      setting.AutoAssignOrg,
 		"autoAssignOrg":      setting.AutoAssignOrg,
@@ -19,7 +19,7 @@ func GetSignUpOptions(c *m.Context) Response {
 }
 }
 
 
 // POST /api/user/signup
 // POST /api/user/signup
-func SignUp(c *m.Context, form dtos.SignUpForm) Response {
+func SignUp(c *m.ReqContext, form dtos.SignUpForm) Response {
 	if !setting.AllowUserSignUp {
 	if !setting.AllowUserSignUp {
 		return ApiError(401, "User signup is disabled", nil)
 		return ApiError(401, "User signup is disabled", nil)
 	}
 	}
@@ -51,7 +51,7 @@ func SignUp(c *m.Context, form dtos.SignUpForm) Response {
 	return Json(200, util.DynMap{"status": "SignUpCreated"})
 	return Json(200, util.DynMap{"status": "SignUpCreated"})
 }
 }
 
 
-func SignUpStep2(c *m.Context, form dtos.SignUpStep2Form) Response {
+func SignUpStep2(c *m.ReqContext, form dtos.SignUpStep2Form) Response {
 	if !setting.AllowUserSignUp {
 	if !setting.AllowUserSignUp {
 		return ApiError(401, "User signup is disabled", nil)
 		return ApiError(401, "User signup is disabled", nil)
 	}
 	}

+ 2 - 2
pkg/api/stars.go

@@ -5,7 +5,7 @@ import (
 	m "github.com/grafana/grafana/pkg/models"
 	m "github.com/grafana/grafana/pkg/models"
 )
 )
 
 
-func StarDashboard(c *m.Context) Response {
+func StarDashboard(c *m.ReqContext) Response {
 	if !c.IsSignedIn {
 	if !c.IsSignedIn {
 		return ApiError(412, "You need to sign in to star dashboards", nil)
 		return ApiError(412, "You need to sign in to star dashboards", nil)
 	}
 	}
@@ -23,7 +23,7 @@ func StarDashboard(c *m.Context) Response {
 	return ApiSuccess("Dashboard starred!")
 	return ApiSuccess("Dashboard starred!")
 }
 }
 
 
-func UnstarDashboard(c *m.Context) Response {
+func UnstarDashboard(c *m.ReqContext) Response {
 
 
 	cmd := m.UnstarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
 	cmd := m.UnstarDashboardCommand{UserId: c.UserId, DashboardId: c.ParamsInt64(":id")}
 
 

+ 5 - 5
pkg/api/team.go

@@ -8,7 +8,7 @@ import (
 )
 )
 
 
 // POST /api/teams
 // POST /api/teams
-func CreateTeam(c *m.Context, cmd m.CreateTeamCommand) Response {
+func CreateTeam(c *m.ReqContext, cmd m.CreateTeamCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {
 		if err == m.ErrTeamNameTaken {
 		if err == m.ErrTeamNameTaken {
@@ -24,7 +24,7 @@ func CreateTeam(c *m.Context, cmd m.CreateTeamCommand) Response {
 }
 }
 
 
 // PUT /api/teams/:teamId
 // PUT /api/teams/:teamId
-func UpdateTeam(c *m.Context, cmd m.UpdateTeamCommand) Response {
+func UpdateTeam(c *m.ReqContext, cmd m.UpdateTeamCommand) Response {
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 	cmd.Id = c.ParamsInt64(":teamId")
 	cmd.Id = c.ParamsInt64(":teamId")
 	if err := bus.Dispatch(&cmd); err != nil {
 	if err := bus.Dispatch(&cmd); err != nil {
@@ -38,7 +38,7 @@ func UpdateTeam(c *m.Context, cmd m.UpdateTeamCommand) Response {
 }
 }
 
 
 // DELETE /api/teams/:teamId
 // DELETE /api/teams/:teamId
-func DeleteTeamById(c *m.Context) Response {
+func DeleteTeamById(c *m.ReqContext) Response {
 	if err := bus.Dispatch(&m.DeleteTeamCommand{OrgId: c.OrgId, Id: c.ParamsInt64(":teamId")}); err != nil {
 	if err := bus.Dispatch(&m.DeleteTeamCommand{OrgId: c.OrgId, Id: c.ParamsInt64(":teamId")}); err != nil {
 		if err == m.ErrTeamNotFound {
 		if err == m.ErrTeamNotFound {
 			return ApiError(404, "Failed to delete Team. ID not found", nil)
 			return ApiError(404, "Failed to delete Team. ID not found", nil)
@@ -49,7 +49,7 @@ func DeleteTeamById(c *m.Context) Response {
 }
 }
 
 
 // GET /api/teams/search
 // GET /api/teams/search
-func SearchTeams(c *m.Context) Response {
+func SearchTeams(c *m.ReqContext) Response {
 	perPage := c.QueryInt("perpage")
 	perPage := c.QueryInt("perpage")
 	if perPage <= 0 {
 	if perPage <= 0 {
 		perPage = 1000
 		perPage = 1000
@@ -82,7 +82,7 @@ func SearchTeams(c *m.Context) Response {
 }
 }
 
 
 // GET /api/teams/:teamId
 // GET /api/teams/:teamId
-func GetTeamById(c *m.Context) Response {
+func GetTeamById(c *m.ReqContext) Response {
 	query := m.GetTeamByIdQuery{OrgId: c.OrgId, Id: c.ParamsInt64(":teamId")}
 	query := m.GetTeamByIdQuery{OrgId: c.OrgId, Id: c.ParamsInt64(":teamId")}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {

+ 3 - 3
pkg/api/team_members.go

@@ -8,7 +8,7 @@ import (
 )
 )
 
 
 // GET /api/teams/:teamId/members
 // GET /api/teams/:teamId/members
-func GetTeamMembers(c *m.Context) Response {
+func GetTeamMembers(c *m.ReqContext) Response {
 	query := m.GetTeamMembersQuery{OrgId: c.OrgId, TeamId: c.ParamsInt64(":teamId")}
 	query := m.GetTeamMembersQuery{OrgId: c.OrgId, TeamId: c.ParamsInt64(":teamId")}
 
 
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
@@ -23,7 +23,7 @@ func GetTeamMembers(c *m.Context) Response {
 }
 }
 
 
 // POST /api/teams/:teamId/members
 // POST /api/teams/:teamId/members
-func AddTeamMember(c *m.Context, cmd m.AddTeamMemberCommand) Response {
+func AddTeamMember(c *m.ReqContext, cmd m.AddTeamMemberCommand) Response {
 	cmd.TeamId = c.ParamsInt64(":teamId")
 	cmd.TeamId = c.ParamsInt64(":teamId")
 	cmd.OrgId = c.OrgId
 	cmd.OrgId = c.OrgId
 
 
@@ -45,7 +45,7 @@ func AddTeamMember(c *m.Context, cmd m.AddTeamMemberCommand) Response {
 }
 }
 
 
 // DELETE /api/teams/:teamId/members/:userId
 // DELETE /api/teams/:teamId/members/:userId
-func RemoveTeamMember(c *m.Context) Response {
+func RemoveTeamMember(c *m.ReqContext) Response {
 	if err := bus.Dispatch(&m.RemoveTeamMemberCommand{OrgId: c.OrgId, TeamId: c.ParamsInt64(":teamId"), UserId: c.ParamsInt64(":userId")}); err != nil {
 	if err := bus.Dispatch(&m.RemoveTeamMemberCommand{OrgId: c.OrgId, TeamId: c.ParamsInt64(":teamId"), UserId: c.ParamsInt64(":userId")}); err != nil {
 		if err == m.ErrTeamNotFound {
 		if err == m.ErrTeamNotFound {
 			return ApiError(404, "Team not found", nil)
 			return ApiError(404, "Team not found", nil)

+ 16 - 16
pkg/api/user.go

@@ -9,12 +9,12 @@ import (
 )
 )
 
 
 // GET /api/user  (current authenticated user)
 // GET /api/user  (current authenticated user)
-func GetSignedInUser(c *m.Context) Response {
+func GetSignedInUser(c *m.ReqContext) Response {
 	return getUserUserProfile(c.UserId)
 	return getUserUserProfile(c.UserId)
 }
 }
 
 
 // GET /api/users/:id
 // GET /api/users/:id
-func GetUserById(c *m.Context) Response {
+func GetUserById(c *m.ReqContext) Response {
 	return getUserUserProfile(c.ParamsInt64(":id"))
 	return getUserUserProfile(c.ParamsInt64(":id"))
 }
 }
 
 
@@ -32,7 +32,7 @@ func getUserUserProfile(userId int64) Response {
 }
 }
 
 
 // GET /api/users/lookup
 // GET /api/users/lookup
-func GetUserByLoginOrEmail(c *m.Context) Response {
+func GetUserByLoginOrEmail(c *m.ReqContext) Response {
 	query := m.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")}
 	query := m.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")}
 	if err := bus.Dispatch(&query); err != nil {
 	if err := bus.Dispatch(&query); err != nil {
 		if err == m.ErrUserNotFound {
 		if err == m.ErrUserNotFound {
@@ -54,7 +54,7 @@ func GetUserByLoginOrEmail(c *m.Context) Response {
 }
 }
 
 
 // POST /api/user
 // POST /api/user
-func UpdateSignedInUser(c *m.Context, cmd m.UpdateUserCommand) Response {
+func UpdateSignedInUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
 	if setting.AuthProxyEnabled {
 	if setting.AuthProxyEnabled {
 		if setting.AuthProxyHeaderProperty == "email" && cmd.Email != c.Email {
 		if setting.AuthProxyHeaderProperty == "email" && cmd.Email != c.Email {
 			return ApiError(400, "Not allowed to change email when auth proxy is using email property", nil)
 			return ApiError(400, "Not allowed to change email when auth proxy is using email property", nil)
@@ -68,13 +68,13 @@ func UpdateSignedInUser(c *m.Context, cmd m.UpdateUserCommand) Response {
 }
 }
 
 
 // POST /api/users/:id
 // POST /api/users/:id
-func UpdateUser(c *m.Context, cmd m.UpdateUserCommand) Response {
+func UpdateUser(c *m.ReqContext, cmd m.UpdateUserCommand) Response {
 	cmd.UserId = c.ParamsInt64(":id")
 	cmd.UserId = c.ParamsInt64(":id")
 	return handleUpdateUser(cmd)
 	return handleUpdateUser(cmd)
 }
 }
 
 
 //POST /api/users/:id/using/:orgId
 //POST /api/users/:id/using/:orgId
-func UpdateUserActiveOrg(c *m.Context) Response {
+func UpdateUserActiveOrg(c *m.ReqContext) Response {
 	userId := c.ParamsInt64(":id")
 	userId := c.ParamsInt64(":id")
 	orgId := c.ParamsInt64(":orgId")
 	orgId := c.ParamsInt64(":orgId")
 
 
@@ -107,12 +107,12 @@ func handleUpdateUser(cmd m.UpdateUserCommand) Response {
 }
 }
 
 
 // GET /api/user/orgs
 // GET /api/user/orgs
-func GetSignedInUserOrgList(c *m.Context) Response {
+func GetSignedInUserOrgList(c *m.ReqContext) Response {
 	return getUserOrgList(c.UserId)
 	return getUserOrgList(c.UserId)
 }
 }
 
 
 // GET /api/user/:id/orgs
 // GET /api/user/:id/orgs
-func GetUserOrgList(c *m.Context) Response {
+func GetUserOrgList(c *m.ReqContext) Response {
 	return getUserOrgList(c.ParamsInt64(":id"))
 	return getUserOrgList(c.ParamsInt64(":id"))
 }
 }
 
 
@@ -145,7 +145,7 @@ func validateUsingOrg(userId int64, orgId int64) bool {
 }
 }
 
 
 // POST /api/user/using/:id
 // POST /api/user/using/:id
-func UserSetUsingOrg(c *m.Context) Response {
+func UserSetUsingOrg(c *m.ReqContext) Response {
 	orgId := c.ParamsInt64(":id")
 	orgId := c.ParamsInt64(":id")
 
 
 	if !validateUsingOrg(c.UserId, orgId) {
 	if !validateUsingOrg(c.UserId, orgId) {
@@ -162,7 +162,7 @@ func UserSetUsingOrg(c *m.Context) Response {
 }
 }
 
 
 // GET /profile/switch-org/:id
 // GET /profile/switch-org/:id
-func ChangeActiveOrgAndRedirectToHome(c *m.Context) {
+func ChangeActiveOrgAndRedirectToHome(c *m.ReqContext) {
 	orgId := c.ParamsInt64(":id")
 	orgId := c.ParamsInt64(":id")
 
 
 	if !validateUsingOrg(c.UserId, orgId) {
 	if !validateUsingOrg(c.UserId, orgId) {
@@ -178,7 +178,7 @@ func ChangeActiveOrgAndRedirectToHome(c *m.Context) {
 	c.Redirect(setting.AppSubUrl + "/")
 	c.Redirect(setting.AppSubUrl + "/")
 }
 }
 
 
-func ChangeUserPassword(c *m.Context, cmd m.ChangeUserPasswordCommand) Response {
+func ChangeUserPassword(c *m.ReqContext, cmd m.ChangeUserPasswordCommand) Response {
 	if setting.LdapEnabled || setting.AuthProxyEnabled {
 	if setting.LdapEnabled || setting.AuthProxyEnabled {
 		return ApiError(400, "Not allowed to change password when LDAP or Auth Proxy is enabled", nil)
 		return ApiError(400, "Not allowed to change password when LDAP or Auth Proxy is enabled", nil)
 	}
 	}
@@ -210,7 +210,7 @@ func ChangeUserPassword(c *m.Context, cmd m.ChangeUserPasswordCommand) Response
 }
 }
 
 
 // GET /api/users
 // GET /api/users
-func SearchUsers(c *m.Context) Response {
+func SearchUsers(c *m.ReqContext) Response {
 	query, err := searchUser(c)
 	query, err := searchUser(c)
 	if err != nil {
 	if err != nil {
 		return ApiError(500, "Failed to fetch users", err)
 		return ApiError(500, "Failed to fetch users", err)
@@ -220,7 +220,7 @@ func SearchUsers(c *m.Context) Response {
 }
 }
 
 
 // GET /api/users/search
 // GET /api/users/search
-func SearchUsersWithPaging(c *m.Context) Response {
+func SearchUsersWithPaging(c *m.ReqContext) Response {
 	query, err := searchUser(c)
 	query, err := searchUser(c)
 	if err != nil {
 	if err != nil {
 		return ApiError(500, "Failed to fetch users", err)
 		return ApiError(500, "Failed to fetch users", err)
@@ -229,7 +229,7 @@ func SearchUsersWithPaging(c *m.Context) Response {
 	return Json(200, query.Result)
 	return Json(200, query.Result)
 }
 }
 
 
-func searchUser(c *m.Context) (*m.SearchUsersQuery, error) {
+func searchUser(c *m.ReqContext) (*m.SearchUsersQuery, error) {
 	perPage := c.QueryInt("perpage")
 	perPage := c.QueryInt("perpage")
 	if perPage <= 0 {
 	if perPage <= 0 {
 		perPage = 1000
 		perPage = 1000
@@ -257,7 +257,7 @@ func searchUser(c *m.Context) (*m.SearchUsersQuery, error) {
 	return query, nil
 	return query, nil
 }
 }
 
 
-func SetHelpFlag(c *m.Context) Response {
+func SetHelpFlag(c *m.ReqContext) Response {
 	flag := c.ParamsInt64(":id")
 	flag := c.ParamsInt64(":id")
 
 
 	bitmask := &c.HelpFlags1
 	bitmask := &c.HelpFlags1
@@ -275,7 +275,7 @@ func SetHelpFlag(c *m.Context) Response {
 	return Json(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
 	return Json(200, &util.DynMap{"message": "Help flag set", "helpFlags1": cmd.HelpFlags1})
 }
 }
 
 
-func ClearHelpFlags(c *m.Context) Response {
+func ClearHelpFlags(c *m.ReqContext) Response {
 	cmd := m.SetUserHelpFlagCommand{
 	cmd := m.SetUserHelpFlagCommand{
 		UserId:     c.UserId,
 		UserId:     c.UserId,
 		HelpFlags1: m.HelpFlags1(0),
 		HelpFlags1: m.HelpFlags1(0),

+ 6 - 6
pkg/middleware/auth.go

@@ -16,7 +16,7 @@ type AuthOptions struct {
 	ReqSignedIn     bool
 	ReqSignedIn     bool
 }
 }
 
 
-func getRequestUserId(c *m.Context) int64 {
+func getRequestUserId(c *m.ReqContext) int64 {
 	userId := c.Session.Get(session.SESS_KEY_USERID)
 	userId := c.Session.Get(session.SESS_KEY_USERID)
 
 
 	if userId != nil {
 	if userId != nil {
@@ -26,7 +26,7 @@ func getRequestUserId(c *m.Context) int64 {
 	return 0
 	return 0
 }
 }
 
 
-func getApiKey(c *m.Context) string {
+func getApiKey(c *m.ReqContext) string {
 	header := c.Req.Header.Get("Authorization")
 	header := c.Req.Header.Get("Authorization")
 	parts := strings.SplitN(header, " ", 2)
 	parts := strings.SplitN(header, " ", 2)
 	if len(parts) == 2 && parts[0] == "Bearer" {
 	if len(parts) == 2 && parts[0] == "Bearer" {
@@ -37,7 +37,7 @@ func getApiKey(c *m.Context) string {
 	return ""
 	return ""
 }
 }
 
 
-func accessForbidden(c *m.Context) {
+func accessForbidden(c *m.ReqContext) {
 	if c.IsApiRequest() {
 	if c.IsApiRequest() {
 		c.JsonApiErr(403, "Permission denied", nil)
 		c.JsonApiErr(403, "Permission denied", nil)
 		return
 		return
@@ -46,7 +46,7 @@ func accessForbidden(c *m.Context) {
 	c.Redirect(setting.AppSubUrl + "/")
 	c.Redirect(setting.AppSubUrl + "/")
 }
 }
 
 
-func notAuthorized(c *m.Context) {
+func notAuthorized(c *m.ReqContext) {
 	if c.IsApiRequest() {
 	if c.IsApiRequest() {
 		c.JsonApiErr(401, "Unauthorized", nil)
 		c.JsonApiErr(401, "Unauthorized", nil)
 		return
 		return
@@ -58,7 +58,7 @@ func notAuthorized(c *m.Context) {
 }
 }
 
 
 func RoleAuth(roles ...m.RoleType) macaron.Handler {
 func RoleAuth(roles ...m.RoleType) macaron.Handler {
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		ok := false
 		ok := false
 		for _, role := range roles {
 		for _, role := range roles {
 			if role == c.OrgRole {
 			if role == c.OrgRole {
@@ -73,7 +73,7 @@ func RoleAuth(roles ...m.RoleType) macaron.Handler {
 }
 }
 
 
 func Auth(options *AuthOptions) macaron.Handler {
 func Auth(options *AuthOptions) macaron.Handler {
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		if !c.IsSignedIn && options.ReqSignedIn && !c.AllowAnonymous {
 		if !c.IsSignedIn && options.ReqSignedIn && !c.AllowAnonymous {
 			notAuthorized(c)
 			notAuthorized(c)
 			return
 			return

+ 3 - 3
pkg/middleware/auth_proxy.go

@@ -14,7 +14,7 @@ import (
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
 
 
-func initContextWithAuthProxy(ctx *m.Context, orgId int64) bool {
+func initContextWithAuthProxy(ctx *m.ReqContext, orgId int64) bool {
 	if !setting.AuthProxyEnabled {
 	if !setting.AuthProxyEnabled {
 		return false
 		return false
 	}
 	}
@@ -95,7 +95,7 @@ func initContextWithAuthProxy(ctx *m.Context, orgId int64) bool {
 	return true
 	return true
 }
 }
 
 
-var syncGrafanaUserWithLdapUser = func(ctx *m.Context, query *m.GetSignedInUserQuery) error {
+var syncGrafanaUserWithLdapUser = func(ctx *m.ReqContext, query *m.GetSignedInUserQuery) error {
 	if setting.LdapEnabled {
 	if setting.LdapEnabled {
 		expireEpoch := time.Now().Add(time.Duration(-setting.AuthProxyLdapSyncTtl) * time.Minute).Unix()
 		expireEpoch := time.Now().Add(time.Duration(-setting.AuthProxyLdapSyncTtl) * time.Minute).Unix()
 
 
@@ -121,7 +121,7 @@ var syncGrafanaUserWithLdapUser = func(ctx *m.Context, query *m.GetSignedInUserQ
 	return nil
 	return nil
 }
 }
 
 
-func checkAuthenticationProxy(ctx *m.Context, proxyHeaderValue string) error {
+func checkAuthenticationProxy(ctx *m.ReqContext, proxyHeaderValue string) error {
 	if len(strings.TrimSpace(setting.AuthProxyWhitelist)) > 0 {
 	if len(strings.TrimSpace(setting.AuthProxyWhitelist)) > 0 {
 		proxies := strings.Split(setting.AuthProxyWhitelist, ",")
 		proxies := strings.Split(setting.AuthProxyWhitelist, ",")
 		remoteAddrSplit := strings.Split(ctx.Req.RemoteAddr, ":")
 		remoteAddrSplit := strings.Split(ctx.Req.RemoteAddr, ":")

+ 3 - 3
pkg/middleware/auth_proxy_test.go

@@ -32,7 +32,7 @@ func TestAuthProxyWithLdapEnabled(t *testing.T) {
 		Convey("When session variable lastLdapSync not set, call syncSignedInUser and set lastLdapSync", func() {
 		Convey("When session variable lastLdapSync not set, call syncSignedInUser and set lastLdapSync", func() {
 			// arrange
 			// arrange
 			sess := mockSession{}
 			sess := mockSession{}
-			ctx := m.Context{Session: &sess}
+			ctx := m.ReqContext{Session: &sess}
 			So(sess.Get(session.SESS_KEY_LASTLDAPSYNC), ShouldBeNil)
 			So(sess.Get(session.SESS_KEY_LASTLDAPSYNC), ShouldBeNil)
 
 
 			// act
 			// act
@@ -46,7 +46,7 @@ func TestAuthProxyWithLdapEnabled(t *testing.T) {
 		Convey("When session variable not expired, don't sync and don't change session var", func() {
 		Convey("When session variable not expired, don't sync and don't change session var", func() {
 			// arrange
 			// arrange
 			sess := mockSession{}
 			sess := mockSession{}
-			ctx := m.Context{Session: &sess}
+			ctx := m.ReqContext{Session: &sess}
 			now := time.Now().Unix()
 			now := time.Now().Unix()
 			sess.Set(session.SESS_KEY_LASTLDAPSYNC, now)
 			sess.Set(session.SESS_KEY_LASTLDAPSYNC, now)
 
 
@@ -61,7 +61,7 @@ func TestAuthProxyWithLdapEnabled(t *testing.T) {
 		Convey("When lastldapsync is expired, session variable should be updated", func() {
 		Convey("When lastldapsync is expired, session variable should be updated", func() {
 			// arrange
 			// arrange
 			sess := mockSession{}
 			sess := mockSession{}
-			ctx := m.Context{Session: &sess}
+			ctx := m.ReqContext{Session: &sess}
 			expiredTime := time.Now().Add(time.Duration(-120) * time.Minute).Unix()
 			expiredTime := time.Now().Add(time.Duration(-120) * time.Minute).Unix()
 			sess.Set(session.SESS_KEY_LASTLDAPSYNC, expiredTime)
 			sess.Set(session.SESS_KEY_LASTLDAPSYNC, expiredTime)
 
 

+ 2 - 2
pkg/middleware/dashboard_redirect.go

@@ -20,7 +20,7 @@ func getDashboardUrlBySlug(orgId int64, slug string) (string, error) {
 }
 }
 
 
 func RedirectFromLegacyDashboardUrl() macaron.Handler {
 func RedirectFromLegacyDashboardUrl() macaron.Handler {
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		slug := c.Params("slug")
 		slug := c.Params("slug")
 
 
 		if slug != "" {
 		if slug != "" {
@@ -34,7 +34,7 @@ func RedirectFromLegacyDashboardUrl() macaron.Handler {
 }
 }
 
 
 func RedirectFromLegacyDashboardSoloUrl() macaron.Handler {
 func RedirectFromLegacyDashboardSoloUrl() macaron.Handler {
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		slug := c.Params("slug")
 		slug := c.Params("slug")
 
 
 		if slug != "" {
 		if slug != "" {

+ 1 - 1
pkg/middleware/logger.go

@@ -48,7 +48,7 @@ func Logger() macaron.Handler {
 		}
 		}
 
 
 		if ctx, ok := c.Data["ctx"]; ok {
 		if ctx, ok := c.Data["ctx"]; ok {
-			ctxTyped := ctx.(*m.Context)
+			ctxTyped := ctx.(*m.ReqContext)
 			if status == 500 {
 			if status == 500 {
 				ctxTyped.Logger.Error("Request Completed", "method", req.Method, "path", req.URL.Path, "status", status, "remote_addr", c.RemoteAddr(), "time_ms", int64(timeTakenMs), "size", rw.Size(), "referer", req.Referer())
 				ctxTyped.Logger.Error("Request Completed", "method", req.Method, "path", req.URL.Path, "status", status, "remote_addr", c.RemoteAddr(), "time_ms", int64(timeTakenMs), "size", rw.Size(), "referer", req.Referer())
 			} else {
 			} else {

+ 6 - 6
pkg/middleware/middleware.go

@@ -17,7 +17,7 @@ import (
 
 
 func GetContextHandler() macaron.Handler {
 func GetContextHandler() macaron.Handler {
 	return func(c *macaron.Context) {
 	return func(c *macaron.Context) {
-		ctx := &m.Context{
+		ctx := &m.ReqContext{
 			Context:        c,
 			Context:        c,
 			SignedInUser:   &m.SignedInUser{},
 			SignedInUser:   &m.SignedInUser{},
 			Session:        session.GetSession(),
 			Session:        session.GetSession(),
@@ -61,7 +61,7 @@ func GetContextHandler() macaron.Handler {
 	}
 	}
 }
 }
 
 
-func initContextWithAnonymousUser(ctx *m.Context) bool {
+func initContextWithAnonymousUser(ctx *m.ReqContext) bool {
 	if !setting.AnonymousEnabled {
 	if !setting.AnonymousEnabled {
 		return false
 		return false
 	}
 	}
@@ -81,7 +81,7 @@ func initContextWithAnonymousUser(ctx *m.Context) bool {
 	return true
 	return true
 }
 }
 
 
-func initContextWithUserSessionCookie(ctx *m.Context, orgId int64) bool {
+func initContextWithUserSessionCookie(ctx *m.ReqContext, orgId int64) bool {
 	// initialize session
 	// initialize session
 	if err := ctx.Session.Start(ctx.Context); err != nil {
 	if err := ctx.Session.Start(ctx.Context); err != nil {
 		ctx.Logger.Error("Failed to start session", "error", err)
 		ctx.Logger.Error("Failed to start session", "error", err)
@@ -104,7 +104,7 @@ func initContextWithUserSessionCookie(ctx *m.Context, orgId int64) bool {
 	return true
 	return true
 }
 }
 
 
-func initContextWithApiKey(ctx *m.Context) bool {
+func initContextWithApiKey(ctx *m.ReqContext) bool {
 	var keyString string
 	var keyString string
 	if keyString = getApiKey(ctx); keyString == "" {
 	if keyString = getApiKey(ctx); keyString == "" {
 		return false
 		return false
@@ -140,7 +140,7 @@ func initContextWithApiKey(ctx *m.Context) bool {
 	return true
 	return true
 }
 }
 
 
-func initContextWithBasicAuth(ctx *m.Context, orgId int64) bool {
+func initContextWithBasicAuth(ctx *m.ReqContext, orgId int64) bool {
 
 
 	if !setting.BasicAuthEnabled {
 	if !setting.BasicAuthEnabled {
 		return false
 		return false
@@ -183,7 +183,7 @@ func initContextWithBasicAuth(ctx *m.Context, orgId int64) bool {
 }
 }
 
 
 func AddDefaultResponseHeaders() macaron.Handler {
 func AddDefaultResponseHeaders() macaron.Handler {
-	return func(ctx *m.Context) {
+	return func(ctx *m.ReqContext) {
 		if ctx.IsApiRequest() && ctx.Req.Method == "GET" {
 		if ctx.IsApiRequest() && ctx.Req.Method == "GET" {
 			ctx.Resp.Header().Add("Cache-Control", "no-cache")
 			ctx.Resp.Header().Add("Cache-Control", "no-cache")
 			ctx.Resp.Header().Add("Pragma", "no-cache")
 			ctx.Resp.Header().Add("Pragma", "no-cache")

+ 6 - 6
pkg/middleware/middleware_test.go

@@ -131,7 +131,7 @@ func TestMiddlewareContext(t *testing.T) {
 
 
 		middlewareScenario("UserId in session", func(sc *scenarioContext) {
 		middlewareScenario("UserId in session", func(sc *scenarioContext) {
 
 
-			sc.fakeReq("GET", "/").handler(func(c *m.Context) {
+			sc.fakeReq("GET", "/").handler(func(c *m.ReqContext) {
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 			}).exec()
 			}).exec()
 
 
@@ -277,7 +277,7 @@ func TestMiddlewareContext(t *testing.T) {
 			})
 			})
 
 
 			// create session
 			// create session
-			sc.fakeReq("GET", "/").handler(func(c *m.Context) {
+			sc.fakeReq("GET", "/").handler(func(c *m.ReqContext) {
 				c.Session.Set(session.SESS_KEY_USERID, int64(33))
 				c.Session.Set(session.SESS_KEY_USERID, int64(33))
 			}).exec()
 			}).exec()
 
 
@@ -301,7 +301,7 @@ func TestMiddlewareContext(t *testing.T) {
 			setting.LdapEnabled = true
 			setting.LdapEnabled = true
 
 
 			called := false
 			called := false
-			syncGrafanaUserWithLdapUser = func(ctx *m.Context, query *m.GetSignedInUserQuery) error {
+			syncGrafanaUserWithLdapUser = func(ctx *m.ReqContext, query *m.GetSignedInUserQuery) error {
 				called = true
 				called = true
 				return nil
 				return nil
 			}
 			}
@@ -342,7 +342,7 @@ func middlewareScenario(desc string, fn scenarioFunc) {
 		sc.m.Use(OrgRedirect())
 		sc.m.Use(OrgRedirect())
 		sc.m.Use(AddDefaultResponseHeaders())
 		sc.m.Use(AddDefaultResponseHeaders())
 
 
-		sc.defaultHandler = func(c *m.Context) {
+		sc.defaultHandler = func(c *m.ReqContext) {
 			sc.context = c
 			sc.context = c
 			if sc.handlerFunc != nil {
 			if sc.handlerFunc != nil {
 				sc.handlerFunc(sc.context)
 				sc.handlerFunc(sc.context)
@@ -357,7 +357,7 @@ func middlewareScenario(desc string, fn scenarioFunc) {
 
 
 type scenarioContext struct {
 type scenarioContext struct {
 	m              *macaron.Macaron
 	m              *macaron.Macaron
-	context        *m.Context
+	context        *m.ReqContext
 	resp           *httptest.ResponseRecorder
 	resp           *httptest.ResponseRecorder
 	apiKey         string
 	apiKey         string
 	authHeader     string
 	authHeader     string
@@ -437,4 +437,4 @@ func (sc *scenarioContext) exec() {
 }
 }
 
 
 type scenarioFunc func(c *scenarioContext)
 type scenarioFunc func(c *scenarioContext)
-type handlerFunc func(c *m.Context)
+type handlerFunc func(c *m.ReqContext)

+ 1 - 1
pkg/middleware/org_redirect.go

@@ -22,7 +22,7 @@ func OrgRedirect() macaron.Handler {
 			return
 			return
 		}
 		}
 
 
-		ctx, ok := c.Data["ctx"].(*m.Context)
+		ctx, ok := c.Data["ctx"].(*m.ReqContext)
 		if !ok || !ctx.IsSignedIn {
 		if !ok || !ctx.IsSignedIn {
 			return
 			return
 		}
 		}

+ 2 - 2
pkg/middleware/org_redirect_test.go

@@ -15,7 +15,7 @@ func TestOrgRedirectMiddleware(t *testing.T) {
 
 
 	Convey("Can redirect to correct org", t, func() {
 	Convey("Can redirect to correct org", t, func() {
 		middlewareScenario("when setting a correct org for the user", func(sc *scenarioContext) {
 		middlewareScenario("when setting a correct org for the user", func(sc *scenarioContext) {
-			sc.fakeReq("GET", "/").handler(func(c *m.Context) {
+			sc.fakeReq("GET", "/").handler(func(c *m.ReqContext) {
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 			}).exec()
 			}).exec()
 
 
@@ -37,7 +37,7 @@ func TestOrgRedirectMiddleware(t *testing.T) {
 		})
 		})
 
 
 		middlewareScenario("when setting an invalid org for user", func(sc *scenarioContext) {
 		middlewareScenario("when setting an invalid org for user", func(sc *scenarioContext) {
-			sc.fakeReq("GET", "/").handler(func(c *m.Context) {
+			sc.fakeReq("GET", "/").handler(func(c *m.ReqContext) {
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 			}).exec()
 			}).exec()
 
 

+ 1 - 1
pkg/middleware/perf.go

@@ -9,6 +9,6 @@ import (
 )
 )
 
 
 func MeasureRequestTime() macaron.Handler {
 func MeasureRequestTime() macaron.Handler {
-	return func(res http.ResponseWriter, req *http.Request, c *m.Context) {
+	return func(res http.ResponseWriter, req *http.Request, c *m.ReqContext) {
 	}
 	}
 }
 }

+ 2 - 2
pkg/middleware/quota.go

@@ -11,7 +11,7 @@ import (
 )
 )
 
 
 func Quota(target string) macaron.Handler {
 func Quota(target string) macaron.Handler {
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		limitReached, err := QuotaReached(c, target)
 		limitReached, err := QuotaReached(c, target)
 		if err != nil {
 		if err != nil {
 			c.JsonApiErr(500, "failed to get quota", err)
 			c.JsonApiErr(500, "failed to get quota", err)
@@ -24,7 +24,7 @@ func Quota(target string) macaron.Handler {
 	}
 	}
 }
 }
 
 
-func QuotaReached(c *m.Context, target string) (bool, error) {
+func QuotaReached(c *m.ReqContext, target string) (bool, error) {
 	if !setting.Quota.Enabled {
 	if !setting.Quota.Enabled {
 		return false, nil
 		return false, nil
 	}
 	}

+ 1 - 1
pkg/middleware/quota_test.go

@@ -75,7 +75,7 @@ func TestMiddlewareQuota(t *testing.T) {
 
 
 		middlewareScenario("with user logged in", func(sc *scenarioContext) {
 		middlewareScenario("with user logged in", func(sc *scenarioContext) {
 			// log us in, so we have a user_id and org_id in the context
 			// log us in, so we have a user_id and org_id in the context
-			sc.fakeReq("GET", "/").handler(func(c *m.Context) {
+			sc.fakeReq("GET", "/").handler(func(c *m.ReqContext) {
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 				c.Session.Set(session.SESS_KEY_USERID, int64(12))
 			}).exec()
 			}).exec()
 
 

+ 2 - 2
pkg/middleware/recovery.go

@@ -107,7 +107,7 @@ func Recovery() macaron.Handler {
 				panicLogger := log.Root
 				panicLogger := log.Root
 				// try to get request logger
 				// try to get request logger
 				if ctx, ok := c.Data["ctx"]; ok {
 				if ctx, ok := c.Data["ctx"]; ok {
-					ctxTyped := ctx.(*m.Context)
+					ctxTyped := ctx.(*m.ReqContext)
 					panicLogger = ctxTyped.Logger
 					panicLogger = ctxTyped.Logger
 				}
 				}
 
 
@@ -124,7 +124,7 @@ func Recovery() macaron.Handler {
 					c.Data["ErrorMsg"] = string(stack)
 					c.Data["ErrorMsg"] = string(stack)
 				}
 				}
 
 
-				ctx, ok := c.Data["ctx"].(*m.Context)
+				ctx, ok := c.Data["ctx"].(*m.ReqContext)
 
 
 				if ok && ctx.IsApiRequest() {
 				if ok && ctx.IsApiRequest() {
 					resp := make(map[string]interface{})
 					resp := make(map[string]interface{})

+ 2 - 2
pkg/middleware/recovery_test.go

@@ -39,7 +39,7 @@ func TestRecoveryMiddleware(t *testing.T) {
 	})
 	})
 }
 }
 
 
-func PanicHandler(c *m.Context) {
+func PanicHandler(c *m.ReqContext) {
 	panic("Handler has panicked")
 	panic("Handler has panicked")
 }
 }
 
 
@@ -67,7 +67,7 @@ func recoveryScenario(desc string, url string, fn scenarioFunc) {
 		sc.m.Use(OrgRedirect())
 		sc.m.Use(OrgRedirect())
 		sc.m.Use(AddDefaultResponseHeaders())
 		sc.m.Use(AddDefaultResponseHeaders())
 
 
-		sc.defaultHandler = func(c *m.Context) {
+		sc.defaultHandler = func(c *m.ReqContext) {
 			sc.context = c
 			sc.context = c
 			if sc.handlerFunc != nil {
 			if sc.handlerFunc != nil {
 				sc.handlerFunc(sc.context)
 				sc.handlerFunc(sc.context)

+ 1 - 1
pkg/middleware/render_auth.go

@@ -10,7 +10,7 @@ import (
 var renderKeysLock sync.Mutex
 var renderKeysLock sync.Mutex
 var renderKeys map[string]*m.SignedInUser = make(map[string]*m.SignedInUser)
 var renderKeys map[string]*m.SignedInUser = make(map[string]*m.SignedInUser)
 
 
-func initContextWithRenderAuth(ctx *m.Context) bool {
+func initContextWithRenderAuth(ctx *m.ReqContext) bool {
 	key := ctx.GetCookie("renderKey")
 	key := ctx.GetCookie("renderKey")
 	if key == "" {
 	if key == "" {
 		return false
 		return false

+ 1 - 1
pkg/middleware/session.go

@@ -11,7 +11,7 @@ import (
 func Sessioner(options *ms.Options) macaron.Handler {
 func Sessioner(options *ms.Options) macaron.Handler {
 	session.Init(options)
 	session.Init(options)
 
 
-	return func(ctx *m.Context) {
+	return func(ctx *m.ReqContext) {
 		ctx.Next()
 		ctx.Next()
 
 
 		if err := ctx.Session.Release(); err != nil {
 		if err := ctx.Session.Release(); err != nil {

+ 1 - 1
pkg/middleware/validate_host.go

@@ -9,7 +9,7 @@ import (
 )
 )
 
 
 func ValidateHostHeader(domain string) macaron.Handler {
 func ValidateHostHeader(domain string) macaron.Handler {
-	return func(c *m.Context) {
+	return func(c *m.ReqContext) {
 		// ignore local render calls
 		// ignore local render calls
 		if c.IsRenderCall {
 		if c.IsRenderCall {
 			return
 			return

+ 8 - 8
pkg/models/context.go

@@ -11,7 +11,7 @@ import (
 	"github.com/grafana/grafana/pkg/setting"
 	"github.com/grafana/grafana/pkg/setting"
 )
 )
 
 
-type Context struct {
+type ReqContext struct {
 	*macaron.Context
 	*macaron.Context
 	*SignedInUser
 	*SignedInUser
 
 
@@ -24,7 +24,7 @@ type Context struct {
 }
 }
 
 
 // Handle handles and logs error by given status.
 // Handle handles and logs error by given status.
-func (ctx *Context) Handle(status int, title string, err error) {
+func (ctx *ReqContext) Handle(status int, title string, err error) {
 	if err != nil {
 	if err != nil {
 		ctx.Logger.Error(title, "error", err)
 		ctx.Logger.Error(title, "error", err)
 		if setting.Env != setting.PROD {
 		if setting.Env != setting.PROD {
@@ -39,17 +39,17 @@ func (ctx *Context) Handle(status int, title string, err error) {
 	ctx.HTML(status, "error")
 	ctx.HTML(status, "error")
 }
 }
 
 
-func (ctx *Context) JsonOK(message string) {
+func (ctx *ReqContext) JsonOK(message string) {
 	resp := make(map[string]interface{})
 	resp := make(map[string]interface{})
 	resp["message"] = message
 	resp["message"] = message
 	ctx.JSON(200, resp)
 	ctx.JSON(200, resp)
 }
 }
 
 
-func (ctx *Context) IsApiRequest() bool {
+func (ctx *ReqContext) IsApiRequest() bool {
 	return strings.HasPrefix(ctx.Req.URL.Path, "/api")
 	return strings.HasPrefix(ctx.Req.URL.Path, "/api")
 }
 }
 
 
-func (ctx *Context) JsonApiErr(status int, message string, err error) {
+func (ctx *ReqContext) JsonApiErr(status int, message string, err error) {
 	resp := make(map[string]interface{})
 	resp := make(map[string]interface{})
 
 
 	if err != nil {
 	if err != nil {
@@ -73,14 +73,14 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
 	ctx.JSON(status, resp)
 	ctx.JSON(status, resp)
 }
 }
 
 
-func (ctx *Context) HasUserRole(role RoleType) bool {
+func (ctx *ReqContext) HasUserRole(role RoleType) bool {
 	return ctx.OrgRole.Includes(role)
 	return ctx.OrgRole.Includes(role)
 }
 }
 
 
-func (ctx *Context) HasHelpFlag(flag HelpFlags1) bool {
+func (ctx *ReqContext) HasHelpFlag(flag HelpFlags1) bool {
 	return ctx.HelpFlags1.HasFlag(flag)
 	return ctx.HelpFlags1.HasFlag(flag)
 }
 }
 
 
-func (ctx *Context) TimeRequest(timer prometheus.Summary) {
+func (ctx *ReqContext) TimeRequest(timer prometheus.Summary) {
 	ctx.Data["perfmon.timer"] = timer
 	ctx.Data["perfmon.timer"] = timer
 }
 }