2017-05-08 08:35:34 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
2017-06-09 14:56:13 -05:00
|
|
|
"github.com/grafana/grafana/pkg/metrics"
|
2017-05-08 08:35:34 -05:00
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
|
"github.com/grafana/grafana/pkg/services/guardian"
|
|
|
|
"github.com/grafana/grafana/pkg/util"
|
|
|
|
)
|
|
|
|
|
2017-06-19 17:11:30 -05:00
|
|
|
func GetDashboardAclList(c *middleware.Context) Response {
|
|
|
|
dashId := c.ParamsInt64(":dashboardId")
|
2017-05-08 08:35:34 -05:00
|
|
|
|
2017-06-19 12:47:44 -05:00
|
|
|
guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
|
|
|
|
|
|
|
|
if canView, err := guardian.CanView(); err != nil || !canView {
|
|
|
|
return dashboardGuardianResponse(err)
|
2017-05-08 08:35:34 -05:00
|
|
|
}
|
|
|
|
|
2017-06-19 16:30:54 -05:00
|
|
|
query := m.GetDashboardAclInfoListQuery{DashboardId: dashId}
|
2017-05-08 08:35:34 -05:00
|
|
|
if err := bus.Dispatch(&query); err != nil {
|
|
|
|
return ApiError(500, "Failed to get Dashboard ACL", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return Json(200, &query.Result)
|
|
|
|
}
|
2017-05-22 03:36:47 -05:00
|
|
|
|
2017-06-19 16:15:25 -05:00
|
|
|
func PostDashboardAcl(c *middleware.Context, cmd m.SetDashboardAclCommand) Response {
|
2017-06-19 12:47:44 -05:00
|
|
|
dashId := c.ParamsInt64(":id")
|
|
|
|
|
|
|
|
guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
|
|
|
|
if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
|
return dashboardGuardianResponse(err)
|
|
|
|
}
|
|
|
|
|
2017-06-09 14:56:13 -05:00
|
|
|
cmd.OrgId = c.OrgId
|
2017-06-19 12:47:44 -05:00
|
|
|
cmd.DashboardId = dashId
|
2017-06-09 14:56:13 -05:00
|
|
|
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
2017-06-19 17:19:58 -05:00
|
|
|
if err == m.ErrDashboardAclInfoMissing {
|
2017-06-14 16:45:30 -05:00
|
|
|
return ApiError(409, err.Error(), err)
|
2017-06-09 14:56:13 -05:00
|
|
|
}
|
|
|
|
return ApiError(500, "Failed to create permission", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
metrics.M_Api_Dashboard_Acl_Create.Inc(1)
|
|
|
|
|
|
|
|
return Json(200, &util.DynMap{
|
|
|
|
"permissionId": cmd.Result.Id,
|
|
|
|
"message": "Permission created",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-19 17:11:30 -05:00
|
|
|
func DeleteDashboardAcl(c *middleware.Context) Response {
|
|
|
|
dashId := c.ParamsInt64(":dashboardId")
|
|
|
|
aclId := c.ParamsInt64(":aclId")
|
2017-06-19 12:47:44 -05:00
|
|
|
|
|
|
|
guardian := guardian.NewDashboardGuardian(dashId, c.OrgId, c.SignedInUser)
|
|
|
|
if canSave, err := guardian.CanSave(); err != nil || !canSave {
|
|
|
|
return dashboardGuardianResponse(err)
|
|
|
|
}
|
|
|
|
|
2017-06-19 17:11:30 -05:00
|
|
|
cmd := m.RemoveDashboardAclCommand{OrgId: c.OrgId, AclId: aclId}
|
2017-06-19 12:47:44 -05:00
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
|
|
|
return ApiError(500, "Failed to delete permission for user", err)
|
|
|
|
}
|
2017-05-22 03:36:47 -05:00
|
|
|
|
|
|
|
return Json(200, "")
|
|
|
|
}
|