acl_service.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package dashboards
  2. import (
  3. "github.com/grafana/grafana/pkg/bus"
  4. "github.com/grafana/grafana/pkg/models"
  5. "time"
  6. )
  7. func MakeUserAdmin(bus bus.Bus, orgId int64, userId int64, dashboardId int64, setViewAndEditPermissions bool) error {
  8. rtEditor := models.ROLE_EDITOR
  9. rtViewer := models.ROLE_VIEWER
  10. items := []*models.DashboardAcl{
  11. {
  12. OrgId: orgId,
  13. DashboardId: dashboardId,
  14. UserId: userId,
  15. Permission: models.PERMISSION_ADMIN,
  16. Created: time.Now(),
  17. Updated: time.Now(),
  18. },
  19. }
  20. if setViewAndEditPermissions {
  21. items = append(items,
  22. &models.DashboardAcl{
  23. OrgId: orgId,
  24. DashboardId: dashboardId,
  25. Role: &rtEditor,
  26. Permission: models.PERMISSION_EDIT,
  27. Created: time.Now(),
  28. Updated: time.Now(),
  29. },
  30. &models.DashboardAcl{
  31. OrgId: orgId,
  32. DashboardId: dashboardId,
  33. Role: &rtViewer,
  34. Permission: models.PERMISSION_VIEW,
  35. Created: time.Now(),
  36. Updated: time.Now(),
  37. },
  38. )
  39. }
  40. aclCmd := &models.UpdateDashboardAclCommand{
  41. DashboardId: dashboardId,
  42. Items: items,
  43. }
  44. if err := bus.Dispatch(aclCmd); err != nil {
  45. return err
  46. }
  47. return nil
  48. }