dashboard_acl.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. 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. Permissions 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. Permissions PermissionType `json:"permissions"`
  48. PermissionName string `json:"permissionName"`
  49. }
  50. //
  51. // COMMANDS
  52. //
  53. type SetDashboardAclCommand struct {
  54. DashboardId int64 `json:"-"`
  55. OrgId int64 `json:"-"`
  56. UserId int64 `json:"userId"`
  57. UserGroupId int64 `json:"userGroupId"`
  58. Permissions PermissionType `json:"permissions" binding:"Required"`
  59. Result DashboardAcl `json:"-"`
  60. }
  61. type RemoveDashboardAclCommand struct {
  62. AclId int64
  63. OrgId int64
  64. }
  65. //
  66. // QUERIES
  67. //
  68. type GetDashboardAclInfoListQuery struct {
  69. DashboardId int64
  70. Result []*DashboardAclInfoDTO
  71. }
  72. // Returns dashboard acl list items and parent folder items
  73. type GetInheritedDashboardAclQuery struct {
  74. DashboardId int64
  75. OrgId int64
  76. Result []*DashboardAcl
  77. }