org_user.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. // Typed errors
  7. var (
  8. ErrInvalidRoleType = errors.New("Invalid role type")
  9. ErrLastOrgAdmin = errors.New("Cannot remove last organization admin")
  10. ErrOrgUserNotFound = errors.New("Cannot find the organization user")
  11. )
  12. type RoleType string
  13. const (
  14. ROLE_VIEWER RoleType = "Viewer"
  15. ROLE_EDITOR RoleType = "Editor"
  16. ROLE_READ_ONLY_EDITOR RoleType = "Read Only Editor"
  17. ROLE_ADMIN RoleType = "Admin"
  18. )
  19. func (r RoleType) IsValid() bool {
  20. return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR || r == ROLE_READ_ONLY_EDITOR
  21. }
  22. type OrgUser struct {
  23. Id int64
  24. OrgId int64
  25. UserId int64
  26. Role RoleType
  27. Created time.Time
  28. Updated time.Time
  29. }
  30. // ---------------------
  31. // COMMANDS
  32. type RemoveOrgUserCommand struct {
  33. UserId int64
  34. OrgId int64
  35. }
  36. type AddOrgUserCommand struct {
  37. LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
  38. Role RoleType `json:"role" binding:"Required"`
  39. OrgId int64 `json:"-"`
  40. UserId int64 `json:"-"`
  41. }
  42. type UpdateOrgUserCommand struct {
  43. Role RoleType `json:"role" binding:"Required"`
  44. OrgId int64 `json:"-"`
  45. UserId int64 `json:"-"`
  46. }
  47. // ----------------------
  48. // QUERIES
  49. type GetOrgUsersQuery struct {
  50. OrgId int64
  51. Result []*OrgUserDTO
  52. }
  53. // ----------------------
  54. // Projections and DTOs
  55. type OrgUserDTO struct {
  56. OrgId int64 `json:"orgId"`
  57. UserId int64 `json:"userId"`
  58. Email string `json:"email"`
  59. Login string `json:"login"`
  60. Role string `json:"role"`
  61. }