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:
Spike Curtis
2023-10-10 16:55:28 +04:00
committed by GitHub
parent 19400d6794
commit db8592fa93
4 changed files with 90 additions and 48 deletions

View File

@ -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 {