2015-01-19 09:28:45 -06:00
|
|
|
package models
|
|
|
|
|
2015-01-19 11:01:04 -06:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Typed errors
|
|
|
|
var (
|
|
|
|
ErrUserNotFound = errors.New("User not found")
|
|
|
|
)
|
2015-01-19 09:28:45 -06:00
|
|
|
|
2016-12-09 08:25:02 -06:00
|
|
|
type Password string
|
|
|
|
|
|
|
|
func (p Password) IsWeak() bool {
|
|
|
|
return len(p) <= 4
|
|
|
|
}
|
|
|
|
|
2015-01-19 09:28:45 -06:00
|
|
|
type User struct {
|
2015-02-12 03:32:22 -06:00
|
|
|
Id int64
|
|
|
|
Version int
|
|
|
|
Email string
|
|
|
|
Name string
|
|
|
|
Login string
|
|
|
|
Password string
|
|
|
|
Salt string
|
|
|
|
Rands string
|
|
|
|
Company string
|
|
|
|
EmailVerified bool
|
|
|
|
Theme string
|
2016-11-09 03:41:39 -06:00
|
|
|
HelpFlags1 HelpFlags1
|
2015-01-19 09:28:45 -06:00
|
|
|
|
2015-02-23 13:07:49 -06:00
|
|
|
IsAdmin bool
|
|
|
|
OrgId int64
|
2015-01-19 09:28:45 -06:00
|
|
|
|
|
|
|
Created time.Time
|
|
|
|
Updated time.Time
|
|
|
|
}
|
|
|
|
|
2015-06-08 03:57:01 -05:00
|
|
|
func (u *User) NameOrFallback() string {
|
|
|
|
if u.Name != "" {
|
|
|
|
return u.Name
|
|
|
|
} else if u.Login != "" {
|
|
|
|
return u.Login
|
|
|
|
} else {
|
|
|
|
return u.Email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-19 09:28:45 -06:00
|
|
|
// ---------------------
|
|
|
|
// COMMANDS
|
|
|
|
|
|
|
|
type CreateUserCommand struct {
|
2016-09-20 11:36:36 -05:00
|
|
|
Email string
|
|
|
|
Login string
|
|
|
|
Name string
|
|
|
|
Company string
|
|
|
|
OrgName string
|
|
|
|
Password string
|
|
|
|
EmailVerified bool
|
|
|
|
IsAdmin bool
|
|
|
|
SkipOrgSetup bool
|
|
|
|
DefaultOrgRole string
|
2015-08-31 04:35:07 -05:00
|
|
|
|
|
|
|
Result User
|
2015-01-19 09:28:45 -06:00
|
|
|
}
|
2015-01-19 11:01:04 -06:00
|
|
|
|
|
|
|
type UpdateUserCommand struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
Login string `json:"login"`
|
2015-02-28 07:30:08 -06:00
|
|
|
Theme string `json:"theme"`
|
2015-01-19 11:01:04 -06:00
|
|
|
|
|
|
|
UserId int64 `json:"-"`
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:09:49 -06:00
|
|
|
type ChangeUserPasswordCommand struct {
|
|
|
|
OldPassword string `json:"oldPassword"`
|
|
|
|
NewPassword string `json:"newPassword"`
|
|
|
|
|
|
|
|
UserId int64 `json:"-"`
|
|
|
|
}
|
|
|
|
|
2015-02-26 08:43:48 -06:00
|
|
|
type UpdateUserPermissionsCommand struct {
|
|
|
|
IsGrafanaAdmin bool
|
|
|
|
UserId int64 `json:"-"`
|
|
|
|
}
|
|
|
|
|
2015-02-11 09:47:22 -06:00
|
|
|
type DeleteUserCommand struct {
|
|
|
|
UserId int64
|
|
|
|
}
|
|
|
|
|
2015-02-23 13:07:49 -06:00
|
|
|
type SetUsingOrgCommand struct {
|
|
|
|
UserId int64
|
|
|
|
OrgId int64
|
2015-01-19 11:01:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------
|
|
|
|
// QUERIES
|
|
|
|
|
|
|
|
type GetUserByLoginQuery struct {
|
|
|
|
LoginOrEmail string
|
|
|
|
Result *User
|
|
|
|
}
|
|
|
|
|
2016-10-19 23:45:10 -05:00
|
|
|
type GetUserByEmailQuery struct {
|
|
|
|
Email string
|
|
|
|
Result *User
|
|
|
|
}
|
|
|
|
|
2015-02-10 08:36:51 -06:00
|
|
|
type GetUserByIdQuery struct {
|
|
|
|
Id int64
|
|
|
|
Result *User
|
|
|
|
}
|
|
|
|
|
2015-01-19 11:01:04 -06:00
|
|
|
type GetSignedInUserQuery struct {
|
|
|
|
UserId int64
|
2015-05-02 05:06:58 -05:00
|
|
|
Login string
|
|
|
|
Email string
|
2017-04-14 08:47:39 -05:00
|
|
|
OrgId int64
|
2015-01-19 11:01:04 -06:00
|
|
|
Result *SignedInUser
|
|
|
|
}
|
|
|
|
|
2015-02-28 07:30:08 -06:00
|
|
|
type GetUserProfileQuery struct {
|
2015-01-19 11:01:04 -06:00
|
|
|
UserId int64
|
2015-02-28 07:30:08 -06:00
|
|
|
Result UserProfileDTO
|
2015-01-19 11:01:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type SearchUsersQuery struct {
|
|
|
|
Query string
|
|
|
|
Page int
|
|
|
|
Limit int
|
|
|
|
|
2017-02-08 07:20:07 -06:00
|
|
|
Result SearchUserQueryResult
|
|
|
|
}
|
|
|
|
|
|
|
|
type SearchUserQueryResult struct {
|
|
|
|
TotalCount int64 `json:"totalCount"`
|
|
|
|
Users []*UserSearchHitDTO `json:"users"`
|
|
|
|
Page int `json:"page"`
|
|
|
|
PerPage int `json:"perPage"`
|
2015-01-19 11:01:04 -06:00
|
|
|
}
|
|
|
|
|
2015-02-23 13:07:49 -06:00
|
|
|
type GetUserOrgListQuery struct {
|
|
|
|
UserId int64
|
|
|
|
Result []*UserOrgDTO
|
|
|
|
}
|
|
|
|
|
2015-01-19 11:01:04 -06:00
|
|
|
// ------------------------
|
|
|
|
// DTO & Projections
|
|
|
|
|
|
|
|
type SignedInUser struct {
|
|
|
|
UserId int64
|
2015-02-23 13:07:49 -06:00
|
|
|
OrgId int64
|
|
|
|
OrgName string
|
|
|
|
OrgRole RoleType
|
2015-01-19 11:01:04 -06:00
|
|
|
Login string
|
|
|
|
Name string
|
|
|
|
Email string
|
|
|
|
ApiKeyId int64
|
|
|
|
IsGrafanaAdmin bool
|
2016-11-09 03:41:39 -06:00
|
|
|
HelpFlags1 HelpFlags1
|
2015-01-19 11:01:04 -06:00
|
|
|
}
|
|
|
|
|
2015-02-28 07:30:08 -06:00
|
|
|
type UserProfileDTO struct {
|
2015-02-26 08:43:48 -06:00
|
|
|
Email string `json:"email"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Login string `json:"login"`
|
2015-02-28 07:30:08 -06:00
|
|
|
Theme string `json:"theme"`
|
2015-05-19 03:16:32 -05:00
|
|
|
OrgId int64 `json:"orgId"`
|
2015-02-26 08:43:48 -06:00
|
|
|
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
|
2015-01-19 11:01:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
type UserSearchHitDTO struct {
|
|
|
|
Id int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Login string `json:"login"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
IsAdmin bool `json:"isAdmin"`
|
|
|
|
}
|
2015-11-16 08:55:02 -06:00
|
|
|
|
|
|
|
type UserIdDTO struct {
|
2015-11-16 09:28:38 -06:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
Message string `json:"message"`
|
2015-11-16 08:55:02 -06:00
|
|
|
}
|