mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Folders: Allow listing folders with write permission (#83527)
* Folders: Allow listing folders with write permission * Check for subfolder access if parent does not have * Add test * GetFolders: fix ordering * Apply suggestion from code review
This commit is contained in:
committed by
GitHub
parent
39232a0776
commit
1208888bb6
@@ -43,12 +43,18 @@ const REDACTED = "redacted"
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetFolders(c *contextmodel.ReqContext) response.Response {
|
||||
permission := dashboardaccess.PERMISSION_VIEW
|
||||
if c.Query("permission") == "Edit" {
|
||||
permission = dashboardaccess.PERMISSION_EDIT
|
||||
}
|
||||
|
||||
if hs.Features.IsEnabled(c.Req.Context(), featuremgmt.FlagNestedFolders) {
|
||||
q := &folder.GetChildrenQuery{
|
||||
OrgID: c.SignedInUser.GetOrgID(),
|
||||
Limit: c.QueryInt64("limit"),
|
||||
Page: c.QueryInt64("page"),
|
||||
UID: c.Query("parentUid"),
|
||||
Permission: permission,
|
||||
SignedInUser: c.SignedInUser,
|
||||
}
|
||||
|
||||
@@ -71,7 +77,7 @@ func (hs *HTTPServer) GetFolders(c *contextmodel.ReqContext) response.Response {
|
||||
return response.JSON(http.StatusOK, hits)
|
||||
}
|
||||
|
||||
hits, err := hs.searchFolders(c)
|
||||
hits, err := hs.searchFolders(c, permission)
|
||||
if err != nil {
|
||||
return apierrors.ToFolderErrorResponse(err)
|
||||
}
|
||||
@@ -448,7 +454,7 @@ func (hs *HTTPServer) getFolderACMetadata(c *contextmodel.ReqContext, f *folder.
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) searchFolders(c *contextmodel.ReqContext) ([]dtos.FolderSearchHit, error) {
|
||||
func (hs *HTTPServer) searchFolders(c *contextmodel.ReqContext, permission dashboardaccess.PermissionType) ([]dtos.FolderSearchHit, error) {
|
||||
searchQuery := search.Query{
|
||||
SignedInUser: c.SignedInUser,
|
||||
DashboardIds: make([]int64, 0),
|
||||
@@ -456,7 +462,7 @@ func (hs *HTTPServer) searchFolders(c *contextmodel.ReqContext) ([]dtos.FolderSe
|
||||
Limit: c.QueryInt64("limit"),
|
||||
OrgId: c.SignedInUser.GetOrgID(),
|
||||
Type: "dash-folder",
|
||||
Permission: dashboardaccess.PERMISSION_VIEW,
|
||||
Permission: permission,
|
||||
Page: c.QueryInt64("page"),
|
||||
}
|
||||
|
||||
@@ -494,6 +500,12 @@ type GetFoldersParams struct {
|
||||
// in:query
|
||||
// required:false
|
||||
ParentUID string `json:"parentUid"`
|
||||
// Set to `Edit` to return folders that the user can edit
|
||||
// in:query
|
||||
// required: false
|
||||
// default:View
|
||||
// Enum: Edit,View
|
||||
Permission string `json:"permission"`
|
||||
}
|
||||
|
||||
// swagger:parameters getFolderByUID
|
||||
|
||||
Reference in New Issue
Block a user