user.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 GetUserByIdQuery struct {
  81. Id int64
  82. Result *User
  83. }
  84. type GetSignedInUserQuery struct {
  85. UserId int64
  86. Login string
  87. Email string
  88. Result *SignedInUser
  89. }
  90. type GetUserProfileQuery struct {
  91. UserId int64
  92. Result UserProfileDTO
  93. }
  94. type SearchUsersQuery struct {
  95. Query string
  96. Page int
  97. Limit int
  98. Result []*UserSearchHitDTO
  99. }
  100. type GetUserOrgListQuery struct {
  101. UserId int64
  102. Result []*UserOrgDTO
  103. }
  104. // ------------------------
  105. // DTO & Projections
  106. type SignedInUser struct {
  107. UserId int64
  108. OrgId int64
  109. OrgName string
  110. OrgRole RoleType
  111. Login string
  112. Name string
  113. Email string
  114. ApiKeyId int64
  115. IsGrafanaAdmin bool
  116. }
  117. type UserProfileDTO struct {
  118. Email string `json:"email"`
  119. Name string `json:"name"`
  120. Login string `json:"login"`
  121. Theme string `json:"theme"`
  122. OrgId int64 `json:"orgId"`
  123. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  124. }
  125. type UserSearchHitDTO struct {
  126. Id int64 `json:"id"`
  127. Name string `json:"name"`
  128. Login string `json:"login"`
  129. Email string `json:"email"`
  130. IsAdmin bool `json:"isAdmin"`
  131. }
  132. type UserIdDTO struct {
  133. Id int64 `json:"id"`
  134. Message string `json:"message"`
  135. }