Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service * Rename package to contextmodel * Generate ngalert files * Remove unused imports
This commit is contained in:
+19
-18
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/team"
|
||||
@@ -29,7 +30,7 @@ import (
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetSignedInUser(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetSignedInUser(c *contextmodel.ReqContext) response.Response {
|
||||
return hs.getUserUserProfile(c, c.UserID)
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ func (hs *HTTPServer) GetSignedInUser(c *models.ReqContext) response.Response {
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetUserByID(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetUserByID(c *contextmodel.ReqContext) response.Response {
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -51,7 +52,7 @@ func (hs *HTTPServer) GetUserByID(c *models.ReqContext) response.Response {
|
||||
return hs.getUserUserProfile(c, id)
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) getUserUserProfile(c *models.ReqContext, userID int64) response.Response {
|
||||
func (hs *HTTPServer) getUserUserProfile(c *contextmodel.ReqContext, userID int64) response.Response {
|
||||
query := user.GetUserProfileQuery{UserID: userID}
|
||||
|
||||
userProfile, err := hs.userService.GetProfile(c.Req.Context(), &query)
|
||||
@@ -86,7 +87,7 @@ func (hs *HTTPServer) getUserUserProfile(c *models.ReqContext, userID int64) res
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetUserByLoginOrEmail(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetUserByLoginOrEmail(c *contextmodel.ReqContext) response.Response {
|
||||
query := user.GetUserByLoginQuery{LoginOrEmail: c.Query("loginOrEmail")}
|
||||
usr, err := hs.userService.GetByLogin(c.Req.Context(), &query)
|
||||
if err != nil {
|
||||
@@ -118,7 +119,7 @@ func (hs *HTTPServer) GetUserByLoginOrEmail(c *models.ReqContext) response.Respo
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) UpdateSignedInUser(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) UpdateSignedInUser(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := user.UpdateUserCommand{}
|
||||
var err error
|
||||
if err = web.Bind(c.Req, &cmd); err != nil {
|
||||
@@ -152,7 +153,7 @@ func (hs *HTTPServer) UpdateSignedInUser(c *models.ReqContext) response.Response
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) UpdateUser(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) UpdateUser(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := user.UpdateUserCommand{}
|
||||
var err error
|
||||
if err = web.Bind(c.Req, &cmd); err != nil {
|
||||
@@ -171,7 +172,7 @@ func (hs *HTTPServer) UpdateUser(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// POST /api/users/:id/using/:orgId
|
||||
func (hs *HTTPServer) UpdateUserActiveOrg(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) UpdateUserActiveOrg(c *contextmodel.ReqContext) response.Response {
|
||||
userID, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -250,7 +251,7 @@ func (hs *HTTPServer) isExternalUser(ctx context.Context, userID int64) (bool, e
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetSignedInUserOrgList(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetSignedInUserOrgList(c *contextmodel.ReqContext) response.Response {
|
||||
return hs.getUserOrgList(c.Req.Context(), c.UserID)
|
||||
}
|
||||
|
||||
@@ -265,7 +266,7 @@ func (hs *HTTPServer) GetSignedInUserOrgList(c *models.ReqContext) response.Resp
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetSignedInUserTeamList(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetSignedInUserTeamList(c *contextmodel.ReqContext) response.Response {
|
||||
return hs.getUserTeamList(c, c.OrgID, c.UserID)
|
||||
}
|
||||
|
||||
@@ -281,7 +282,7 @@ func (hs *HTTPServer) GetSignedInUserTeamList(c *models.ReqContext) response.Res
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetUserTeams(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetUserTeams(c *contextmodel.ReqContext) response.Response {
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -289,7 +290,7 @@ func (hs *HTTPServer) GetUserTeams(c *models.ReqContext) response.Response {
|
||||
return hs.getUserTeamList(c, c.OrgID, id)
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) getUserTeamList(c *models.ReqContext, orgID int64, userID int64) response.Response {
|
||||
func (hs *HTTPServer) getUserTeamList(c *contextmodel.ReqContext, orgID int64, userID int64) response.Response {
|
||||
query := team.GetTeamsByUserQuery{OrgID: orgID, UserID: userID, SignedInUser: c.SignedInUser}
|
||||
|
||||
queryResult, err := hs.teamService.GetTeamsByUser(c.Req.Context(), &query)
|
||||
@@ -315,7 +316,7 @@ func (hs *HTTPServer) getUserTeamList(c *models.ReqContext, orgID int64, userID
|
||||
// 403: forbiddenError
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetUserOrgList(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) GetUserOrgList(c *contextmodel.ReqContext) response.Response {
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -365,7 +366,7 @@ func (hs *HTTPServer) validateUsingOrg(ctx context.Context, userID int64, orgID
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) UserSetUsingOrg(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) UserSetUsingOrg(c *contextmodel.ReqContext) response.Response {
|
||||
orgID, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -385,7 +386,7 @@ func (hs *HTTPServer) UserSetUsingOrg(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
// GET /profile/switch-org/:id
|
||||
func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *models.ReqContext) {
|
||||
func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *contextmodel.ReqContext) {
|
||||
orgID, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
c.JsonApiErr(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -420,7 +421,7 @@ func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *models.ReqContext) {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) ChangeUserPassword(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) ChangeUserPassword(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := user.ChangeUserPasswordCommand{}
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
@@ -468,7 +469,7 @@ func (hs *HTTPServer) ChangeUserPassword(c *models.ReqContext) response.Response
|
||||
}
|
||||
|
||||
// redirectToChangePassword handles GET /.well-known/change-password.
|
||||
func redirectToChangePassword(c *models.ReqContext) {
|
||||
func redirectToChangePassword(c *contextmodel.ReqContext) {
|
||||
c.Redirect("/profile/password", 302)
|
||||
}
|
||||
|
||||
@@ -481,7 +482,7 @@ func redirectToChangePassword(c *models.ReqContext) {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) SetHelpFlag(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) SetHelpFlag(c *contextmodel.ReqContext) response.Response {
|
||||
flag, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
@@ -511,7 +512,7 @@ func (hs *HTTPServer) SetHelpFlag(c *models.ReqContext) response.Response {
|
||||
// 401: unauthorisedError
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) ClearHelpFlags(c *models.ReqContext) response.Response {
|
||||
func (hs *HTTPServer) ClearHelpFlags(c *contextmodel.ReqContext) response.Response {
|
||||
cmd := user.SetUserHelpFlagCommand{
|
||||
UserID: c.UserID,
|
||||
HelpFlags1: user.HelpFlags1(0),
|
||||
|
||||
Reference in New Issue
Block a user