Skip to content

Commit

Permalink
Add 'search' query parameter for GET /users
Browse files Browse the repository at this point in the history
* Search query param for GetUsers
* Update Swagger and remove max query parameter
  • Loading branch information
harture committed May 10, 2019
1 parent 17eee91 commit e623f38
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion api/management/swagger-api_management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ paths:
in: query
schema:
type: string
allowEmptyValue: true
allowEmptyValue: true
- name: search
in: query
schema:
type: string
allowEmptyValue: true
responses:
200:
description: successful operation
Expand Down
2 changes: 1 addition & 1 deletion pkg/management/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func MakeGetUsersEndpoint(managementComponent ManagementComponent) endpoint.Endp
var m = req.(map[string]string)

var paramKV []string
for _, key := range []string{"email", "firstName", "lastName", "max", "username"} {
for _, key := range []string{"email", "firstName", "lastName", "username", "search"} {
if m[key] != "" {
paramKV = append(paramKV, key, m[key])
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/management/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ func TestGetUsersEndpoint(t *testing.T) {
req["email"] = "email@elca.ch"
req["firstName"] = "firstname"
req["lastName"] = "lastname"
req["max"] = "10"
req["search"] = "search"
req["username"] = "username"
req["toto"] = "tutu" // Check this param is not transmitted
req["groupIds"] = "123-784dsf-sdf567"

mockManagementComponent.EXPECT().GetUsers(ctx, realm, []string{req["groupIds"]}, "email", req["email"], "firstName", req["firstName"], "lastName", req["lastName"], "max", req["max"], "username", req["username"]).Return([]api.UserRepresentation{}, nil).Times(1)
mockManagementComponent.EXPECT().GetUsers(ctx, realm, []string{req["groupIds"]}, "email", req["email"], "firstName", req["firstName"], "lastName", req["lastName"], "username", req["username"], "search", req["search"],).Return([]api.UserRepresentation{}, nil).Times(1)
var res, err = e(ctx, req)
assert.Nil(t, err)
assert.NotNil(t, res)
Expand Down
2 changes: 1 addition & 1 deletion pkg/management/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func decodeManagementRequest(_ context.Context, req *http.Request) (interface{},
buf.ReadFrom(req.Body)
request["body"] = buf.String()

for _, key := range []string{"email", "firstName", "lastName", "max", "username", "client_id", "redirect_uri", "lifespan", "groupIds"} {
for _, key := range []string{"email", "firstName", "lastName", "username", "search", "client_id", "redirect_uri", "lifespan", "groupIds"} {
if value := req.URL.Query().Get(key); value != "" {
request[key] = value
}
Expand Down

0 comments on commit e623f38

Please sign in to comment.