|
|
|
@ -17,6 +17,7 @@ import ( |
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson" |
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson" |
|
|
|
"github.com/grafana/grafana/pkg/infra/metrics" |
|
|
|
"github.com/grafana/grafana/pkg/infra/metrics" |
|
|
|
"github.com/grafana/grafana/pkg/models" |
|
|
|
"github.com/grafana/grafana/pkg/models" |
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol" |
|
|
|
"github.com/grafana/grafana/pkg/services/alerting" |
|
|
|
"github.com/grafana/grafana/pkg/services/alerting" |
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards" |
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards" |
|
|
|
"github.com/grafana/grafana/pkg/services/guardian" |
|
|
|
"github.com/grafana/grafana/pkg/services/guardian" |
|
|
|
@ -115,6 +116,13 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response { |
|
|
|
creator = hs.getUserLogin(c.Req.Context(), dash.CreatedBy) |
|
|
|
creator = hs.getUserLogin(c.Req.Context(), dash.CreatedBy) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
annotationPermissions := &dtos.AnnotationPermission{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !hs.AccessControl.IsDisabled() { |
|
|
|
|
|
|
|
hs.getAnnotationPermissionsByScope(c, &annotationPermissions.Dashboard, accesscontrol.ScopeAnnotationsTypeDashboard) |
|
|
|
|
|
|
|
hs.getAnnotationPermissionsByScope(c, &annotationPermissions.Organization, accesscontrol.ScopeAnnotationsTypeOrganization) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
meta := dtos.DashboardMeta{ |
|
|
|
meta := dtos.DashboardMeta{ |
|
|
|
IsStarred: isStarred, |
|
|
|
IsStarred: isStarred, |
|
|
|
Slug: dash.Slug, |
|
|
|
Slug: dash.Slug, |
|
|
|
@ -134,6 +142,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response { |
|
|
|
FolderId: dash.FolderId, |
|
|
|
FolderId: dash.FolderId, |
|
|
|
Url: dash.GetUrl(), |
|
|
|
Url: dash.GetUrl(), |
|
|
|
FolderTitle: "General", |
|
|
|
FolderTitle: "General", |
|
|
|
|
|
|
|
AnnotationsPermissions: annotationPermissions, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// lookup folder title
|
|
|
|
// lookup folder title
|
|
|
|
@ -190,6 +199,22 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) response.Response { |
|
|
|
return response.JSON(200, dto) |
|
|
|
return response.JSON(200, dto) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (hs *HTTPServer) getAnnotationPermissionsByScope(c *models.ReqContext, actions *dtos.AnnotationActions, scope string) { |
|
|
|
|
|
|
|
var err error |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
evaluate := accesscontrol.EvalPermission(accesscontrol.ActionAnnotationsDelete, scope) |
|
|
|
|
|
|
|
actions.CanDelete, err = hs.AccessControl.Evaluate(c.Req.Context(), c.SignedInUser, evaluate) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
hs.log.Warn("Failed to evaluate permission", "err", err, "action", accesscontrol.ActionAnnotationsDelete, "scope", scope) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
evaluate = accesscontrol.EvalPermission(accesscontrol.ActionAnnotationsWrite, scope) |
|
|
|
|
|
|
|
actions.CanEdit, err = hs.AccessControl.Evaluate(c.Req.Context(), c.SignedInUser, evaluate) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
hs.log.Warn("Failed to evaluate permission", "err", err, "action", accesscontrol.ActionAnnotationsWrite, "scope", scope) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (hs *HTTPServer) getUserLogin(ctx context.Context, userID int64) string { |
|
|
|
func (hs *HTTPServer) getUserLogin(ctx context.Context, userID int64) string { |
|
|
|
query := models.GetUserByIdQuery{Id: userID} |
|
|
|
query := models.GetUserByIdQuery{Id: userID} |
|
|
|
err := hs.SQLStore.GetUserById(ctx, &query) |
|
|
|
err := hs.SQLStore.GetUserById(ctx, &query) |
|
|
|
|