Nested folders: Provide count of all descendant dashboards and folders (#67184)

* Add a method for getting descendant folders
* Include dashboard count for descendant folders
* Return subfolder count
* Replace references to children with descendants
* Update openapi specs
* Add test for descendant counts
* Add logging to GetDescendantCounts
This commit is contained in:
Arati R
2023-04-27 17:00:09 +02:00
committed by GitHub
parent 4d96afa979
commit a5206a1cda
9 changed files with 237 additions and 169 deletions

View File

@@ -299,19 +299,19 @@ func (hs *HTTPServer) DeleteFolder(c *contextmodel.ReqContext) response.Response
return response.JSON(http.StatusOK, "")
}
// swagger:route GET /folders/{folder_uid}/counts folders getFolderChildrenCounts
// swagger:route GET /folders/{folder_uid}/counts folders getFolderDescendantCounts
//
// Gets the count of each descendant of a folder by kind. The folder is identified by UID.
//
// Responses:
// 200: getFolderChildrenCountsResponse
// 200: getFolderDescendantCountsResponse
// 401: unauthorisedError
// 403: forbiddenError
// 404: notFoundError
// 500: internalServerError
func (hs *HTTPServer) GetFolderChildrenCounts(c *contextmodel.ReqContext) response.Response {
func (hs *HTTPServer) GetFolderDescendantCounts(c *contextmodel.ReqContext) response.Response {
uid := web.Params(c.Req)[":uid"]
counts, err := hs.folderService.GetChildrenCounts(c.Req.Context(), &folder.GetChildrenCountsQuery{OrgID: c.OrgID, UID: &uid, SignedInUser: c.SignedInUser})
counts, err := hs.folderService.GetDescendantCounts(c.Req.Context(), &folder.GetDescendantCountsQuery{OrgID: c.OrgID, UID: &uid, SignedInUser: c.SignedInUser})
if err != nil {
return apierrors.ToFolderErrorResponse(err)
}
@@ -546,16 +546,16 @@ type DeleteFolderResponse struct {
} `json:"body"`
}
// swagger:parameters getFolderChildrenCounts
type GetFolderChildrenCountsParams struct {
// swagger:parameters getFolderDescendantCounts
type GetFolderDescendantCountsParams struct {
// in:path
// required:true
FolderUID string `json:"folder_uid"`
}
// swagger:response getFolderChildrenCountsResponse
type GetFolderChildrenCountsResponse struct {
// swagger:response getFolderDescendantCountsResponse
type GetFolderDescendantCountsResponse struct {
// The response message
// in: body
Body folder.ChildrenCounts `json:"body"`
Body folder.DescendantCounts `json:"body"`
}