mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Allow using username in user queries (#1221)
* feat: Allow using username in user queries * Test needs a username/email to not match empty string
This commit is contained in:
+10
-1
@@ -274,7 +274,16 @@ func (c *Client) Logout(ctx context.Context) error {
|
||||
// User returns a user for the ID provided.
|
||||
// If the uuid is nil, the current user will be returned.
|
||||
func (c *Client) User(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
res, err := c.request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s", uuidOrMe(id)), nil)
|
||||
return c.userByIdentifier(ctx, uuidOrMe(id))
|
||||
}
|
||||
|
||||
// UserByUsername returns a user for the username provided.
|
||||
func (c *Client) UserByUsername(ctx context.Context, username string) (User, error) {
|
||||
return c.userByIdentifier(ctx, username)
|
||||
}
|
||||
|
||||
func (c *Client) userByIdentifier(ctx context.Context, ident string) (User, error) {
|
||||
res, err := c.request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s", ident), nil)
|
||||
if err != nil {
|
||||
return User{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user