Skip to content

Commit f30665c

Browse files
committed
only validate name if it's different
1 parent ee44145 commit f30665c

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

coderd/organizations.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,31 @@ func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) {
137137
return
138138
}
139139

140-
if req.Name == codersdk.DefaultOrganization && !organization.IsDefault {
141-
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
142-
Message: fmt.Sprintf("Organization name %q is reserved.", codersdk.DefaultOrganization),
143-
})
144-
return
145-
}
140+
if req.Name != organization.Name {
141+
if req.Name == codersdk.DefaultOrganization && !organization.IsDefault {
142+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
143+
Message: fmt.Sprintf("Organization name %q is reserved.", codersdk.DefaultOrganization),
144+
})
145+
return
146+
}
146147

147-
_, err := api.Database.GetOrganizationByName(ctx, req.Name)
148-
if err == nil {
149-
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
150-
Message: "Organization already exists with that name.",
151-
})
152-
return
153-
}
154-
if !errors.Is(err, sql.ErrNoRows) {
155-
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
156-
Message: fmt.Sprintf("Internal error fetching organization %q.", req.Name),
157-
Detail: err.Error(),
158-
})
159-
return
148+
_, err := api.Database.GetOrganizationByName(ctx, req.Name)
149+
if err == nil {
150+
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
151+
Message: "Organization already exists with that name.",
152+
})
153+
return
154+
}
155+
if !errors.Is(err, sql.ErrNoRows) {
156+
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
157+
Message: fmt.Sprintf("Internal error fetching organization %q.", req.Name),
158+
Detail: err.Error(),
159+
})
160+
return
161+
}
160162
}
161163

162-
organization, err = api.Database.UpdateOrganization(ctx, database.UpdateOrganizationParams{
164+
organization, err := api.Database.UpdateOrganization(ctx, database.UpdateOrganizationParams{
163165
ID: organization.ID,
164166
UpdatedAt: dbtime.Now(),
165167
Name: req.Name,

0 commit comments

Comments
 (0)