Skip to content

Commit dd62ca7

Browse files
zeripathlunny
authored andcommitted
Add support for search by uid (#4876)
Signed-off-by: Andrew Thornton <[email protected]>
1 parent 7bb4d61 commit dd62ca7

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

models/user.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ func GetUser(user *User) (bool, error) {
13371337
type SearchUserOptions struct {
13381338
Keyword string
13391339
Type UserType
1340+
UID int64
13401341
OrderBy SearchOrderBy
13411342
Page int
13421343
PageSize int // Can be smaller than or equal to setting.UI.ExplorePagingNum
@@ -1355,9 +1356,14 @@ func (opts *SearchUserOptions) toConds() builder.Cond {
13551356
if opts.SearchByEmail {
13561357
keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword})
13571358
}
1359+
13581360
cond = cond.And(keywordCond)
13591361
}
13601362

1363+
if opts.UID > 0 {
1364+
cond = cond.And(builder.Eq{"id": opts.UID})
1365+
}
1366+
13611367
if !opts.IsActive.IsNone() {
13621368
cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()})
13631369
}

routers/api/v1/user/user.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ func Search(ctx *context.APIContext) {
2727
// in: query
2828
// description: keyword
2929
// type: string
30+
// - name: uid
31+
// in: query
32+
// description: ID of the user to search for
33+
// type: integer
3034
// - name: limit
3135
// in: query
3236
// description: maximum number of users to return
@@ -45,6 +49,7 @@ func Search(ctx *context.APIContext) {
4549
// "$ref": "#/definitions/User"
4650
opts := &models.SearchUserOptions{
4751
Keyword: strings.Trim(ctx.Query("q"), " "),
52+
UID: com.StrTo(ctx.Query("uid")).MustInt64(),
4853
Type: models.UserTypeIndividual,
4954
PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
5055
}

templates/swagger/v1_json.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5203,6 +5203,12 @@
52035203
"name": "q",
52045204
"in": "query"
52055205
},
5206+
{
5207+
"type": "integer",
5208+
"description": "ID of the user to search for",
5209+
"name": "uid",
5210+
"in": "query"
5211+
},
52065212
{
52075213
"type": "integer",
52085214
"description": "maximum number of users to return",

0 commit comments

Comments
 (0)