Annotations: Fix usage of dashboard table for permissions (#98774)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/db"
|
||||
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/annotations"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/permissions"
|
||||
@@ -29,12 +30,14 @@ var (
|
||||
type AuthService struct {
|
||||
db db.DB
|
||||
features featuremgmt.FeatureToggles
|
||||
dashSvc dashboards.DashboardService
|
||||
}
|
||||
|
||||
func NewAuthService(db db.DB, features featuremgmt.FeatureToggles) *AuthService {
|
||||
func NewAuthService(db db.DB, features featuremgmt.FeatureToggles, dashSvc dashboards.DashboardService) *AuthService {
|
||||
return &AuthService{
|
||||
db: db,
|
||||
features: features,
|
||||
dashSvc: dashSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,26 +136,21 @@ func (authz *AuthService) dashboardsWithVisibleAnnotations(ctx context.Context,
|
||||
})
|
||||
}
|
||||
|
||||
sb := &searchstore.Builder{Dialect: authz.db.GetDialect(), Filters: filters, Features: authz.features}
|
||||
// This is a limit for a batch size, not for the end query result.
|
||||
var limit int64 = 1000
|
||||
if query.Page == 0 {
|
||||
query.Page = 1
|
||||
}
|
||||
sql, params := sb.ToSQL(limit, query.Page)
|
||||
|
||||
visibleDashboards := make(map[string]int64)
|
||||
var res []dashboardProjection
|
||||
|
||||
err = authz.db.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
return sess.SQL(sql, params...).Find(&res)
|
||||
dashs, err := authz.dashSvc.SearchDashboards(ctx, &dashboards.FindPersistedDashboardsQuery{
|
||||
OrgId: query.SignedInUser.GetOrgID(),
|
||||
Filters: filters,
|
||||
SignedInUser: query.SignedInUser,
|
||||
Page: query.Page,
|
||||
Type: filterType,
|
||||
Limit: 1000,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, p := range res {
|
||||
visibleDashboards[p.UID] = p.ID
|
||||
visibleDashboards := make(map[string]int64)
|
||||
for _, d := range dashs {
|
||||
visibleDashboards[d.UID] = d.ID
|
||||
}
|
||||
|
||||
return visibleDashboards, nil
|
||||
|
||||
Reference in New Issue
Block a user