user.go 2.5 KB

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