K8s: Folders: Modify GetChildren to return only Folder References (#103072)

* Return FolderReference instead of Folder on GetChildren

Signed-off-by: Maicon Costa <maiconscosta@gmail.com>

---------

Signed-off-by: Maicon Costa <maiconscosta@gmail.com>
This commit is contained in:
maicon
2025-04-02 01:30:17 -03:00
committed by GitHub
parent 654afbcfa2
commit d8c5c2d3b8
24 changed files with 107 additions and 104 deletions
+9 -23
View File
@@ -171,7 +171,7 @@ func (ss *FolderUnifiedStoreImpl) GetParents(ctx context.Context, q folder.GetPa
return hits, nil
}
func (ss *FolderUnifiedStoreImpl) GetChildren(ctx context.Context, q folder.GetChildrenQuery) ([]*folder.Folder, error) {
func (ss *FolderUnifiedStoreImpl) GetChildren(ctx context.Context, q folder.GetChildrenQuery) ([]*folder.FolderReference, error) {
// the general folder is saved as an empty string in the database
if q.UID == folder.GeneralFolderUID {
q.UID = ""
@@ -230,36 +230,22 @@ func (ss *FolderUnifiedStoreImpl) GetChildren(ctx context.Context, q folder.GetC
}
allowK6Folder := (q.SignedInUser != nil && q.SignedInUser.IsIdentityType(claims.TypeServiceAccount))
hits := make([]*folder.Folder, 0)
hits := make([]*folder.FolderReference, 0)
for _, item := range res.Hits {
// filter out k6 folders if request is not from a service account
if item.Name == accesscontrol.K6FolderUID && !allowK6Folder {
continue
}
// TODO: Remove this once we migrate the alerting use case.
// This is a temporary flag, and will be removed once we migrate the alerting use case to
// expect a folder ref too for children folders.
if q.RefOnly { // nolint:staticcheck
f := &folder.Folder{
ID: item.Field.GetNestedInt64(search.DASHBOARD_LEGACY_ID),
UID: item.Name,
Title: item.Title,
ParentUID: item.Folder,
}
if item.Field.GetNestedString(resource.SEARCH_FIELD_MANAGER_KIND) != "" {
f.ManagedBy = utils.ParseManagerKindString(item.Field.GetNestedString(resource.SEARCH_FIELD_MANAGER_KIND))
}
hits = append(hits, f)
continue
f := &folder.FolderReference{
ID: item.Field.GetNestedInt64(search.DASHBOARD_LEGACY_ID),
UID: item.Name,
Title: item.Title,
ParentUID: item.Folder,
}
// search only returns a subset of info, get all info of the folder
f, err := ss.Get(ctx, folder.GetFolderQuery{UID: &item.Name, OrgID: q.OrgID})
if err != nil {
return nil, err
if item.Field.GetNestedString(resource.SEARCH_FIELD_MANAGER_KIND) != "" {
f.ManagedBy = utils.ParseManagerKindString(item.Field.GetNestedString(resource.SEARCH_FIELD_MANAGER_KIND))
}
hits = append(hits, f)