2015-01-19 16:28:45 +01:00
|
|
|
package models
|
|
|
|
|
|
2015-01-19 18:01:04 +01:00
|
|
|
import (
|
|
|
|
|
"time"
|
2022-06-28 14:32:25 +02:00
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
2015-01-19 18:01:04 +01:00
|
|
|
)
|
|
|
|
|
|
2016-12-09 15:25:02 +01:00
|
|
|
type Password string
|
|
|
|
|
|
|
|
|
|
func (p Password) IsWeak() bool {
|
|
|
|
|
return len(p) <= 4
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 18:01:04 +01:00
|
|
|
type UpdateUserCommand struct {
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Email string `json:"email"`
|
|
|
|
|
Login string `json:"login"`
|
2015-02-28 14:30:08 +01:00
|
|
|
Theme string `json:"theme"`
|
2015-01-19 18:01:04 +01:00
|
|
|
|
|
|
|
|
UserId int64 `json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-19 16:09:49 +01:00
|
|
|
type ChangeUserPasswordCommand struct {
|
|
|
|
|
OldPassword string `json:"oldPassword"`
|
|
|
|
|
NewPassword string `json:"newPassword"`
|
|
|
|
|
|
|
|
|
|
UserId int64 `json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-21 14:52:49 +03:00
|
|
|
type DisableUserCommand struct {
|
|
|
|
|
UserId int64
|
|
|
|
|
IsDisabled bool
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 13:22:22 +03:00
|
|
|
type BatchDisableUsersCommand struct {
|
|
|
|
|
UserIds []int64
|
|
|
|
|
IsDisabled bool
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 16:47:22 +01:00
|
|
|
type DeleteUserCommand struct {
|
|
|
|
|
UserId int64
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 20:07:49 +01:00
|
|
|
type SetUsingOrgCommand struct {
|
|
|
|
|
UserId int64
|
|
|
|
|
OrgId int64
|
2015-01-19 18:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------
|
|
|
|
|
// QUERIES
|
|
|
|
|
|
|
|
|
|
type GetUserByLoginQuery struct {
|
|
|
|
|
LoginOrEmail string
|
2022-06-28 14:32:25 +02:00
|
|
|
Result *user.User
|
2015-01-19 18:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-19 21:45:10 -07:00
|
|
|
type GetUserByEmailQuery struct {
|
|
|
|
|
Email string
|
2022-06-28 14:32:25 +02:00
|
|
|
Result *user.User
|
2016-10-19 21:45:10 -07:00
|
|
|
}
|
|
|
|
|
|
2015-02-10 15:36:51 +01:00
|
|
|
type GetUserByIdQuery struct {
|
|
|
|
|
Id int64
|
2022-06-28 14:32:25 +02:00
|
|
|
Result *user.User
|
2015-02-10 15:36:51 +01:00
|
|
|
}
|
|
|
|
|
|
2015-01-19 18:01:04 +01:00
|
|
|
type GetSignedInUserQuery struct {
|
|
|
|
|
UserId int64
|
2015-05-02 12:06:58 +02:00
|
|
|
Login string
|
|
|
|
|
Email string
|
2017-04-14 09:47:39 -04:00
|
|
|
OrgId int64
|
2022-08-10 11:56:48 +02:00
|
|
|
Result *user.SignedInUser
|
2015-01-19 18:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-28 14:30:08 +01:00
|
|
|
type GetUserProfileQuery struct {
|
2015-01-19 18:01:04 +01:00
|
|
|
UserId int64
|
2015-02-28 14:30:08 +01:00
|
|
|
Result UserProfileDTO
|
2015-01-19 18:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SearchUsersQuery struct {
|
2022-08-10 11:56:48 +02:00
|
|
|
SignedInUser *user.SignedInUser
|
2022-05-13 09:26:34 +02:00
|
|
|
OrgId int64
|
|
|
|
|
Query string
|
|
|
|
|
Page int
|
|
|
|
|
Limit int
|
|
|
|
|
AuthModule string
|
2022-08-11 14:45:29 +02:00
|
|
|
Filters []user.Filter
|
2015-01-19 18:01:04 +01:00
|
|
|
|
2019-07-17 06:24:56 +03:00
|
|
|
IsDisabled *bool
|
2019-07-15 09:14:32 +03:00
|
|
|
|
2017-02-08 14:20:07 +01: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 18:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 20:07:49 +01:00
|
|
|
type GetUserOrgListQuery struct {
|
|
|
|
|
UserId int64
|
|
|
|
|
Result []*UserOrgDTO
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 10:36:41 +02:00
|
|
|
type UpdateUserLastSeenAtCommand struct {
|
|
|
|
|
UserId int64
|
2015-01-19 18:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-28 14:30:08 +01:00
|
|
|
type UserProfileDTO struct {
|
2022-01-05 08:59:17 +00:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
|
Email string `json:"email"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Login string `json:"login"`
|
|
|
|
|
Theme string `json:"theme"`
|
2022-04-06 08:35:58 +02:00
|
|
|
OrgId int64 `json:"orgId,omitempty"`
|
2022-01-05 08:59:17 +00:00
|
|
|
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
|
|
|
|
|
IsDisabled bool `json:"isDisabled"`
|
|
|
|
|
IsExternal bool `json:"isExternal"`
|
|
|
|
|
AuthLabels []string `json:"authLabels"`
|
|
|
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
|
AvatarUrl string `json:"avatarUrl"`
|
|
|
|
|
AccessControl map[string]bool `json:"accessControl,omitempty"`
|
2015-01-19 18:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UserSearchHitDTO struct {
|
2019-06-25 18:29:07 +03:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Login string `json:"login"`
|
|
|
|
|
Email string `json:"email"`
|
|
|
|
|
AvatarUrl string `json:"avatarUrl"`
|
|
|
|
|
IsAdmin bool `json:"isAdmin"`
|
|
|
|
|
IsDisabled bool `json:"isDisabled"`
|
|
|
|
|
LastSeenAt time.Time `json:"lastSeenAt"`
|
|
|
|
|
LastSeenAtAge string `json:"lastSeenAtAge"`
|
2019-07-10 12:06:51 +03:00
|
|
|
AuthLabels []string `json:"authLabels"`
|
|
|
|
|
AuthModule AuthModuleConversion `json:"-"`
|
2015-01-19 18:01:04 +01:00
|
|
|
}
|
2015-11-16 06:55:02 -08:00
|
|
|
|
|
|
|
|
type UserIdDTO struct {
|
2015-11-16 07:28:38 -08:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
|
Message string `json:"message"`
|
2015-11-16 06:55:02 -08:00
|
|
|
}
|
2019-06-25 18:29:07 +03:00
|
|
|
|
|
|
|
|
// implement Conversion interface to define custom field mapping (xorm feature)
|
|
|
|
|
type AuthModuleConversion []string
|
|
|
|
|
|
|
|
|
|
func (auth *AuthModuleConversion) FromDB(data []byte) error {
|
|
|
|
|
auth_module := string(data)
|
|
|
|
|
*auth = []string{auth_module}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 21:37:21 +02:00
|
|
|
// Just a stub, we don't want to write to database
|
2019-06-25 18:29:07 +03:00
|
|
|
func (auth *AuthModuleConversion) ToDB() ([]byte, error) {
|
|
|
|
|
return []byte{}, nil
|
|
|
|
|
}
|