@ -8,37 +8,24 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/optional"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert"
"code.gitea.io/gitea/services/convert"
)
)
// Search search users
// SearchCandidates searches candidate users for dropdown list
func Search ( ctx * context . Context ) {
func SearchCandidates ( ctx * context . Context ) {
listOptions := db . ListOptions {
users , _ , err := user_model . SearchUsers ( ctx , & user_model . SearchUserOptions {
Page : ctx . FormInt ( "page" ) ,
PageSize : convert . ToCorrectPageSize ( ctx . FormInt ( "limit" ) ) ,
}
users , maxResults , err := user_model . SearchUsers ( ctx , & user_model . SearchUserOptions {
Actor : ctx . Doer ,
Actor : ctx . Doer ,
Keyword : ctx . FormTrim ( "q" ) ,
Keyword : ctx . FormTrim ( "q" ) ,
UID : ctx . FormInt64 ( "uid" ) ,
Type : user_model . UserTypeIndividual ,
Type : user_model . UserTypeIndividual ,
IsActive : ctx . FormOptionalBool ( "active" ) ,
IsActive : optional . Some ( true ) ,
ListOptions : l istOptions,
ListOptions : db . ListOptions { PageSize : setting . UI . MembersPagingNum } ,
} )
} )
if err != nil {
if err != nil {
ctx . JSON ( http . StatusInternalServerError , map [ string ] any {
ctx . ServerError ( "Unable to search users" , err )
"ok" : false ,
"error" : err . Error ( ) ,
} )
return
return
}
}
ctx . JSON ( http . StatusOK , map [ string ] any { "data" : convert . ToUsers ( ctx , ctx . Doer , users ) } )
ctx . SetTotalCountHeader ( maxResults )
ctx . JSON ( http . StatusOK , map [ string ] any {
"ok" : true ,
"data" : convert . ToUsers ( ctx , ctx . Doer , users ) ,
} )
}
}