mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00: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:
+23
-2
@@ -216,9 +216,30 @@ func (api *API) tokens(rw http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var apiKeys []codersdk.APIKey
|
||||
var userIds []uuid.UUID
|
||||
for _, key := range keys {
|
||||
apiKeys = append(apiKeys, convertAPIKey(key))
|
||||
userIds = append(userIds, key.UserID)
|
||||
}
|
||||
|
||||
users, _ := api.Database.GetUsersByIDs(ctx, userIds)
|
||||
usersByID := map[uuid.UUID]database.User{}
|
||||
for _, user := range users {
|
||||
usersByID[user.ID] = user
|
||||
}
|
||||
|
||||
var apiKeys []codersdk.APIKeyWithOwner
|
||||
for _, key := range keys {
|
||||
if user, exists := usersByID[key.UserID]; exists {
|
||||
apiKeys = append(apiKeys, codersdk.APIKeyWithOwner{
|
||||
APIKey: convertAPIKey(key),
|
||||
Username: user.Username,
|
||||
})
|
||||
} else {
|
||||
apiKeys = append(apiKeys, codersdk.APIKeyWithOwner{
|
||||
APIKey: convertAPIKey(key),
|
||||
Username: "",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
httpapi.Write(ctx, rw, http.StatusOK, apiKeys)
|
||||
|
||||
Reference in New Issue
Block a user