@@ -82,6 +82,12 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
82
82
return
83
83
}
84
84
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
+
85
91
users := make ([]string , 0 , len (req .AddUsers )+ len (req .RemoveUsers ))
86
92
users = append (users , req .AddUsers ... )
87
93
users = append (users , req .RemoveUsers ... )
@@ -110,22 +116,16 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
110
116
return
111
117
}
112
118
}
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 {
115
121
OrganizationID : group .OrganizationID ,
116
122
Name : req .Name ,
117
123
})
118
124
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
129
129
}
130
130
}
131
131
0 commit comments