Signed-off-by: Andrew Thornton <art27@cantab.net>tags/v1.21.12.1
| @@ -1337,6 +1337,7 @@ func GetUser(user *User) (bool, error) { | |||||
| type SearchUserOptions struct { | type SearchUserOptions struct { | ||||
| Keyword string | Keyword string | ||||
| Type UserType | Type UserType | ||||
| UID int64 | |||||
| OrderBy SearchOrderBy | OrderBy SearchOrderBy | ||||
| Page int | Page int | ||||
| PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum | PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum | ||||
| @@ -1355,9 +1356,14 @@ func (opts *SearchUserOptions) toConds() builder.Cond { | |||||
| if opts.SearchByEmail { | if opts.SearchByEmail { | ||||
| keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) | keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) | ||||
| } | } | ||||
| cond = cond.And(keywordCond) | cond = cond.And(keywordCond) | ||||
| } | } | ||||
| if opts.UID > 0 { | |||||
| cond = cond.And(builder.Eq{"id": opts.UID}) | |||||
| } | |||||
| if !opts.IsActive.IsNone() { | if !opts.IsActive.IsNone() { | ||||
| cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()}) | cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()}) | ||||
| } | } | ||||
| @@ -27,6 +27,10 @@ func Search(ctx *context.APIContext) { | |||||
| // in: query | // in: query | ||||
| // description: keyword | // description: keyword | ||||
| // type: string | // type: string | ||||
| // - name: uid | |||||
| // in: query | |||||
| // description: ID of the user to search for | |||||
| // type: integer | |||||
| // - name: limit | // - name: limit | ||||
| // in: query | // in: query | ||||
| // description: maximum number of users to return | // description: maximum number of users to return | ||||
| @@ -45,6 +49,7 @@ func Search(ctx *context.APIContext) { | |||||
| // "$ref": "#/definitions/User" | // "$ref": "#/definitions/User" | ||||
| opts := &models.SearchUserOptions{ | opts := &models.SearchUserOptions{ | ||||
| Keyword: strings.Trim(ctx.Query("q"), " "), | Keyword: strings.Trim(ctx.Query("q"), " "), | ||||
| UID: com.StrTo(ctx.Query("uid")).MustInt64(), | |||||
| Type: models.UserTypeIndividual, | Type: models.UserTypeIndividual, | ||||
| PageSize: com.StrTo(ctx.Query("limit")).MustInt(), | PageSize: com.StrTo(ctx.Query("limit")).MustInt(), | ||||
| } | } | ||||
| @@ -5203,6 +5203,12 @@ | |||||
| "name": "q", | "name": "q", | ||||
| "in": "query" | "in": "query" | ||||
| }, | }, | ||||
| { | |||||
| "type": "integer", | |||||
| "description": "ID of the user to search for", | |||||
| "name": "uid", | |||||
| "in": "query" | |||||
| }, | |||||
| { | { | ||||
| "type": "integer", | "type": "integer", | ||||
| "description": "maximum number of users to return", | "description": "maximum number of users to return", | ||||