From 82e3e2e5582c49fa793cb9a0c143b7b76cbdfb58 Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:17:41 +0000 Subject: [PATCH] LibraryPanels/RBAC: Fix issue where folder scopes weren't being correctly inherited (#82700) --- pkg/services/libraryelements/database.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/services/libraryelements/database.go b/pkg/services/libraryelements/database.go index f067881a830..b8c09c12816 100644 --- a/pkg/services/libraryelements/database.go +++ b/pkg/services/libraryelements/database.go @@ -21,6 +21,7 @@ import ( "github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/search" "github.com/grafana/grafana/pkg/services/sqlstore/migrator" + "github.com/grafana/grafana/pkg/services/sqlstore/searchstore" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/util" ) @@ -283,7 +284,7 @@ func (l *LibraryElementService) getLibraryElements(c context.Context, store db.D builder := db.NewSqlBuilder(cfg, features, store.GetDialect(), recursiveQueriesAreSupported) builder.Write(selectLibraryElementDTOWithMeta) builder.Write(", ? as folder_name ", cmd.FolderName) - builder.Write(", '' as folder_uid ") + builder.Write(", COALESCE((SELECT folder.uid FROM folder WHERE folder.id = le.folder_id), '') as folder_uid ") builder.Write(getFromLibraryElementDTOWithMeta(store.GetDialect())) metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc() // nolint:staticcheck @@ -295,7 +296,7 @@ func (l *LibraryElementService) getLibraryElements(c context.Context, store db.D builder.Write(getFromLibraryElementDTOWithMeta(store.GetDialect())) builder.Write(" INNER JOIN dashboard AS dashboard on le.folder_id = dashboard.id AND le.folder_id <> 0") writeParamSelectorSQL(&builder, params...) - builder.WriteDashboardPermissionFilter(signedInUser, dashboardaccess.PERMISSION_VIEW, "") + builder.WriteDashboardPermissionFilter(signedInUser, dashboardaccess.PERMISSION_VIEW, searchstore.TypeFolder) builder.Write(` OR dashboard.id=0`) if err := session.SQL(builder.GetSQLString(), builder.GetParams()...).Find(&libraryElements); err != nil { return err @@ -321,11 +322,15 @@ func (l *LibraryElementService) getLibraryElements(c context.Context, store db.D } metrics.MFolderIDsServiceCount.WithLabelValues(metrics.LibraryElements).Inc() + folderUID := libraryElement.FolderUID + if libraryElement.FolderID == 0 { // nolint:staticcheck + folderUID = ac.GeneralFolderUID + } leDtos[i] = model.LibraryElementDTO{ ID: libraryElement.ID, OrgID: libraryElement.OrgID, FolderID: libraryElement.FolderID, // nolint:staticcheck - FolderUID: libraryElement.FolderUID, + FolderUID: folderUID, UID: libraryElement.UID, Name: libraryElement.Name, Kind: libraryElement.Kind,