user.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. Result User
  49. }
  50. type UpdateUserCommand struct {
  51. Name string `json:"name"`
  52. Email string `json:"email"`
  53. Login string `json:"login"`
  54. Theme string `json:"theme"`
  55. UserId int64 `json:"-"`
  56. }
  57. type ChangeUserPasswordCommand struct {
  58. OldPassword string `json:"oldPassword"`
  59. NewPassword string `json:"newPassword"`
  60. UserId int64 `json:"-"`
  61. }
  62. type UpdateUserPermissionsCommand struct {
  63. IsGrafanaAdmin bool
  64. UserId int64 `json:"-"`
  65. }
  66. type DeleteUserCommand struct {
  67. UserId int64
  68. }
  69. type SetUsingOrgCommand struct {
  70. UserId int64
  71. OrgId int64
  72. }
  73. // ----------------------
  74. // QUERIES
  75. type GetUserByLoginQuery struct {
  76. LoginOrEmail string
  77. Result *User
  78. }
  79. type GetUserByIdQuery struct {
  80. Id int64
  81. Result *User
  82. }
  83. type GetSignedInUserQuery struct {
  84. UserId int64
  85. Login string
  86. Email string
  87. Result *SignedInUser
  88. }
  89. type GetUserProfileQuery struct {
  90. UserId int64
  91. Result UserProfileDTO
  92. }
  93. type SearchUsersQuery struct {
  94. Query string
  95. Page int
  96. Limit int
  97. Result []*UserSearchHitDTO
  98. }
  99. type GetUserOrgListQuery struct {
  100. UserId int64
  101. Result []*UserOrgDTO
  102. }
  103. // ------------------------
  104. // DTO & Projections
  105. type SignedInUser struct {
  106. UserId int64
  107. OrgId int64
  108. OrgName string
  109. OrgRole RoleType
  110. Login string
  111. Name string
  112. Email string
  113. ApiKeyId int64
  114. IsGrafanaAdmin bool
  115. }
  116. type UserProfileDTO struct {
  117. Email string `json:"email"`
  118. Name string `json:"name"`
  119. Login string `json:"login"`
  120. Theme string `json:"theme"`
  121. OrgId int64 `json:"orgId"`
  122. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  123. }
  124. type UserSearchHitDTO struct {
  125. Id int64 `json:"id"`
  126. Name string `json:"name"`
  127. Login string `json:"login"`
  128. Email string `json:"email"`
  129. IsAdmin bool `json:"isAdmin"`
  130. }
  131. type UserIdDTO struct {
  132. Id int64 `json:"id"`
  133. Message string `json:"message"`
  134. }