team_member.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. // Typed errors
  7. var (
  8. ErrTeamMemberAlreadyAdded = errors.New("User is already added to this team")
  9. )
  10. // TeamMember model
  11. type TeamMember struct {
  12. Id int64
  13. OrgId int64
  14. TeamId int64
  15. UserId int64
  16. External bool // Signals that the membership has been created by an external systems, such as LDAP
  17. Permission PermissionType
  18. Created time.Time
  19. Updated time.Time
  20. }
  21. // ---------------------
  22. // COMMANDS
  23. type AddTeamMemberCommand struct {
  24. UserId int64 `json:"userId" binding:"Required"`
  25. OrgId int64 `json:"-"`
  26. TeamId int64 `json:"-"`
  27. External bool `json:"-"`
  28. Permission PermissionType `json:"-"`
  29. }
  30. type UpdateTeamMemberCommand struct {
  31. UserId int64 `json:"-"`
  32. OrgId int64 `json:"-"`
  33. TeamId int64 `json:"-"`
  34. Permission PermissionType `json:"permission"`
  35. ProtectLastAdmin bool `json:"-"`
  36. }
  37. type RemoveTeamMemberCommand struct {
  38. OrgId int64 `json:"-"`
  39. UserId int64
  40. TeamId int64
  41. ProtectLastAdmin bool `json:"-"`
  42. }
  43. // ----------------------
  44. // QUERIES
  45. type GetTeamMembersQuery struct {
  46. OrgId int64
  47. TeamId int64
  48. UserId int64
  49. External bool
  50. Result []*TeamMemberDTO
  51. }
  52. // ----------------------
  53. // Projections and DTOs
  54. type TeamMemberDTO struct {
  55. OrgId int64 `json:"orgId"`
  56. TeamId int64 `json:"teamId"`
  57. UserId int64 `json:"userId"`
  58. External bool `json:"-"`
  59. AuthModule string `json:"auth_module"`
  60. Email string `json:"email"`
  61. Login string `json:"login"`
  62. AvatarUrl string `json:"avatarUrl"`
  63. Labels []string `json:"labels"`
  64. Permission PermissionType `json:"permission"`
  65. }