diff --git a/pkg/api/folder.go b/pkg/api/folder.go index ad15d5371ad..1f510d4396b 100644 --- a/pkg/api/folder.go +++ b/pkg/api/folder.go @@ -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 diff --git a/pkg/services/folder/folderimpl/sqlstore.go b/pkg/services/folder/folderimpl/sqlstore.go index 30d1256dd70..badf2fc272a 100644 --- a/pkg/services/folder/folderimpl/sqlstore.go +++ b/pkg/services/folder/folderimpl/sqlstore.go @@ -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) } diff --git a/pkg/services/folder/folderimpl/sqlstore_test.go b/pkg/services/folder/folderimpl/sqlstore_test.go index d5a032dd3d6..b8f45eb85f1 100644 --- a/pkg/services/folder/folderimpl/sqlstore_test.go +++ b/pkg/services/folder/folderimpl/sqlstore_test.go @@ -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, }) diff --git a/public/api-merged.json b/public/api-merged.json index 93e06f99ba1..8dec040b7ee 100644 --- a/public/api-merged.json +++ b/public/api-merged.json @@ -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": { diff --git a/public/openapi3.json b/public/openapi3.json index 635e242ae6e..bbdca11f0f6 100644 --- a/public/openapi3.json +++ b/public/openapi3.json @@ -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": [ {