mirror of
https://github.com/grafana/grafana.git
synced 2026-08-13 06:34:55 -05:00
Access control: Modify dashboard/folder resolvers so that return also the inherited scopes (#62025)
* Access Control: Add folder service dependency to the dashboard/folder resolvers * Expose the function fetching parents to folder interface * Add generic prepend utility * Modify dashboard resolvers to return inherited scopes
This commit is contained in:
@@ -51,8 +51,6 @@ func ProvideService(
|
||||
features featuremgmt.FeatureToggles,
|
||||
folderPermissionsService accesscontrol.FolderPermissionsService,
|
||||
) folder.Service {
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewFolderNameScopeResolver(dashboardStore, folderStore))
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewFolderIDScopeResolver(dashboardStore, folderStore))
|
||||
store := ProvideStore(db, cfg, features)
|
||||
svr := &Service{
|
||||
cfg: cfg,
|
||||
@@ -68,6 +66,9 @@ func ProvideService(
|
||||
if features.IsEnabled(featuremgmt.FlagNestedFolders) {
|
||||
svr.DBMigration(db)
|
||||
}
|
||||
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewFolderNameScopeResolver(dashboardStore, folderStore, svr))
|
||||
ac.RegisterScopeAttributeResolver(dashboards.NewFolderIDScopeResolver(dashboardStore, folderStore, svr))
|
||||
return svr
|
||||
}
|
||||
|
||||
@@ -185,6 +186,13 @@ func (s *Service) GetChildren(ctx context.Context, cmd *folder.GetChildrenQuery)
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetParents(ctx context.Context, q folder.GetParentsQuery) ([]*folder.Folder, error) {
|
||||
if !s.features.IsEnabled(featuremgmt.FlagNestedFolders) {
|
||||
return nil, nil
|
||||
}
|
||||
return s.store.GetParents(ctx, q)
|
||||
}
|
||||
|
||||
func (s *Service) getFolderByID(ctx context.Context, user *user.SignedInUser, id int64, orgID int64) (*folder.Folder, error) {
|
||||
if id == 0 {
|
||||
return &folder.Folder{ID: id, Title: "General"}, nil
|
||||
|
||||
@@ -21,6 +21,11 @@ var _ folder.Service = (*FakeService)(nil)
|
||||
func (s *FakeService) GetChildren(ctx context.Context, cmd *folder.GetChildrenQuery) ([]*folder.Folder, error) {
|
||||
return s.ExpectedFolders, s.ExpectedError
|
||||
}
|
||||
|
||||
func (s *FakeService) GetParents(ctx context.Context, q folder.GetParentsQuery) ([]*folder.Folder, error) {
|
||||
return s.ExpectedFolders, s.ExpectedError
|
||||
}
|
||||
|
||||
func (s *FakeService) Create(ctx context.Context, cmd *folder.CreateFolderCommand) (*folder.Folder, error) {
|
||||
return s.ExpectedFolder, s.ExpectedError
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import (
|
||||
type Service interface {
|
||||
// GetChildren returns an array containing all child folders.
|
||||
GetChildren(ctx context.Context, cmd *GetChildrenQuery) ([]*Folder, error)
|
||||
// GetParents returns an array containing add parent folders if nested folders are enabled
|
||||
// otherwise it returns an empty array
|
||||
GetParents(ctx context.Context, q GetParentsQuery) ([]*Folder, error)
|
||||
Create(ctx context.Context, cmd *CreateFolderCommand) (*Folder, error)
|
||||
|
||||
// GetFolder takes a GetFolderCommand and returns a folder matching the
|
||||
|
||||
Reference in New Issue
Block a user