Skip to content

feat: add avatar urls to groups #4525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 17, 2022
Prev Previous commit
Next Next commit
fix issue where update doesn't work when submitting the existing name
  • Loading branch information
sreya committed Oct 13, 2022
commit e682e134a98698d8fc86b0f4377728c254b6414f
18 changes: 12 additions & 6 deletions enterprise/coderd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,21 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
}
}
if req.Name != "" {
_, err := api.Database.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
existingGroup, err := api.Database.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
OrganizationID: group.OrganizationID,
Name: req.Name,
})
if err == nil {
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
Message: fmt.Sprintf("A group with name %q already exists.", req.Name),
})
return
// We may have just queried ourself. This should really
// go in the tx.
if existingGroup.ID != group.ID {
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
Message: fmt.Sprintf("A group with name %q already exists.", req.Name),
})
return
}
// If we queried ourself then we don't want to update the name.
req.Name = ""
}
}

Expand All @@ -139,7 +145,7 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {

group, err = tx.UpdateGroupByID(ctx, database.UpdateGroupByIDParams{
ID: group.ID,
Name: req.Name,
Name: group.Name,
AvatarURL: group.AvatarURL,
})
if err != nil {
Expand Down