user.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. Result *SignedInUser
  74. }
  75. type GetUserProfileQuery struct {
  76. UserId int64
  77. Result UserProfileDTO
  78. }
  79. type SearchUsersQuery struct {
  80. Query string
  81. Page int
  82. Limit int
  83. Result []*UserSearchHitDTO
  84. }
  85. type GetUserOrgListQuery struct {
  86. UserId int64
  87. Result []*UserOrgDTO
  88. }
  89. // ------------------------
  90. // DTO & Projections
  91. type SignedInUser struct {
  92. UserId int64
  93. OrgId int64
  94. OrgName string
  95. OrgRole RoleType
  96. Login string
  97. Name string
  98. Email string
  99. Theme string
  100. ApiKeyId int64
  101. IsGrafanaAdmin bool
  102. }
  103. type UserProfileDTO struct {
  104. Email string `json:"email"`
  105. Name string `json:"name"`
  106. Login string `json:"login"`
  107. Theme string `json:"theme"`
  108. IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
  109. }
  110. type UserSearchHitDTO struct {
  111. Id int64 `json:"id"`
  112. Name string `json:"name"`
  113. Login string `json:"login"`
  114. Email string `json:"email"`
  115. IsAdmin bool `json:"isAdmin"`
  116. }