dashboard_acl.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. type PermissionType int
  7. const (
  8. PERMISSION_NONE = 0
  9. PERMISSION_VIEW PermissionType = 1 << iota
  10. PERMISSION_EDIT
  11. PERMISSION_ADMIN
  12. )
  13. func (p PermissionType) String() string {
  14. names := map[int]string{
  15. int(PERMISSION_NONE): "None",
  16. int(PERMISSION_VIEW): "View",
  17. int(PERMISSION_EDIT): "Edit",
  18. int(PERMISSION_ADMIN): "Admin",
  19. }
  20. return names[int(p)]
  21. }
  22. // Typed errors
  23. var (
  24. ErrDashboardAclInfoMissing = errors.New("User id and user group id cannot both be empty for a dashboard permission.")
  25. ErrDashboardPermissionDashboardEmpty = errors.New("Dashboard Id must be greater than zero for a dashboard permission.")
  26. )
  27. // Dashboard ACL model
  28. type DashboardAcl struct {
  29. Id int64
  30. OrgId int64
  31. DashboardId int64
  32. UserId int64
  33. UserGroupId int64
  34. Permissions PermissionType
  35. Created time.Time
  36. Updated time.Time
  37. }
  38. type DashboardAclInfoDTO struct {
  39. Id int64 `json:"id"`
  40. OrgId int64 `json:"-"`
  41. DashboardId int64 `json:"dashboardId"`
  42. Created time.Time `json:"created"`
  43. Updated time.Time `json:"updated"`
  44. UserId int64 `json:"userId"`
  45. UserLogin string `json:"userLogin"`
  46. UserEmail string `json:"userEmail"`
  47. UserGroupId int64 `json:"userGroupId"`
  48. UserGroup string `json:"userGroup"`
  49. Role RoleType `json:"role"`
  50. Permissions PermissionType `json:"permissions"`
  51. PermissionName string `json:"permissionName"`
  52. }
  53. //
  54. // COMMANDS
  55. //
  56. type SetDashboardAclCommand struct {
  57. DashboardId int64 `json:"-"`
  58. OrgId int64 `json:"-"`
  59. UserId int64 `json:"userId"`
  60. UserGroupId int64 `json:"userGroupId"`
  61. Permissions PermissionType `json:"permissions" binding:"Required"`
  62. Result DashboardAcl `json:"-"`
  63. }
  64. type RemoveDashboardAclCommand struct {
  65. AclId int64
  66. OrgId int64
  67. }
  68. //
  69. // QUERIES
  70. //
  71. type GetDashboardAclInfoListQuery struct {
  72. DashboardId int64
  73. Result []*DashboardAclInfoDTO
  74. }
  75. // Returns dashboard acl list items and parent folder items
  76. type GetInheritedDashboardAclQuery struct {
  77. DashboardId int64
  78. OrgId int64
  79. Result []*DashboardAcl
  80. }