Alerting: Export and provisioning rules into subfolders (#77450)

* Folders: Optionally include fullpath in service responses
* Alerting: Export folder fullpath instead of title
* Escape separator in folder title
* Add support for provisiong alret rules into subfolders
* Use FolderService for creating folders during provisioning
* Export WithFullpath() folder service function

---------

Co-authored-by: Tania B <yalyna.ts@gmail.com>
Co-authored-by: Yuri Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
Sofia Papagiannaki
2024-05-31 11:09:20 +03:00
committed by GitHub
co-authored by Tania B Yuri Tseretyan
parent e1aedb65b3
commit 17ca61d7f8
21 changed files with 435 additions and 164 deletions
+32
View File
@@ -34,6 +34,8 @@ import (
"github.com/grafana/grafana/pkg/util"
)
const FULLPATH_SEPARATOR = "/"
type Service struct {
store store
db db.DB
@@ -1109,6 +1111,36 @@ func (s *Service) buildSaveDashboardCommand(ctx context.Context, dto *dashboards
return cmd, nil
}
// SplitFullpath splits a string into an array of strings using the FULLPATH_SEPARATOR as the delimiter.
// It handles escape characters by appending the separator and the new string if the current string ends with an escape character.
// The resulting array does not contain empty strings.
func SplitFullpath(s string) []string {
splitStrings := strings.Split(s, FULLPATH_SEPARATOR)
result := make([]string, 0)
current := ""
for _, str := range splitStrings {
if strings.HasSuffix(current, "\\") {
// If the current string ends with an escape character, append the separator and the new string
current = current[:len(current)-1] + FULLPATH_SEPARATOR + str
} else {
// If the current string does not end with an escape character, append the current string to the result and start a new current string
if current != "" {
result = append(result, current)
}
current = str
}
}
// Append the last string to the result
if current != "" {
result = append(result, current)
}
return result
}
// getGuardianForSavePermissionCheck returns the guardian to be used for checking permission of dashboard
// It replaces deleted Dashboard.GetDashboardIdForSavePermissionCheck()
func getGuardianForSavePermissionCheck(ctx context.Context, d *dashboards.Dashboard, user identity.Requester) (guardian.DashboardGuardian, error) {