Chore move Filter to user service (#53588)

This commit is contained in:
idafurjes
2022-08-11 14:45:29 +02:00
committed by GitHub
parent a14621fff6
commit da72a4ed2e
9 changed files with 120 additions and 57 deletions

View File

@@ -101,6 +101,68 @@ type SetUsingOrgCommand struct {
OrgID int64
}
type SearchUsersQuery struct {
SignedInUser *SignedInUser
OrgID int64
Query string
Page int
Limit int
AuthModule string
Filters []Filter
IsDisabled *bool
}
type SearchUserQueryResult struct {
TotalCount int64 `json:"totalCount"`
Users []*UserSearchHitDTO `json:"users"`
Page int `json:"page"`
PerPage int `json:"perPage"`
}
type UserSearchHitDTO struct {
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"`
AuthLabels []string `json:"authLabels"`
AuthModule AuthModuleConversion `json:"-"`
}
// 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
}
// Just a stub, we don't want to write to database
func (auth *AuthModuleConversion) ToDB() ([]byte, error) {
return []byte{}, nil
}
type DisableUserCommand struct {
UserID int64
IsDisabled bool
}
type BatchDisableUsersCommand struct {
UserIDs []int64
IsDisabled bool
}
type SetUserHelpFlagCommand struct {
HelpFlags1 HelpFlags1
UserID int64
}
type GetSignedInUserQuery struct {
UserID int64
Login string
@@ -153,7 +215,7 @@ type ErrCaseInsensitiveLoginConflict struct {
}
type UserDisplayDTO struct {
Id int64 `json:"id,omitempty"`
ID int64 `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Login string `json:"login,omitempty"`
AvatarUrl string `json:"avatarUrl"`
@@ -178,7 +240,7 @@ func (u *SignedInUser) NameOrFallback() string {
func (u *SignedInUser) ToUserDisplayDTO() *UserDisplayDTO {
return &UserDisplayDTO{
Id: u.UserID,
ID: u.UserID,
Login: u.Login,
Name: u.Name,
}
@@ -211,3 +273,32 @@ func (e *ErrCaseInsensitiveLoginConflict) Error() string {
"Found a conflict in user login information. %d users already exist with either the same login or email: [%s].",
n, strings.Join(userStrings, ", "))
}
type Filter interface {
WhereCondition() *WhereCondition
InCondition() *InCondition
JoinCondition() *JoinCondition
}
type WhereCondition struct {
Condition string
Params interface{}
}
type InCondition struct {
Condition string
Params interface{}
}
type JoinCondition struct {
Operator string
Table string
Params string
}
type SearchUserFilter interface {
GetFilter(filterName string, params []string) Filter
GetFilterList() map[string]FilterHandler
}
type FilterHandler func(params []string) (Filter, error)