dashboard_acl.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. type PermissionType int
  7. const (
  8. PERMISSION_VIEW PermissionType = 1 << iota
  9. PERMISSION_READ_ONLY_EDIT
  10. PERMISSION_EDIT
  11. )
  12. func (p PermissionType) String() string {
  13. names := map[int]string{
  14. int(PERMISSION_VIEW): "View",
  15. int(PERMISSION_READ_ONLY_EDIT): "Read-only Edit",
  16. int(PERMISSION_EDIT): "Edit",
  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. )
  24. // Dashboard ACL model
  25. type DashboardAcl struct {
  26. Id int64
  27. OrgId int64
  28. DashboardId int64
  29. UserId int64
  30. UserGroupId int64
  31. Permissions PermissionType
  32. Created time.Time
  33. Updated time.Time
  34. }
  35. type DashboardAclInfoDTO struct {
  36. Id int64 `json:"id"`
  37. OrgId int64 `json:"-"`
  38. DashboardId int64 `json:"dashboardId"`
  39. Created time.Time `json:"created"`
  40. Updated time.Time `json:"updated"`
  41. UserId int64 `json:"userId"`
  42. UserLogin string `json:"userLogin"`
  43. UserEmail string `json:"userEmail"`
  44. UserGroupId int64 `json:"userGroupId"`
  45. UserGroup string `json:"userGroup"`
  46. Permissions PermissionType `json:"permissions"`
  47. PermissionName string `json:"permissionName"`
  48. }
  49. //
  50. // COMMANDS
  51. //
  52. type SetDashboardAclCommand struct {
  53. DashboardId int64 `json:"-"`
  54. OrgId int64 `json:"-"`
  55. UserId int64 `json:"userId"`
  56. UserGroupId int64 `json:"userGroupId"`
  57. Permissions PermissionType `json:"permissions" binding:"Required"`
  58. Result DashboardAcl `json:"-"`
  59. }
  60. type RemoveDashboardAclCommand struct {
  61. AclId int64
  62. OrgId int64
  63. }
  64. //
  65. // QUERIES
  66. //
  67. type GetDashboardAclInfoListQuery struct {
  68. DashboardId int64
  69. Result []*DashboardAclInfoDTO
  70. }
  71. // Returns dashboard acl list items and parent folder items
  72. type GetInheritedDashboardAclQuery struct {
  73. DashboardId int64
  74. OrgId int64
  75. Result []*DashboardAcl
  76. }