Skip to content

Commit 223182f

Browse files
committed
fix some dumb shit
1 parent 8d1393c commit 223182f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

enterprise/coderd/groups.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
8282
return
8383
}
8484

85+
// If the name matches the existing group name pretend we aren't
86+
// updating the name at all.
87+
if req.Name == group.Name {
88+
req.Name = ""
89+
}
90+
8591
users := make([]string, 0, len(req.AddUsers)+len(req.RemoveUsers))
8692
users = append(users, req.AddUsers...)
8793
users = append(users, req.RemoveUsers...)
@@ -110,22 +116,16 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
110116
return
111117
}
112118
}
113-
if req.Name != "" {
114-
existingGroup, err := api.Database.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
119+
if req.Name != "" && req.Name != group.Name {
120+
_, err := api.Database.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
115121
OrganizationID: group.OrganizationID,
116122
Name: req.Name,
117123
})
118124
if err == nil {
119-
// We may have just queried ourself. This should really
120-
// go in the tx.
121-
if existingGroup.ID != group.ID {
122-
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
123-
Message: fmt.Sprintf("A group with name %q already exists.", req.Name),
124-
})
125-
return
126-
}
127-
// If we queried ourself then we don't want to update the name.
128-
req.Name = ""
125+
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
126+
Message: fmt.Sprintf("A group with name %q already exists.", req.Name),
127+
})
128+
return
129129
}
130130
}
131131

0 commit comments

Comments
 (0)