mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: resolve missing users in <UserCombobox /> (#21822)
Closes #21044 This pull-request addresses an issue we were seeing where we would attempt to filter the `<UserCombobox />` by the users username or email not their username (which the rendered options would show). To highlight this I created three different users. Each with a username that did not contain their `email` or `name` and attempted to filter. Attempting to search for `John` wouldn't actually show the user as his username was `x`, and infact whereas a subset of users might be returned from the backend for having `john` in the `email` it would've been filtered by the frontend for not being in the `name` field. | Name | Username | | --- | --- | | `Jake` | `z` | | `Jeff` | `y` | | `John` | `x` | | Previously | Now | | --- | --- | | <img width="560" height="547" alt="OLD_USER_COMBOBOX" src="https://github.com/user-attachments/assets/a0567264-0034-42ac-aba0-95b05c4f92dd" /> | <img width="580" height="548" alt="NEW_USER_COMBOBOX" src="https://github.com/user-attachments/assets/1aa0c942-d340-4b1c-8dde-b97879525bfb" /> |
This commit is contained in:
@@ -156,6 +156,7 @@ func Users(query string) (database.GetUsersParams, []codersdk.ValidationError) {
|
||||
parser := httpapi.NewQueryParamParser()
|
||||
filter := database.GetUsersParams{
|
||||
Search: parser.String(values, "", "search"),
|
||||
Name: parser.String(values, "", "name"),
|
||||
Status: httpapi.ParseCustomList(parser, values, []database.UserStatus{}, "status", httpapi.ParseEnum[database.UserStatus]),
|
||||
RbacRole: parser.Strings(values, []string{}, "role"),
|
||||
LastSeenAfter: parser.Time3339Nano(values, time.Time{}, "last_seen_after"),
|
||||
|
||||
@@ -754,6 +754,49 @@ func TestSearchUsers(t *testing.T) {
|
||||
},
|
||||
},
|
||||
|
||||
// Name filter tests
|
||||
{
|
||||
Name: "NameFilter",
|
||||
Query: "name:John",
|
||||
Expected: database.GetUsersParams{
|
||||
Name: "john",
|
||||
Status: []database.UserStatus{},
|
||||
RbacRole: []string{},
|
||||
LoginType: []database.LoginType{},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "NameFilterQuoted",
|
||||
Query: `name:"John Doe"`,
|
||||
Expected: database.GetUsersParams{
|
||||
Name: "john doe",
|
||||
Status: []database.UserStatus{},
|
||||
RbacRole: []string{},
|
||||
LoginType: []database.LoginType{},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "NameFilterWithSearch",
|
||||
Query: "name:John search:johnd",
|
||||
Expected: database.GetUsersParams{
|
||||
Search: "johnd",
|
||||
Name: "john",
|
||||
Status: []database.UserStatus{},
|
||||
RbacRole: []string{},
|
||||
LoginType: []database.LoginType{},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "NameFilterWithOtherParams",
|
||||
Query: "name:John status:active role:owner",
|
||||
Expected: database.GetUsersParams{
|
||||
Name: "john",
|
||||
Status: []database.UserStatus{database.UserStatusActive},
|
||||
RbacRole: []string{codersdk.RoleOwner},
|
||||
LoginType: []database.LoginType{},
|
||||
},
|
||||
},
|
||||
|
||||
// Failures
|
||||
{
|
||||
Name: "ExtraColon",
|
||||
|
||||
Reference in New Issue
Block a user