]> source.dussan.org Git - gitea.git/commitdiff
Add support for search by uid (#4876)
authorzeripath <art27@cantab.net>
Thu, 18 Oct 2018 08:44:51 +0000 (09:44 +0100)
committerLunny Xiao <xiaolunwen@gmail.com>
Thu, 18 Oct 2018 08:44:51 +0000 (16:44 +0800)
Signed-off-by: Andrew Thornton <art27@cantab.net>
models/user.go
routers/api/v1/user/user.go
templates/swagger/v1_json.tmpl

index 01c7f5048993a4c0a695dac3a6dfc65a72216a2b..6a9828d5739c38121aa0b7f67b69d5ef8b2d471f 100644 (file)
@@ -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()})
        }
index edd5d1b1cbb91d46bbbed7ff29b635b6bc46845f..38576a7337df2e6b3fa3d5442358d507003023c8 100644 (file)
@@ -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(),
        }
index 18fb34ff4525eeaf99ccf702d885b661e9567af9..e6cdfc0270ee39ceda3a71f023b2e7f9c486bcb5 100644 (file)
             "name": "q",
             "in": "query"
           },
+          {
+            "type": "integer",
+            "description": "ID of the user to search for",
+            "name": "uid",
+            "in": "query"
+          },
           {
             "type": "integer",
             "description": "maximum number of users to return",