dashboard_acl.go 2.0 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. 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. UserGroupId int64 `json:"userGroupId"`
  47. UserGroup string `json:"userGroup"`
  48. Role *RoleType `json:"role,omitempty"`
  49. Permission PermissionType `json:"permission"`
  50. PermissionName string `json:"permissionName"`
  51. }
  52. //
  53. // COMMANDS
  54. //
  55. type UpdateDashboardAclCommand struct {
  56. DashboardId int64
  57. Items []*DashboardAcl
  58. }
  59. type SetDashboardAclCommand struct {
  60. DashboardId int64
  61. OrgId int64
  62. UserId int64
  63. UserGroupId int64
  64. Permission PermissionType
  65. Result DashboardAcl
  66. }
  67. type RemoveDashboardAclCommand struct {
  68. AclId int64
  69. OrgId int64
  70. }
  71. //
  72. // QUERIES
  73. //
  74. type GetDashboardAclInfoListQuery struct {
  75. DashboardId int64
  76. OrgId int64
  77. Result []*DashboardAclInfoDTO
  78. }