dashboard_acl.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 team 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. TeamId 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. 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. TeamId int64 `json:"teamId"`
  46. Team string `json:"team"`
  47. Role *RoleType `json:"role,omitempty"`
  48. Permission PermissionType `json:"permission"`
  49. PermissionName string `json:"permissionName"`
  50. Uid string `json:"uid"`
  51. Title string `json:"title"`
  52. Slug string `json:"slug"`
  53. IsFolder bool `json:"isFolder"`
  54. Url string `json:"url"`
  55. }
  56. //
  57. // COMMANDS
  58. //
  59. type UpdateDashboardAclCommand struct {
  60. DashboardId int64
  61. Items []*DashboardAcl
  62. }
  63. //
  64. // QUERIES
  65. //
  66. type GetDashboardAclInfoListQuery struct {
  67. DashboardId int64
  68. OrgId int64
  69. Result []*DashboardAclInfoDTO
  70. }