mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: refactor workspace conversion to accept ownerName (#10171)
Refactors workspace conversion to accept the ownerName, rather than a slice of users, since all it does is search the slice for the owner and use the username. This is in preparation for a fix to `postWorkspacesByOrganization()` that will remove the need to pass the user object. Also avoids panicing if the required user is not in the slice, since `findUser` could return nil in the old code, which would then get dereferenced for the username.
This commit is contained in:
@ -1177,13 +1177,13 @@ func userOrganizationIDs(ctx context.Context, api *API, user database.User) ([]u
|
||||
return member.OrganizationIDs, nil
|
||||
}
|
||||
|
||||
func findUser(id uuid.UUID, users []database.User) *database.User {
|
||||
for _, u := range users {
|
||||
if u.ID == id {
|
||||
return &u
|
||||
func usernameWithID(id uuid.UUID, users []database.User) (string, bool) {
|
||||
for _, user := range users {
|
||||
if id == user.ID {
|
||||
return user.Username, true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return "", false
|
||||
}
|
||||
|
||||
func convertAPIKey(k database.APIKey) codersdk.APIKey {
|
||||
|
Reference in New Issue
Block a user