mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add 'Show all tokens' toggle for owners (#6325)
* add tokens switch * reorged TokensPage * using Trans component for description * using Trans component on DeleteDialog * add owner col * simplify hook return * lint * type for response * PR feedback * fix lint
This commit is contained in:
+7
-2
@@ -90,6 +90,11 @@ type TokensFilter struct {
|
||||
IncludeAll bool `json:"include_all"`
|
||||
}
|
||||
|
||||
type APIKeyWithOwner struct {
|
||||
APIKey
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
// asRequestOption returns a function that can be used in (*Client).Request.
|
||||
// It modifies the request query parameters.
|
||||
func (f TokensFilter) asRequestOption() RequestOption {
|
||||
@@ -101,7 +106,7 @@ func (f TokensFilter) asRequestOption() RequestOption {
|
||||
}
|
||||
|
||||
// Tokens list machine API keys.
|
||||
func (c *Client) Tokens(ctx context.Context, userID string, filter TokensFilter) ([]APIKey, error) {
|
||||
func (c *Client) Tokens(ctx context.Context, userID string, filter TokensFilter) ([]APIKeyWithOwner, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/users/%s/keys/tokens", userID), nil, filter.asRequestOption())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -110,7 +115,7 @@ func (c *Client) Tokens(ctx context.Context, userID string, filter TokensFilter)
|
||||
if res.StatusCode > http.StatusOK {
|
||||
return nil, ReadBodyAsError(res)
|
||||
}
|
||||
apiKey := []APIKey{}
|
||||
apiKey := []APIKeyWithOwner{}
|
||||
return apiKey, json.NewDecoder(res.Body).Decode(&apiKey)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user