dashboard_acl.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 user group 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. UserGroupId int64
  32. Permission PermissionType
  33. Created time.Time
  34. Updated time.Time
  35. }
  36. type DashboardAclInfoDTO struct {
  37. Id int64 `json:"id"`
  38. OrgId int64 `json:"-"`
  39. DashboardId int64 `json:"dashboardId"`
  40. Created time.Time `json:"created"`
  41. Updated time.Time `json:"updated"`
  42. UserId int64 `json:"userId"`
  43. UserLogin string `json:"userLogin"`
  44. UserEmail string `json:"userEmail"`
  45. UserGroupId int64 `json:"userGroupId"`
  46. UserGroup string `json:"userGroup"`
  47. Role RoleType `json:"role"`
  48. Permission PermissionType `json:"permission"`
  49. PermissionName string `json:"permissionName"`
  50. }
  51. //
  52. // COMMANDS
  53. //
  54. type SetDashboardAclCommand struct {
  55. DashboardId int64 `json:"-"`
  56. OrgId int64 `json:"-"`
  57. UserId int64 `json:"userId"`
  58. UserGroupId int64 `json:"userGroupId"`
  59. Permission PermissionType `json:"permission" binding:"Required"`
  60. Result DashboardAcl `json:"-"`
  61. }
  62. type RemoveDashboardAclCommand struct {
  63. AclId int64
  64. OrgId int64
  65. }
  66. //
  67. // QUERIES
  68. //
  69. type GetDashboardAclInfoListQuery struct {
  70. DashboardId int64
  71. Result []*DashboardAclInfoDTO
  72. }
  73. // Returns dashboard acl list items and parent folder items
  74. type GetInheritedDashboardAclQuery struct {
  75. DashboardId int64
  76. OrgId int64
  77. Result []*DashboardAcl
  78. }