Files
grafana/pkg/services/folder/store.go
Rafael Bortolon Paulovic e69f3c55f7 fix: delete folders using postorder (#113493)
* fix: delete folders using postorder

* chore: use helper function and do not add method to Folder store

- addresses other review comments fixing log messages and cleans up the unit tests

* chore: run library element tests on modes 2,3,5 only

* chore: adjust to folder.SortByPostorder(folders []*Folder)

* chore: run library panels tests in mode 2,3,5 only

* chore: run tests in all modes and increase timeout

- adjusting the modes and tweaking configs will be done separately
2025-11-06 15:04:34 +01:00

55 lines
2.2 KiB
Go

package folder
import (
"context"
)
type GetFoldersFromStoreQuery struct {
GetFoldersQuery
AncestorUIDs []string
}
func NewGetFoldersQuery(q GetFoldersQuery) GetFoldersFromStoreQuery {
return GetFoldersFromStoreQuery{
GetFoldersQuery: q,
AncestorUIDs: []string{},
}
}
// Store is the interface which a folder Store must implement.
type Store interface {
// Create creates a folder and returns the newly-created folder.
Create(ctx context.Context, cmd CreateFolderCommand) (*Folder, error)
// Delete folders with the specified UIDs and orgID from the folder store.
Delete(ctx context.Context, UIDs []string, orgID int64) error
// Update updates the given folder's UID, Title, and Description (update mode).
// If the NewParentUID field is not nil, it updates also the parent UID (move mode).
// If it's a non empty string, it moves the folder under the folder with the specific UID
// otherwise, it moves the folder under the root folder (parent_uid column is set to NULL).
Update(ctx context.Context, cmd UpdateFolderCommand) (*Folder, error)
// Get returns a folder.
Get(ctx context.Context, q GetFolderQuery) (*Folder, error)
// GetParents returns an ordered list of parent folder of the given folder.
GetParents(ctx context.Context, q GetParentsQuery) ([]*Folder, error)
// GetChildren returns the set of immediate children folders (depth=1) of the
// given folder.
GetChildren(ctx context.Context, q GetChildrenQuery) ([]*FolderReference, error)
// GetHeight returns the height of the folder tree. When parentUID is set, the function would
// verify in the meanwhile that parentUID is not present in the subtree of the folder with the given UID.
GetHeight(ctx context.Context, foldrUID string, orgID int64, parentUID *string) (int, error)
// GetFolders returns folders with given uids
GetFolders(ctx context.Context, q GetFoldersFromStoreQuery) ([]*Folder, error)
// GetDescendants returns all descendants of a folder (with no guaranteed order)
GetDescendants(ctx context.Context, orgID int64, anchestor_uid string) ([]*Folder, error)
// CountInOrg returns the number of folders in the given org
CountInOrg(ctx context.Context, orgID int64) (int64, error)
}