user.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package models
  2. import (
  3. "errors"
  4. "time"
  5. )
  6. // Typed errors
  7. var (
  8. ErrUserNotFound = errors.New("User not found")
  9. )
  10. type User struct {
  11. Id int64
  12. Version int
  13. Email string
  14. Name string
  15. Login string
  16. Password string
  17. Salt string
  18. Rands string
  19. Company string
  20. EmailVerified bool
  21. Theme string
  22. IsAdmin bool
  23. OrgId int64
  24. Created time.Time
  25. Updated time.Time
  26. }
  27. // ---------------------
  28. // COMMANDS
  29. type CreateUserCommand struct {
  30. Email string `json:"email" binding:"Required"`
  31. Login string `json:"login"`
  32. Name string `json:"name"`
  33. Company string `json:"compay"`
  34. Password string `json:"password" binding:"Required"`
  35. IsAdmin bool `json:"-"`
  36. Result User `json:"-"`
  37. }
  38. type UpdateUserCommand struct {
  39. Name string `json:"name"`
  40. Email string `json:"email"`
  41. Login string `json:"login"`
  42. UserId int64 `json:"-"`
  43. }
  44. type ChangeUserPasswordCommand struct {
  45. OldPassword string `json:"oldPassword"`
  46. NewPassword string `json:"newPassword"`
  47. UserId int64 `json:"-"`
  48. }
  49. type UpdateUserPermissionsCommand struct {
  50. IsGrafanaAdmin bool
  51. UserId int64 `json:"-"`
  52. }
  53. type DeleteUserCommand struct {
  54. UserId int64
  55. }
  56. type SetUsingOrgCommand struct {
  57. UserId int64
  58. OrgId int64
  59. }
  60. // ----------------------
  61. // QUERIES
  62. type GetUserByLoginQuery struct {
  63. LoginOrEmail string
  64. Result *User
  65. }
  66. type GetUserByIdQuery struct {
  67. Id int64
  68. Result *User
  69. }
  70. type GetSignedInUserQuery struct {
  71. UserId int64
  72. Result *SignedInUser
  73. }
  74. type GetUserInfoQuery struct {
  75. UserId int64
  76. Result UserDTO
  77. }
  78. type SearchUsersQuery struct {
  79. Query string
  80. Page int
  81. Limit int
  82. Result []*UserSearchHitDTO
  83. }
  84. type GetUserOrgListQuery struct {
  85. UserId int64
  86. Result []*UserOrgDTO
  87. }
  88. // ------------------------
  89. // DTO & Projections
  90. type SignedInUser struct {
  91. UserId int64
  92. OrgId int64
  93. OrgName string
  94. OrgRole RoleType
  95. Login string
  96. Name string
  97. Email string
  98. ApiKeyId int64
  99. IsGrafanaAdmin bool
  100. }
  101. type UserDTO struct {
  102. Email string `json:"email"`
  103. Name string `json:"name"`
  104. Login string `json:"login"`
  105. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  106. }
  107. type UserSearchHitDTO struct {
  108. Id int64 `json:"id"`
  109. Name string `json:"name"`
  110. Login string `json:"login"`
  111. Email string `json:"email"`
  112. IsAdmin bool `json:"isAdmin"`
  113. }