Thanks to visit codestin.com
Credit goes to github.com

Skip to content
18 changes: 18 additions & 0 deletions coderd/coderdtest/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,24 @@ func UsersFilter(
return u.Username == "before1"
},
},
{
Name: "ExactUsername",
Filter: codersdk.UsersRequest{
SearchQuery: "username:" + strings.ToUpper(users[0].Username),
},
FilterF: func(_ codersdk.UsersRequest, u codersdk.User) bool {
return strings.EqualFold(u.Username, users[0].Username)
},
},
{
Name: "ExactEmail",
Filter: codersdk.UsersRequest{
SearchQuery: "email:" + strings.ToUpper(users[0].Email),
},
FilterF: func(_ codersdk.UsersRequest, u codersdk.User) bool {
return strings.EqualFold(u.Email, users[0].Email)
},
},
{
Name: "NameNoMatch",
Filter: codersdk.UsersRequest{
Expand Down
116 changes: 74 additions & 42 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions coderd/database/queries/groupmembers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ WHERE
user_name ILIKE concat('%', @name, '%')
ELSE true
END
-- Filter by exact username
AND CASE
WHEN @exact_username :: text != '' THEN
lower(user_username) = lower(@exact_username)
ELSE true
END
-- Filter by exact email
AND CASE
WHEN @exact_email :: text != '' THEN
lower(user_email) = lower(@exact_email)
ELSE true
END
-- Filter by status
AND CASE
-- @status needs to be a text because it can be empty, If it was
Expand Down
12 changes: 12 additions & 0 deletions coderd/database/queries/organizationmembers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ WHERE
users.name ILIKE concat('%', @name, '%')
ELSE true
END
-- Filter by exact username
AND CASE
WHEN @exact_username :: text != '' THEN
lower(users.username) = lower(@exact_username)
ELSE true
END
-- Filter by exact email
AND CASE
WHEN @exact_email :: text != '' THEN
lower(users.email) = lower(@exact_email)
ELSE true
END
-- Filter by status
AND CASE
-- @status needs to be a text because it can be empty, If it was
Expand Down
2 changes: 2 additions & 0 deletions coderd/members.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ func (api *API) paginatedMembers(rw http.ResponseWriter, r *http.Request) {
IncludeSystem: false,
Search: userFilterParams.Search,
Name: userFilterParams.Name,
ExactUsername: userFilterParams.ExactUsername,
ExactEmail: userFilterParams.ExactEmail,
Status: userFilterParams.Status,
IsServiceAccount: userFilterParams.IsServiceAccount,
RbacRole: userFilterParams.RbacRole,
Expand Down
2 changes: 2 additions & 0 deletions coderd/searchquery/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func Users(query string) (database.GetUsersParams, []codersdk.ValidationError) {
filter := database.GetUsersParams{
Search: parser.String(values, "", "search"),
Name: parser.String(values, "", "name"),
ExactUsername: parser.String(values, "", "username"),
ExactEmail: parser.String(values, "", "email"),
Status: httpapi.ParseCustomList(parser, values, []database.UserStatus{}, "status", httpapi.ParseEnum[database.UserStatus]),
IsServiceAccount: parser.NullableBoolean(values, sql.NullBool{}, "service_account"),
RbacRole: parser.Strings(values, []string{}, "role"),
Expand Down
20 changes: 20 additions & 0 deletions coderd/searchquery/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,26 @@ func TestSearchUsers(t *testing.T) {
LoginType: []database.LoginType{},
},
},
{
Name: "UsernameFilter",
Query: "username:Alice",
Expected: database.GetUsersParams{
ExactUsername: "alice",
Status: []database.UserStatus{},
RbacRole: []string{},
LoginType: []database.LoginType{},
},
},
{
Name: "EmailFilter",
Query: "email:[email protected]",
Expected: database.GetUsersParams{
ExactEmail: "[email protected]",
Status: []database.UserStatus{},
RbacRole: []string{},
LoginType: []database.LoginType{},
},
},
{
Name: "NameFilterWithOtherParams",
Query: "name:John status:active role:owner",
Expand Down
2 changes: 2 additions & 0 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ func (api *API) GetUsers(rw http.ResponseWriter, r *http.Request) ([]database.Us
AfterID: paginationParams.AfterID,
Search: params.Search,
Name: params.Name,
ExactUsername: params.ExactUsername,
ExactEmail: params.ExactEmail,
Status: params.Status,
IsServiceAccount: params.IsServiceAccount,
RbacRole: params.RbacRole,
Expand Down
6 changes: 6 additions & 0 deletions docs/admin/users/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
authentication (MFA). It is your responsibility to ensure the auth provider
enforces MFA correctly.

## Configuring SSO

Check warning on line 8 in docs/admin/users/index.md

View workflow job for this annotation

GitHub Actions / lint-docs

Coder.GerundHeading

Heading starts with an -ing word ('Configuring'); prefer the imperative ('Install') or the noun ('Installation'). See capitalization-and-punctuation.md#no-gerund-leading-headings.

- [OpenID Connect](./oidc-auth/index.md) (e.g. Okta, KeyCloak, PingFederate, Azure AD)
- [GitHub](./github-auth.md) (or GitHub Enterprise)
Expand Down Expand Up @@ -170,7 +170,7 @@
> Resetting a user's password, e.g., the initial `owner` role-based user, only
> works when run on the host running the Coder control plane.

### Resetting a password on Kubernetes

Check warning on line 173 in docs/admin/users/index.md

View workflow job for this annotation

GitHub Actions / lint-docs

Coder.GerundHeading

Heading starts with an -ing word ('Resetting'); prefer the imperative ('Install') or the noun ('Installation'). See capitalization-and-punctuation.md#no-gerund-leading-headings.

```sh
kubectl exec -it deployment/coder -n coder -- /bin/bash
Expand Down Expand Up @@ -201,6 +201,12 @@

The following filters are supported:

- `username` - Matches the exact username of the user. The match ignores
letter case.
- `email` - Matches the exact email address of the user. The match ignores
letter case.
- `name` - Matches part of the display name of the user. The match ignores
letter case.
- `status` - Indicates the status of the user. It can be either `active`,
`dormant` or `suspended`.
- `role` - Represents the role of the user. You can refer to the
Expand Down
2 changes: 2 additions & 0 deletions enterprise/coderd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ func (api *API) groupMembers(rw http.ResponseWriter, r *http.Request) {
IncludeSystem: false,
Search: userFilterParams.Search,
Name: userFilterParams.Name,
ExactUsername: userFilterParams.ExactUsername,
ExactEmail: userFilterParams.ExactEmail,
Status: userFilterParams.Status,
IsServiceAccount: userFilterParams.IsServiceAccount,
RbacRole: userFilterParams.RbacRole,
Expand Down
Loading