Chore: Moves common and response into separate packages (#30298)
* Chore: moves common and response into separate packages * Chore: moves common and response into separate packages * Update pkg/api/utils/common.go Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Chore: changes after PR comments * Chore: move wrap to routing package * Chore: move functions in common to response package * Chore: move functions in common to response package * Chore: formats imports Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
co-authored by
Arve Knudsen
parent
a94c256516
commit
3d41267fc4
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func (hs *HTTPServer) GetFolderPermissionList(c *models.ReqContext) Response {
|
||||
func (hs *HTTPServer) GetFolderPermissionList(c *models.ReqContext) response.Response {
|
||||
s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
|
||||
folder, err := s.GetFolderByUID(c.Params(":uid"))
|
||||
|
||||
@@ -28,7 +29,7 @@ func (hs *HTTPServer) GetFolderPermissionList(c *models.ReqContext) Response {
|
||||
|
||||
acl, err := g.GetAcl()
|
||||
if err != nil {
|
||||
return Error(500, "Failed to get folder permissions", err)
|
||||
return response.Error(500, "Failed to get folder permissions", err)
|
||||
}
|
||||
|
||||
filteredAcls := make([]*models.DashboardAclInfoDTO, 0, len(acl))
|
||||
@@ -53,12 +54,12 @@ func (hs *HTTPServer) GetFolderPermissionList(c *models.ReqContext) Response {
|
||||
filteredAcls = append(filteredAcls, perm)
|
||||
}
|
||||
|
||||
return JSON(200, filteredAcls)
|
||||
return response.JSON(200, filteredAcls)
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext, apiCmd dtos.UpdateDashboardAclCommand) Response {
|
||||
func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext, apiCmd dtos.UpdateDashboardAclCommand) response.Response {
|
||||
if err := validatePermissionsUpdate(apiCmd); err != nil {
|
||||
return Error(400, err.Error(), err)
|
||||
return response.Error(400, err.Error(), err)
|
||||
}
|
||||
|
||||
s := dashboards.NewFolderService(c.OrgId, c.SignedInUser)
|
||||
@@ -96,7 +97,7 @@ func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext, apiCmd dtos.
|
||||
|
||||
hiddenACL, err := g.GetHiddenACL(hs.Cfg)
|
||||
if err != nil {
|
||||
return Error(500, "Error while retrieving hidden permissions", err)
|
||||
return response.Error(500, "Error while retrieving hidden permissions", err)
|
||||
}
|
||||
cmd.Items = append(cmd.Items, hiddenACL...)
|
||||
|
||||
@@ -104,13 +105,13 @@ func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext, apiCmd dtos.
|
||||
if err != nil {
|
||||
if errors.Is(err, guardian.ErrGuardianPermissionExists) ||
|
||||
errors.Is(err, guardian.ErrGuardianOverride) {
|
||||
return Error(400, err.Error(), err)
|
||||
return response.Error(400, err.Error(), err)
|
||||
}
|
||||
|
||||
return Error(500, "Error while checking folder permissions", err)
|
||||
return response.Error(500, "Error while checking folder permissions", err)
|
||||
}
|
||||
|
||||
return Error(403, "Cannot remove own admin permission for a folder", nil)
|
||||
return response.Error(403, "Cannot remove own admin permission for a folder", nil)
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
@@ -122,13 +123,13 @@ func (hs *HTTPServer) UpdateFolderPermissions(c *models.ReqContext, apiCmd dtos.
|
||||
}
|
||||
|
||||
if errors.Is(err, models.ErrFolderAclInfoMissing) || errors.Is(err, models.ErrFolderPermissionFolderEmpty) {
|
||||
return Error(409, err.Error(), err)
|
||||
return response.Error(409, err.Error(), err)
|
||||
}
|
||||
|
||||
return Error(500, "Failed to create permission", err)
|
||||
return response.Error(500, "Failed to create permission", err)
|
||||
}
|
||||
|
||||
return JSON(200, util.DynMap{
|
||||
return response.JSON(200, util.DynMap{
|
||||
"message": "Folder permissions updated",
|
||||
"id": folder.Id,
|
||||
"title": folder.Title,
|
||||
|
||||
Reference in New Issue
Block a user