diff options
author | zeripath <art27@cantab.net> | 2018-10-18 09:44:51 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2018-10-18 16:44:51 +0800 |
commit | dd62ca7ba9b49e799a8bea896cff1b209f813b7e (patch) | |
tree | 6d3ff7da203b6548195ddd37c205c5d5ba7453dc | |
parent | 7bb4d610e5cca7ad514e377d2b36254a4cfee5b9 (diff) | |
download | gitea-dd62ca7ba9b49e799a8bea896cff1b209f813b7e.tar.gz gitea-dd62ca7ba9b49e799a8bea896cff1b209f813b7e.zip |
Add support for search by uid (#4876)
Signed-off-by: Andrew Thornton <art27@cantab.net>
-rw-r--r-- | models/user.go | 6 | ||||
-rw-r--r-- | routers/api/v1/user/user.go | 5 | ||||
-rw-r--r-- | templates/swagger/v1_json.tmpl | 6 |
3 files changed, 17 insertions, 0 deletions
diff --git a/models/user.go b/models/user.go index 01c7f50489..6a9828d573 100644 --- a/models/user.go +++ b/models/user.go @@ -1337,6 +1337,7 @@ func GetUser(user *User) (bool, error) { type SearchUserOptions struct { Keyword string Type UserType + UID int64 OrderBy SearchOrderBy Page int 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 { keywordCond = keywordCond.Or(builder.Like{"LOWER(email)", lowerKeyword}) } + cond = cond.And(keywordCond) } + if opts.UID > 0 { + cond = cond.And(builder.Eq{"id": opts.UID}) + } + if !opts.IsActive.IsNone() { cond = cond.And(builder.Eq{"is_active": opts.IsActive.IsTrue()}) } diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index edd5d1b1cb..38576a7337 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -27,6 +27,10 @@ func Search(ctx *context.APIContext) { // in: query // description: keyword // type: string + // - name: uid + // in: query + // description: ID of the user to search for + // type: integer // - name: limit // in: query // description: maximum number of users to return @@ -45,6 +49,7 @@ func Search(ctx *context.APIContext) { // "$ref": "#/definitions/User" opts := &models.SearchUserOptions{ Keyword: strings.Trim(ctx.Query("q"), " "), + UID: com.StrTo(ctx.Query("uid")).MustInt64(), Type: models.UserTypeIndividual, PageSize: com.StrTo(ctx.Query("limit")).MustInt(), } diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 18fb34ff45..e6cdfc0270 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5205,6 +5205,12 @@ }, { "type": "integer", + "description": "ID of the user to search for", + "name": "uid", + "in": "query" + }, + { + "type": "integer", "description": "maximum number of users to return", "name": "limit", "in": "query" |