org_user.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ErrOrgUserAlreadyAdded = errors.New("User is already added to organization")
  12. )
  13. type RoleType string
  14. const (
  15. ROLE_VIEWER RoleType = "Viewer"
  16. ROLE_EDITOR RoleType = "Editor"
  17. ROLE_READ_ONLY_EDITOR RoleType = "Read Only Editor"
  18. ROLE_ADMIN RoleType = "Admin"
  19. )
  20. func (r RoleType) IsValid() bool {
  21. return r == ROLE_VIEWER || r == ROLE_ADMIN || r == ROLE_EDITOR || r == ROLE_READ_ONLY_EDITOR
  22. }
  23. type OrgUser struct {
  24. Id int64
  25. OrgId int64
  26. UserId int64
  27. Role RoleType
  28. Created time.Time
  29. Updated time.Time
  30. }
  31. // ---------------------
  32. // COMMANDS
  33. type RemoveOrgUserCommand struct {
  34. UserId int64
  35. OrgId int64
  36. }
  37. type AddOrgUserCommand struct {
  38. LoginOrEmail string `json:"loginOrEmail" binding:"Required"`
  39. Role RoleType `json:"role" binding:"Required"`
  40. OrgId int64 `json:"-"`
  41. UserId int64 `json:"-"`
  42. }
  43. type UpdateOrgUserCommand struct {
  44. Role RoleType `json:"role" binding:"Required"`
  45. OrgId int64 `json:"-"`
  46. UserId int64 `json:"-"`
  47. }
  48. // ----------------------
  49. // QUERIES
  50. type GetOrgUsersQuery struct {
  51. OrgId int64
  52. Result []*OrgUserDTO
  53. }
  54. // ----------------------
  55. // Projections and DTOs
  56. type OrgUserDTO struct {
  57. OrgId int64 `json:"orgId"`
  58. UserId int64 `json:"userId"`
  59. Email string `json:"email"`
  60. Login string `json:"login"`
  61. Role string `json:"role"`
  62. }