org_user.go 1.4 KB

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