3
0

Enable user filtering by email and username

This commit is contained in:
Denis Arh
2019-01-22 13:22:35 +01:00
parent 2748847ee9
commit 9557b0ebb5
8 changed files with 56 additions and 4 deletions
+12
View File
@@ -415,6 +415,18 @@
"name": "query",
"required": false,
"title": "Search query to match against users"
},
{
"type": "string",
"name": "username",
"required": false,
"title": "Search username to match against users"
},
{
"type": "string",
"name": "email",
"required": false,
"title": "Search email to match against users"
}
]
}
+12
View File
@@ -29,6 +29,18 @@
"required": false,
"title": "Search query to match against users",
"type": "string"
},
{
"name": "username",
"required": false,
"title": "Search username to match against users",
"type": "string"
},
{
"name": "email",
"required": false,
"title": "Search email to match against users",
"type": "string"
}
]
}
File diff suppressed because one or more lines are too long
+2
View File
@@ -305,6 +305,8 @@ An organisation may have many teams. Teams may have many channels available. Acc
| Parameter | Type | Method | Description | Default | Required? |
| --------- | ---- | ------ | ----------- | ------- | --------- |
| query | string | GET | Search query to match against users | N/A | NO |
| username | string | GET | Search username to match against users | N/A | NO |
| email | string | GET | Search email to match against users | N/A | NO |
## Create user
+10
View File
@@ -118,6 +118,16 @@ func (r *user) Find(filter *types.UserFilter) ([]*types.User, error) {
sql += " OR name LIKE ?)"
params = append(params, filter.Query+"%")
}
if filter.Email != "" {
sql += " AND (email = ?)"
params = append(params, filter.Email)
}
if filter.Username != "" {
sql += " AND (username = ?)"
params = append(params, filter.Username)
}
}
sql += " ORDER BY username ASC"
+11 -1
View File
@@ -33,7 +33,9 @@ var _ = multipart.FileHeader{}
// User list request parameters
type UserList struct {
Query string
Query string
Username string
Email string
}
func NewUserList() *UserList {
@@ -71,6 +73,14 @@ func (u *UserList) Fill(r *http.Request) (err error) {
u.Query = val
}
if val, ok := get["username"]; ok {
u.Username = val
}
if val, ok := get["email"]; ok {
u.Email = val
}
return err
}
+5 -1
View File
@@ -26,7 +26,11 @@ func (User) New() *User {
// Searches the users table in the database to find users by matching (by-prefix) their.Username
func (ctrl *User) List(ctx context.Context, r *request.UserList) (interface{}, error) {
return ctrl.user.With(ctx).Find(&types.UserFilter{Query: r.Query})
return ctrl.user.With(ctx).Find(&types.UserFilter{
Query: r.Query,
Email: r.Email,
Username: r.Username,
})
}
func (ctrl *User) Create(ctx context.Context, r *request.UserCreate) (interface{}, error) {
+3 -1
View File
@@ -33,7 +33,9 @@ type (
}
UserFilter struct {
Query string
Query string
Email string
Username string
}
)