user.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. func (u *User) NameOrFallback() string {
  28. if u.Name != "" {
  29. return u.Name
  30. } else if u.Login != "" {
  31. return u.Login
  32. } else {
  33. return u.Email
  34. }
  35. }
  36. // ---------------------
  37. // COMMANDS
  38. type CreateUserCommand struct {
  39. Email string
  40. Login string
  41. Name string
  42. Company string
  43. OrgName string
  44. Password string
  45. EmailVerified bool
  46. IsAdmin bool
  47. SkipOrgSetup bool
  48. DefaultOrgRole string
  49. Result User
  50. }
  51. type UpdateUserCommand struct {
  52. Name string `json:"name"`
  53. Email string `json:"email"`
  54. Login string `json:"login"`
  55. Theme string `json:"theme"`
  56. UserId int64 `json:"-"`
  57. }
  58. type ChangeUserPasswordCommand struct {
  59. OldPassword string `json:"oldPassword"`
  60. NewPassword string `json:"newPassword"`
  61. UserId int64 `json:"-"`
  62. }
  63. type UpdateUserPermissionsCommand struct {
  64. IsGrafanaAdmin bool
  65. UserId int64 `json:"-"`
  66. }
  67. type DeleteUserCommand struct {
  68. UserId int64
  69. }
  70. type SetUsingOrgCommand struct {
  71. UserId int64
  72. OrgId int64
  73. }
  74. // ----------------------
  75. // QUERIES
  76. type GetUserByLoginQuery struct {
  77. LoginOrEmail string
  78. Result *User
  79. }
  80. type GetUserByEmailQuery struct {
  81. Email string
  82. Result *User
  83. }
  84. type GetUserByIdQuery struct {
  85. Id int64
  86. Result *User
  87. }
  88. type GetSignedInUserQuery struct {
  89. UserId int64
  90. Login string
  91. Email string
  92. Result *SignedInUser
  93. }
  94. type GetUserProfileQuery struct {
  95. UserId int64
  96. Result UserProfileDTO
  97. }
  98. type SearchUsersQuery struct {
  99. Query string
  100. Page int
  101. Limit int
  102. Result []*UserSearchHitDTO
  103. }
  104. type GetUserOrgListQuery struct {
  105. UserId int64
  106. Result []*UserOrgDTO
  107. }
  108. // ------------------------
  109. // DTO & Projections
  110. type SignedInUser struct {
  111. UserId int64
  112. OrgId int64
  113. OrgName string
  114. OrgRole RoleType
  115. Login string
  116. Name string
  117. Email string
  118. ApiKeyId int64
  119. IsGrafanaAdmin bool
  120. }
  121. type UserProfileDTO struct {
  122. Email string `json:"email"`
  123. Name string `json:"name"`
  124. Login string `json:"login"`
  125. Theme string `json:"theme"`
  126. OrgId int64 `json:"orgId"`
  127. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  128. }
  129. type UserSearchHitDTO struct {
  130. Id int64 `json:"id"`
  131. Name string `json:"name"`
  132. Login string `json:"login"`
  133. Email string `json:"email"`
  134. IsAdmin bool `json:"isAdmin"`
  135. }
  136. type UserIdDTO struct {
  137. Id int64 `json:"id"`
  138. Message string `json:"message"`
  139. }