WIP: folder api. #10630

This commit is contained in:
Marcus Efraimsson
2018-01-29 13:51:01 +01:00
parent ee57ed10f9
commit f08932b78a
10 changed files with 725 additions and 47 deletions

View File

@@ -130,6 +130,11 @@ func getDashboardHelper(orgId int64, slug string, id int64) (*m.Dashboard, Respo
if err := bus.Dispatch(&query); err != nil {
return nil, ApiError(404, "Dashboard not found", err)
}
if query.Result.IsFolder {
return nil, ApiError(404, "Dashboard not found", m.ErrDashboardNotFound)
}
return query.Result, nil
}
@@ -164,6 +169,11 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
// if new dashboard, use parent folder permissions instead
if dashId == 0 {
dashId = cmd.FolderId
} else {
_, rsp := getDashboardHelper(c.OrgId, "", dashId)
if rsp != nil {
return rsp
}
}
guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
@@ -439,19 +449,3 @@ func GetDashboardTags(c *middleware.Context) {
c.JSON(200, query.Result)
}
func GetFoldersForSignedInUser(c *middleware.Context) Response {
title := c.Query("query")
query := m.GetFoldersForSignedInUserQuery{
OrgId: c.OrgId,
SignedInUser: c.SignedInUser,
Title: title,
}
err := bus.Dispatch(&query)
if err != nil {
return ApiError(500, "Failed to get folders from database", err)
}
return Json(200, query.Result)
}