mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd/database): match group name case-insensitively in search (#27894)
This commit is contained in:
@@ -199,11 +199,14 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if req.Name != "" && req.Name != group.Name {
|
||||
_, err := api.Database.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
|
||||
existing, err := api.Database.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
|
||||
OrganizationID: group.OrganizationID,
|
||||
Name: req.Name,
|
||||
})
|
||||
if err == nil {
|
||||
// GetGroupByOrgAndName matches names case-insensitively, so exclude the
|
||||
// group being renamed. This allows changing only the casing of a name
|
||||
// while still rejecting a name already taken by a different group.
|
||||
if err == nil && existing.ID != group.ID {
|
||||
httpapi.Write(ctx, rw, http.StatusConflict, codersdk.Response{
|
||||
Message: fmt.Sprintf("A group with name %q already exists.", req.Name),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user