Dashboard/Folder permission fix session (#47174)

* Fix inherited scopes for dashboard to use folder uid

* Add inherited evaluators

* Slight modification of the commments

* Add test for inheritance

* Nit.

* extract shared function from tests

* Nit. Extra line

* Remove unused comment

Co-authored-by: Karl Persson <kalle.persson@grafana.com>
Co-authored-by: gamab <gabi.mabs@gmail.com>
This commit is contained in:
Jguer
2022-04-05 14:28:23 +02:00
committed by GitHub
co-authored by Karl Persson gamab
parent 910ed77e16
commit 90a94eab74
7 changed files with 150 additions and 32 deletions
@@ -169,13 +169,18 @@ func ProvideDashboardPermissions(
return nil
},
InheritedScopePrefixes: []string{"folders:uid:"},
InheritedScopesSolver: func(ctx context.Context, orgID int64, resourceID string) ([]string, error) {
dashboard, err := getDashboard(ctx, orgID, resourceID)
if err != nil {
return nil, err
}
if dashboard.FolderId > 0 {
return []string{dashboards.ScopeFoldersProvider.GetResourceScopeUID(dashboard.Uid)}, nil
query := &models.GetDashboardQuery{Id: dashboard.FolderId, OrgId: orgID}
if err := sql.GetDashboard(ctx, query); err != nil {
return nil, err
}
return []string{dashboards.ScopeFoldersProvider.GetResourceScopeUID(query.Result.Uid)}, nil
}
return []string{}, nil
},