dashboard_acl.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. type PermissionType int
  7. const (
  8. PERMISSION_VIEW PermissionType = 1 << iota
  9. PERMISSION_EDIT
  10. PERMISSION_ADMIN
  11. )
  12. func (p PermissionType) String() string {
  13. names := map[int]string{
  14. int(PERMISSION_VIEW): "View",
  15. int(PERMISSION_EDIT): "Edit",
  16. int(PERMISSION_ADMIN): "Admin",
  17. }
  18. return names[int(p)]
  19. }
  20. // Typed errors
  21. var (
  22. ErrDashboardAclInfoMissing = errors.New("User id and team id cannot both be empty for a dashboard permission.")
  23. ErrDashboardPermissionDashboardEmpty = errors.New("Dashboard Id must be greater than zero for a dashboard permission.")
  24. )
  25. // Dashboard ACL model
  26. type DashboardAcl struct {
  27. Id int64
  28. OrgId int64
  29. DashboardId int64
  30. UserId int64
  31. TeamId int64
  32. Role *RoleType // pointer to be nullable
  33. Permission PermissionType
  34. Created time.Time
  35. Updated time.Time
  36. }
  37. type DashboardAclInfoDTO struct {
  38. Id int64 `json:"id"`
  39. OrgId int64 `json:"-"`
  40. DashboardId int64 `json:"dashboardId"`
  41. Created time.Time `json:"created"`
  42. Updated time.Time `json:"updated"`
  43. UserId int64 `json:"userId"`
  44. UserLogin string `json:"userLogin"`
  45. UserEmail string `json:"userEmail"`
  46. TeamId int64 `json:"teamId"`
  47. Team string `json:"team"`
  48. Role *RoleType `json:"role,omitempty"`
  49. Permission PermissionType `json:"permission"`
  50. PermissionName string `json:"permissionName"`
  51. Uid string `json:"uid"`
  52. Title string `json:"title"`
  53. Slug string `json:"slug"`
  54. IsFolder bool `json:"isFolder"`
  55. Url string `json:"url"`
  56. }
  57. //
  58. // COMMANDS
  59. //
  60. type UpdateDashboardAclCommand struct {
  61. DashboardId int64
  62. Items []*DashboardAcl
  63. }
  64. type SetDashboardAclCommand struct {
  65. DashboardId int64
  66. OrgId int64
  67. UserId int64
  68. TeamId int64
  69. Permission PermissionType
  70. Result DashboardAcl
  71. }
  72. type RemoveDashboardAclCommand struct {
  73. AclId int64
  74. OrgId int64
  75. }
  76. //
  77. // QUERIES
  78. //
  79. type GetDashboardAclInfoListQuery struct {
  80. DashboardId int64
  81. OrgId int64
  82. Result []*DashboardAclInfoDTO
  83. }