|
|
@ -17,6 +17,13 @@ import ( |
|
|
|
"xorm.io/xorm" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type SearchKind int64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
ByDescription SearchKind = iota |
|
|
|
|
|
|
|
ByCompetence |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// SearchUserOptions contains the options for searching
|
|
|
|
// SearchUserOptions contains the options for searching
|
|
|
|
type SearchUserOptions struct { |
|
|
|
type SearchUserOptions struct { |
|
|
|
db.ListOptions |
|
|
|
db.ListOptions |
|
|
@ -28,6 +35,7 @@ type SearchUserOptions struct { |
|
|
|
Visible []structs.VisibleType |
|
|
|
Visible []structs.VisibleType |
|
|
|
Actor *User // The user doing the search
|
|
|
|
Actor *User // The user doing the search
|
|
|
|
SearchByEmail bool // Search by email as well as username/full name
|
|
|
|
SearchByEmail bool // Search by email as well as username/full name
|
|
|
|
|
|
|
|
Kind SearchKind |
|
|
|
|
|
|
|
|
|
|
|
IsActive util.OptionalBool |
|
|
|
IsActive util.OptionalBool |
|
|
|
IsAdmin util.OptionalBool |
|
|
|
IsAdmin util.OptionalBool |
|
|
@ -53,8 +61,15 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session { |
|
|
|
keywordCond := builder.Or( |
|
|
|
keywordCond := builder.Or( |
|
|
|
builder.Like{"lower_name", lowerKeyword}, |
|
|
|
builder.Like{"lower_name", lowerKeyword}, |
|
|
|
builder.Like{"LOWER(full_name)", lowerKeyword}, |
|
|
|
builder.Like{"LOWER(full_name)", lowerKeyword}, |
|
|
|
builder.Like{"LOWER(description)", lowerKeyword}, |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
switch opts.Kind { |
|
|
|
|
|
|
|
case ByDescription: |
|
|
|
|
|
|
|
keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) |
|
|
|
|
|
|
|
case ByCompetence: |
|
|
|
|
|
|
|
keywordCond = builder.Or(builder.Like{"LOWER(competences)", lowerKeyword}) |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
keywordCond = builder.Or(builder.Like{"LOWER(description)", lowerKeyword}) |
|
|
|
|
|
|
|
} |
|
|
|
if opts.SearchByEmail { |
|
|
|
if opts.SearchByEmail { |
|
|
|
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) |
|
|
|
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) |
|
|
|
} |
|
|
|
} |
|
|
|