File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -111,15 +111,21 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
111
111
}
112
112
}
113
113
if req .Name != "" {
114
- _ , err := api .Database .GetGroupByOrgAndName (ctx , database.GetGroupByOrgAndNameParams {
114
+ existingGroup , err := api .Database .GetGroupByOrgAndName (ctx , database.GetGroupByOrgAndNameParams {
115
115
OrganizationID : group .OrganizationID ,
116
116
Name : req .Name ,
117
117
})
118
118
if err == nil {
119
- httpapi .Write (ctx , rw , http .StatusConflict , codersdk.Response {
120
- Message : fmt .Sprintf ("A group with name %q already exists." , req .Name ),
121
- })
122
- return
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 = ""
123
129
}
124
130
}
125
131
@@ -139,7 +145,7 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
139
145
140
146
group , err = tx .UpdateGroupByID (ctx , database.UpdateGroupByIDParams {
141
147
ID : group .ID ,
142
- Name : req .Name ,
148
+ Name : group .Name ,
143
149
AvatarURL : group .AvatarURL ,
144
150
})
145
151
if err != nil {
You can’t perform that action at this time.
0 commit comments