mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Nested folders: Fix API response ordering when fetching subfolders (#67258)
* Nested folders: Fix ordering when getting subfolders * Update endpoint swagger description * Modify test
This commit is contained in:
parent
7c5210a915
commit
893bf08dcf
@ -28,7 +28,9 @@ import (
|
||||
//
|
||||
// Returns all folders that the authenticated user has permission to view.
|
||||
// If nested folders are enabled, it expects an additional query parameter with the parent folder UID
|
||||
// and returns the immediate subfolders.
|
||||
// and returns the immediate subfolders that the authenticated user has permission to view.
|
||||
// If the parameter is not supplied then it returns immediate subfolders under the root
|
||||
// that the authenticated user has permission to view.
|
||||
//
|
||||
// Responses:
|
||||
// 200: getFoldersResponse
|
||||
|
@ -239,10 +239,10 @@ func (ss *sqlStore) GetChildren(ctx context.Context, q folder.GetChildrenQuery)
|
||||
sql := strings.Builder{}
|
||||
args := make([]interface{}, 0, 2)
|
||||
if q.UID == "" {
|
||||
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=?"))
|
||||
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid IS NULL AND org_id=? ORDER BY title ASC"))
|
||||
args = append(args, q.OrgID)
|
||||
} else {
|
||||
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid=? AND org_id=?"))
|
||||
sql.Write([]byte("SELECT * FROM folder WHERE parent_uid=? AND org_id=? ORDER BY title ASC"))
|
||||
args = append(args, q.UID, q.OrgID)
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package folderimpl
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@ -544,6 +545,7 @@ func TestIntegrationGetChildren(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
treeLeaves := CreateLeaves(t, folderStore, parent, 8)
|
||||
sort.Strings(treeLeaves)
|
||||
|
||||
t.Cleanup(func() {
|
||||
for _, uid := range treeLeaves {
|
||||
@ -768,9 +770,10 @@ func CreateLeaves(t *testing.T, store *sqlStore, parent *folder.Folder, num int)
|
||||
|
||||
leaves := make([]string, 0)
|
||||
for i := 0; i < num; i++ {
|
||||
uid := util.GenerateShortUID()
|
||||
f, err := store.Create(context.Background(), folder.CreateFolderCommand{
|
||||
Title: fmt.Sprintf("folder-%d", i),
|
||||
UID: util.GenerateShortUID(),
|
||||
Title: fmt.Sprintf("folder-%s", uid),
|
||||
UID: uid,
|
||||
OrgID: parent.OrgID,
|
||||
ParentUID: parent.UID,
|
||||
})
|
||||
|
@ -5404,7 +5404,7 @@
|
||||
},
|
||||
"/folders": {
|
||||
"get": {
|
||||
"description": "Returns all folders that the authenticated user has permission to view.\nIf nested folders are enabled, it expects an additional query parameter with the parent folder UID\nand returns the immediate subfolders.",
|
||||
"description": "Returns all folders that the authenticated user has permission to view.\nIf nested folders are enabled, it expects an additional query parameter with the parent folder UID\nand returns the immediate subfolders that the authenticated user has permission to view.\nIf the parameter is not supplied then it returns immediate subfolders under the root\nthat the authenticated user has permission to view.",
|
||||
"tags": [
|
||||
"folders"
|
||||
],
|
||||
@ -11885,6 +11885,13 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"ChildrenCounts": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
},
|
||||
"ConfFloat64": {
|
||||
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
||||
"type": "number",
|
||||
@ -13594,13 +13601,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"FolderChildrenCounts": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
},
|
||||
"FolderSearchHit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@ -20344,7 +20344,7 @@
|
||||
"getFolderChildrenCountsResponse": {
|
||||
"description": "(empty)",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/FolderChildrenCounts"
|
||||
"$ref": "#/definitions/ChildrenCounts"
|
||||
}
|
||||
},
|
||||
"getFolderPermissionListResponse": {
|
||||
|
@ -796,7 +796,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/FolderChildrenCounts"
|
||||
"$ref": "#/components/schemas/ChildrenCounts"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -2952,6 +2952,13 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"ChildrenCounts": {
|
||||
"additionalProperties": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"ConfFloat64": {
|
||||
"description": "ConfFloat64 is a float64. It Marshals float64 values of NaN of Inf\nto null.",
|
||||
"format": "double",
|
||||
@ -4661,13 +4668,6 @@
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"FolderChildrenCounts": {
|
||||
"additionalProperties": {
|
||||
"format": "int64",
|
||||
"type": "integer"
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"FolderSearchHit": {
|
||||
"properties": {
|
||||
"id": {
|
||||
@ -16759,7 +16759,7 @@
|
||||
},
|
||||
"/folders": {
|
||||
"get": {
|
||||
"description": "Returns all folders that the authenticated user has permission to view.\nIf nested folders are enabled, it expects an additional query parameter with the parent folder UID\nand returns the immediate subfolders.",
|
||||
"description": "Returns all folders that the authenticated user has permission to view.\nIf nested folders are enabled, it expects an additional query parameter with the parent folder UID\nand returns the immediate subfolders that the authenticated user has permission to view.\nIf the parameter is not supplied then it returns immediate subfolders under the root\nthat the authenticated user has permission to view.",
|
||||
"operationId": "getFolders",
|
||||
"parameters": [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user