Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(coderd/database): match group name case-insensitively in search - #27894

Merged
david-fraley merged 1 commit into
mainfrom
dfraley/product-518-group-search-case-insensitive
Aug 5, 2026
Merged

fix(coderd/database): match group name case-insensitively in search#27894
david-fraley merged 1 commit into
mainfrom
dfraley/product-518-group-search-case-insensitive

Conversation

@david-fraley

Copy link
Copy Markdown
Collaborator

Problem

coder list --search shared_with_group:<org>/<name> fails whenever the group's name contains uppercase letters.

The workspace search parser lowercases the entire query string before the value is resolved, but GetGroupByOrgAndName matched the name with an exact-case comparison (name = $2). The lowercased value therefore never matched a mixed-case group, and the API returned a misleading error implying the group does not exist or the caller is unauthorized. The sibling GetOrganizationByName already uses LOWER("name") = LOWER(@name), so the org half of the reference worked case-insensitively while the group half did not. Looking up a group by UUID was unaffected.

Fixes PRODUCT-518.

Changes

  • coderd/database/queries/groups.sql: GetGroupByOrgAndName now matches the name case-insensitively (LOWER("name") = LOWER(@name)), consistent with organization and workspace name lookups. Regenerated queries.sql.go via sqlc.
  • enterprise/coderd/groups.go: guard the group-rename conflict check so it excludes the group being renamed. Because the lookup is now case-insensitive, a case-only rename (e.g. supportshare -> SupportShare) would otherwise match itself and be falsely rejected.
  • Tests: added TestSearchWorkspace/SharedWithGroupInOrgMixedCase and TestPatchGroup/RenameCasingOnlyOK.

This is a backend/CLI behavior fix with no UI changes. Test output is included below as evidence.

$ go test ./coderd/searchquery/ -run 'TestSearchWorkspace/SharedWithGroup' -count=1
ok  github.com/coder/coder/v2/coderd/searchquery 2.631s

$ go test ./enterprise/coderd/ -run 'TestPatchGroup/RenameCasingOnlyOK|TestPatchGroup/NameConflict|TestPatchGroup/SameNameOK' -count=1
ok  github.com/coder/coder/v2/enterprise/coderd 0.242s
Scope notes / decision log
  • The Linear issue also suggested improving the error message to distinguish "not found" from "unauthorized" from "org not found", and mentioned --shared-with-me / --shared-with-group CLI ergonomics. Those are separate concerns and are intentionally left out of this bug fix to keep it minimal and reviewable.
  • The groups table has a case-sensitive unique constraint UNIQUE (name, organization_id), so two groups differing only by case can technically coexist; in that rare case the case-insensitive lookup returns one arbitrarily (LIMIT 1). This matches existing organization lookup behavior. Enforcing case-insensitive uniqueness on group creation would require a schema/migration change and is out of scope.
  • The change also makes ExtractGroupByNameParam (group-by-name URL resolution) case-insensitive, which is consistent with organization URL resolution.

This PR was generated by Coder Agents on behalf of @david-fraley.

shared_with_group:<org>/<name> workspace searches failed whenever the
group name contained uppercase letters. The search parser lowercases the
whole query before resolving the group, but GetGroupByOrgAndName matched
the name with an exact-case comparison, so the lookup missed the row and
returned a misleading not-found/unauthorized error.

Make GetGroupByOrgAndName case-insensitive with LOWER(name) = LOWER(@name),
matching GetOrganizationByName and workspace name lookups. Guard the group
rename conflict check so a case-only rename does not match itself.

Fixes PRODUCT-518.
@linear-code

linear-code Bot commented Aug 5, 2026

Copy link
Copy Markdown

PRODUCT-518

@Emyrk Emyrk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

We should block naming multiple groups with the same letters of different casing anyway. If there is not already a constraint on the db for that

@david-fraley
david-fraley merged commit d458fe4 into main Aug 5, 2026
49 of 51 checks passed
@david-fraley
david-fraley deleted the dfraley/product-518-group-search-case-insensitive branch August 5, 2026 19:21
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants