API: Support creating a nested folder (#58508)

* API: Support nested folder creation

* Update swagger

* fixup

* Update pkg/api/dtos/folder.go

Co-authored-by: Serge Zaitsev <serge.zaitsev@grafana.com>

* Fix some tests

* create legacy folder url from title and uid

Co-authored-by: idafurjes <36131195+idafurjes@users.noreply.github.com>
Co-authored-by: Serge Zaitsev <serge.zaitsev@grafana.com>
Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com>
This commit is contained in:
Sofia Papagiannaki
2022-11-10 04:41:03 -05:00
committed by GitHub
co-authored by Serge Zaitsev idafurjes Ida Furjesova
parent b5388bb080
commit bf5a08e039
21 changed files with 452 additions and 137 deletions
+44 -2
View File
@@ -3,6 +3,7 @@ package folder
import (
"time"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/util/errutil"
)
@@ -33,7 +34,17 @@ type Folder struct {
// TODO: validate if this field is required/relevant to folders.
// currently there is no such column
// Version int
// Url string
// UpdatedBy int64
// CreatedBy int64
// HasACL bool
}
type FolderDTO struct {
Folder
Children []FolderDTO
}
// NewFolder tales a title and returns a Folder with the Created and Updated
@@ -51,7 +62,7 @@ func NewFolder(title string, description string) *Folder {
// to create a folder.
type CreateFolderCommand struct {
UID string `json:"uid"`
OrgID int64 `json:"orgId"`
OrgID int64 `json:"-"`
Title string `json:"title"`
Description string `json:"description"`
ParentUID string `json:"parent_uid"`
@@ -72,7 +83,7 @@ type UpdateFolderCommand struct {
type MoveFolderCommand struct {
UID string `json:"uid"`
NewParentUID string `json:"new_parent_uid"`
OrgID int64 `json:"orgId"`
OrgID int64 `json:"-"`
}
// DeleteFolderCommand captures the information required by the folder service
@@ -113,3 +124,34 @@ type GetTreeQuery struct {
Limit int64
Page int64
}
// ToLegacyModel is temporary until the two folder services are merged
func (f *Folder) ToLegacyModel() *models.Folder {
return &models.Folder{
Id: f.ID,
Uid: f.UID,
Title: f.Title,
Url: models.GetFolderUrl(f.UID, models.SlugifyTitle(f.Title)),
Version: 0,
Created: f.Created,
Updated: f.Updated,
UpdatedBy: 0,
CreatedBy: 0,
HasACL: false,
}
}
func FromDashboard(dash *models.Dashboard) *Folder {
return &Folder{
ID: dash.Id,
UID: dash.Uid,
Title: dash.Title,
//HasACL: dash.HasACL,
//Url: dash.GetUrl(),
//Version: dash.Version,
Created: dash.Created,
//CreatedBy: dash.CreatedBy,
Updated: dash.Updated,
//UpdatedBy: dash.UpdatedBy,
}
}