Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343)

* Chore: Add user service method SetUsingOrg

* Chore: Add user service method GetSignedInUserWithCacheCtx

* Use method GetSignedInUserWithCacheCtx from user service

* Fix lint after rebase

* Fix lint

* Fix lint error

* roll back some changes

* Roll back changes in api and middleware

* Add xorm tags to SignedInUser ID fields
This commit is contained in:
idafurjes
2022-08-11 13:28:55 +02:00
committed by GitHub
parent ca72cd570e
commit a14621fff6
191 changed files with 1108 additions and 1049 deletions
+21 -21
View File
@@ -34,7 +34,7 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response {
query := &annotations.ItemQuery{
From: c.QueryInt64("from"),
To: c.QueryInt64("to"),
OrgId: c.OrgId,
OrgId: c.OrgID,
UserId: c.QueryInt64("userId"),
AlertId: c.QueryInt64("alertId"),
DashboardId: c.QueryInt64("dashboardId"),
@@ -49,7 +49,7 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response {
// When dashboard UID present in the request, we ignore dashboard ID
if query.DashboardUid != "" {
dq := models.GetDashboardQuery{Uid: query.DashboardUid, OrgId: c.OrgId}
dq := models.GetDashboardQuery{Uid: query.DashboardUid, OrgId: c.OrgID}
err := hs.DashboardService.GetDashboard(c.Req.Context(), &dq)
if err != nil {
return response.Error(http.StatusBadRequest, "Invalid dashboard UID in the request", err)
@@ -75,7 +75,7 @@ func (hs *HTTPServer) GetAnnotations(c *models.ReqContext) response.Response {
if val, ok := dashboardCache[item.DashboardId]; ok {
item.DashboardUID = val
} else {
query := models.GetDashboardQuery{Id: item.DashboardId, OrgId: c.OrgId}
query := models.GetDashboardQuery{Id: item.DashboardId, OrgId: c.OrgID}
err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
if err == nil && query.Result != nil {
item.DashboardUID = &query.Result.Uid
@@ -118,7 +118,7 @@ func (hs *HTTPServer) PostAnnotation(c *models.ReqContext) response.Response {
// overwrite dashboardId when dashboardUID is not empty
if cmd.DashboardUID != "" {
query := models.GetDashboardQuery{OrgId: c.OrgId, Uid: cmd.DashboardUID}
query := models.GetDashboardQuery{OrgId: c.OrgID, Uid: cmd.DashboardUID}
err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
if err == nil {
cmd.DashboardId = query.Result.Id
@@ -137,8 +137,8 @@ func (hs *HTTPServer) PostAnnotation(c *models.ReqContext) response.Response {
}
item := annotations.Item{
OrgId: c.OrgId,
UserId: c.UserId,
OrgId: c.OrgID,
UserId: c.UserID,
DashboardId: cmd.DashboardId,
PanelId: cmd.PanelId,
Epoch: cmd.Time,
@@ -221,8 +221,8 @@ func (hs *HTTPServer) PostGraphiteAnnotation(c *models.ReqContext) response.Resp
}
item := annotations.Item{
OrgId: c.OrgId,
UserId: c.UserId,
OrgId: c.OrgID,
UserId: c.UserID,
Epoch: cmd.When * 1000,
Text: text,
Tags: tagsArray,
@@ -273,8 +273,8 @@ func (hs *HTTPServer) UpdateAnnotation(c *models.ReqContext) response.Response {
}
item := annotations.Item{
OrgId: c.OrgId,
UserId: c.UserId,
OrgId: c.OrgID,
UserId: c.UserID,
Id: annotationID,
Epoch: cmd.Time,
EpochEnd: cmd.TimeEnd,
@@ -325,8 +325,8 @@ func (hs *HTTPServer) PatchAnnotation(c *models.ReqContext) response.Response {
}
existing := annotations.Item{
OrgId: c.OrgId,
UserId: c.UserId,
OrgId: c.OrgID,
UserId: c.UserID,
Id: annotationID,
Epoch: annotation.Time,
EpochEnd: annotation.TimeEnd,
@@ -373,7 +373,7 @@ func (hs *HTTPServer) MassDeleteAnnotations(c *models.ReqContext) response.Respo
}
if cmd.DashboardUID != "" {
query := models.GetDashboardQuery{OrgId: c.OrgId, Uid: cmd.DashboardUID}
query := models.GetDashboardQuery{OrgId: c.OrgID, Uid: cmd.DashboardUID}
err := hs.DashboardService.GetDashboard(c.Req.Context(), &query)
if err == nil {
cmd.DashboardId = query.Result.Id
@@ -400,13 +400,13 @@ func (hs *HTTPServer) MassDeleteAnnotations(c *models.ReqContext) response.Respo
}
dashboardId = annotation.DashboardId
deleteParams = &annotations.DeleteParams{
OrgId: c.OrgId,
OrgId: c.OrgID,
Id: cmd.AnnotationId,
}
} else {
dashboardId = cmd.DashboardId
deleteParams = &annotations.DeleteParams{
OrgId: c.OrgId,
OrgId: c.OrgID,
DashboardId: cmd.DashboardId,
PanelId: cmd.PanelId,
}
@@ -418,7 +418,7 @@ func (hs *HTTPServer) MassDeleteAnnotations(c *models.ReqContext) response.Respo
}
} else { // legacy permissions
deleteParams = &annotations.DeleteParams{
OrgId: c.OrgId,
OrgId: c.OrgID,
Id: cmd.AnnotationId,
DashboardId: cmd.DashboardId,
PanelId: cmd.PanelId,
@@ -491,7 +491,7 @@ func (hs *HTTPServer) DeleteAnnotationByID(c *models.ReqContext) response.Respon
}
err = repo.Delete(c.Req.Context(), &annotations.DeleteParams{
OrgId: c.OrgId,
OrgId: c.OrgID,
Id: annotationID,
})
if err != nil {
@@ -513,7 +513,7 @@ func (hs *HTTPServer) canSaveAnnotation(c *models.ReqContext, annotation *annota
}
func canEditDashboard(c *models.ReqContext, dashboardID int64) (bool, error) {
guard := guardian.New(c.Req.Context(), dashboardID, c.OrgId, c.SignedInUser)
guard := guardian.New(c.Req.Context(), dashboardID, c.OrgID, c.SignedInUser)
if canEdit, err := guard.CanEdit(); err != nil || !canEdit {
return false, err
}
@@ -524,7 +524,7 @@ func canEditDashboard(c *models.ReqContext, dashboardID int64) (bool, error) {
func findAnnotationByID(ctx context.Context, repo annotations.Repository, annotationID int64, user *user.SignedInUser) (*annotations.ItemDTO, response.Response) {
query := &annotations.ItemQuery{
AnnotationId: annotationID,
OrgId: user.OrgId,
OrgId: user.OrgID,
SignedInUser: user,
}
items, err := repo.Find(ctx, query)
@@ -552,7 +552,7 @@ func findAnnotationByID(ctx context.Context, repo annotations.Repository, annota
// 500: internalServerError
func (hs *HTTPServer) GetAnnotationTags(c *models.ReqContext) response.Response {
query := &annotations.TagsQuery{
OrgID: c.OrgId,
OrgID: c.OrgID,
Tag: c.Query("tag"),
Limit: c.QueryInt64("limit"),
}
@@ -586,7 +586,7 @@ func AnnotationTypeScopeResolver() (string, accesscontrol.ScopeAttributeResolver
// tempUser is used to resolve annotation type.
// The annotation doesn't get returned to the real user, so real user's permissions don't matter here.
tempUser := &user.SignedInUser{
OrgId: orgID,
OrgID: orgID,
Permissions: map[int64]map[string][]string{
orgID: {
dashboards.ActionDashboardsRead: {dashboards.ScopeDashboardsAll},