dashboard_acl.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. ErrDashboardPermissionUserOrUserGroupEmpty = 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 `json:"id"`
  27. OrgId int64 `json:"-"`
  28. DashboardId int64 `json:"dashboardId"`
  29. Created time.Time `json:"created"`
  30. Updated time.Time `json:"updated"`
  31. UserId int64 `json:"userId"`
  32. UserGroupId int64 `json:"userGroupId"`
  33. Permissions PermissionType `json:"permissions"`
  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 AddOrUpdateDashboardPermissionCommand struct {
  53. DashboardId int64 `json:"-"`
  54. OrgId int64 `json:"-"`
  55. UserId int64 `json:"userId"`
  56. UserGroupId int64 `json:"userGroupId"`
  57. Permissions PermissionType `json:"permissionType" binding:"Required"`
  58. Result DashboardAcl `json:"-"`
  59. }
  60. type RemoveDashboardPermissionCommand struct {
  61. DashboardId int64 `json:"dashboardId" binding:"Required"`
  62. OrgId int64 `json:"-"`
  63. UserId int64 `json:"userId"`
  64. UserGroupId int64 `json:"userGroupId"`
  65. }
  66. //
  67. // QUERIES
  68. //
  69. type GetDashboardPermissionsQuery struct {
  70. DashboardId int64 `json:"dashboardId" binding:"Required"`
  71. Result []*DashboardAclInfoDTO
  72. }