Skip to content

Commit 5644010

Browse files
committed
add support
1 parent 9c08637 commit 5644010

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

routers/api/v1/user/user.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ func Search(ctx *context.APIContext) {
6868
users = []*user_model.User{user_model.NewActionsUser()}
6969
default:
7070
users, maxResults, err = user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
71-
Actor: ctx.Doer,
72-
Keyword: ctx.FormTrim("q"),
73-
UID: uid,
74-
Type: user_model.UserTypeIndividual,
75-
ListOptions: listOptions,
71+
Actor: ctx.Doer,
72+
Keyword: ctx.FormTrim("q"),
73+
UID: uid,
74+
Type: user_model.UserTypeIndividual,
75+
SearchByEmail: true,
76+
ListOptions: listOptions,
7677
})
7778
if err != nil {
7879
ctx.JSON(http.StatusInternalServerError, map[string]any{

tests/integration/api_user_search_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,19 @@ func TestAPIUserSearchNotLoggedInUserHidden(t *testing.T) {
109109
DecodeJSON(t, resp, &results)
110110
assert.Empty(t, results.Data)
111111
}
112+
113+
func TestAPIUserSearchByEmail(t *testing.T) {
114+
defer tests.PrepareTestEnv(t)()
115+
adminUsername := "user1"
116+
session := loginUser(t, adminUsername)
117+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadUser)
118+
query := "[email protected]"
119+
req := NewRequestf(t, "GET", "/api/v1/users/search?q=%s", query).
120+
AddTokenAuth(token)
121+
resp := MakeRequest(t, req, http.StatusOK)
122+
123+
var results SearchResults
124+
DecodeJSON(t, resp, &results)
125+
assert.Equal(t, 1, len(results.Data))
126+
assert.Equal(t, query, results.Data[0].Email)
127+
}

0 commit comments

Comments
 (0)