Repository navigation
fix(admin): filter users by the name the list shows - #2070
rohanchkrabrty wants to merge 4 commits into
Conversation
The Name column in the admin users list and the org members list shows the title, or the name when the title is empty. Its filter and sort read only the title, so a user without a title could not be found by the name the list showed. Add a display_name RQL field to SearchUsers and SearchOrganizationUsers. It reads COALESCE(NULLIF(title, ''), name) at query time, so there is no new column and no migration. The title and name filters do not change. SearchUsers now checks its RQL query against user.SearchFields, so user.User no longer has rql tags. An unsupported filter operator on SearchUsers now returns ErrBadInput. The org members list now shows the name when the title is empty.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 29 minutes. View limit details
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Coverage Report for CI Build 47092150236Coverage increased (+0.02%) to 56.486%Details
Uncovered Changes
Coverage Regressions3 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
getNonRoleField now handles only org_joined_at and passes every other name to userField, which moves next to userComputedFields. compare is renamed to buildComparisonCondition to match the other condition builders.
SearchUsers checks the group-by key in addSort, so grouping by display_name returns ErrBadInput instead of a Postgres error. user.SearchFields keeps the metadata filter that user.User allowed. The org members list uses getUserName and an uppercase avatar letter, the same as the users list.
The members Name cell still shows getUserName, but the avatar goes back to the title initial, then the email initial, as on main.
rohilsurana
left a comment
There was a problem hiding this comment.
Overall the approach is right, and performance holds up. I checked filter+sort with EXPLAIN ANALYZE on a local seed of 100k users and a 20k-member org. display_name stays a full scan, same as the old title filter, so no regression. A few inline notes below: two should-fixes, one consistency nit, and a couple of questions.
| query = query.OrderAppend(userField(sort.Name).Asc()) | ||
| case "desc": | ||
| query = query.OrderAppend(goqu.I(sort.Name).Desc()) | ||
| query = query.OrderAppend(userField(sort.Name).Desc()) |
There was a problem hiding this comment.
should-fix: the sort appends only the user-selected field, with no stable tiebreaker. Rows that share a display_name (common now, since every user without a title falls back to name) can repeat or get skipped across OFFSET pages. Adding a final users.id ASC here, and in the org users sort, would make pagination deterministic.
| if field, ok := userComputedFields[name]; ok { | ||
| return field | ||
| } | ||
| return goqu.I(TABLE_USERS + "." + name) |
There was a problem hiding this comment.
should-fix: userField falls through to goqu.I(users.) for any name not in userComputedFields, and addFilter has no allow-list of valid fields. So an unknown RQL filter field builds users. and Postgres errors. A filter on displayname returns a 500 on this branch (reproduced locally). Validating filter names against an allow-list and returning ErrBadInput would make it a clean 400. Note OrgUsersRepository.validateFilters already allow-lists, SearchUsers does not. This was already true for createdat.
| // DataTable filter sends them pre-wrapped. | ||
| case "like": | ||
| return goqu.Cast(goqu.I(columnName), "TEXT").Like(filter.Value.(string)), nil | ||
| return goqu.Cast(field, "TEXT").Like(filter.Value.(string)), nil |
There was a problem hiding this comment.
nit: the two lists handle like differently. Org users uses case-sensitive LIKE with caller-owned wildcards (this line), but SearchUsers.addFilter uses ILIKE and wraps the value in %..% itself. Same operator, different behavior between the Users list and the Org Members list. Worth making them consistent.
| } | ||
|
|
||
| var userComputedFields = map[string]searchField{ | ||
| COLUMN_DISPLAY_NAME: goqu.L("COALESCE(NULLIF(?, ''), ?)", |
There was a problem hiding this comment.
question: NULLIF(title, '') only treats an exactly empty title as absent, so a whitespace-only title would still win over the name. Should a spaces-only title fall back to name too? And on sort order: under byte-order collation, capitalized titles sort before lowercase names, so should the display_name sort use LOWER()? What collation does prod run?
Summary
display_nameRQL field toSearchUsersandSearchOrganizationUsers. It is computed at query time asCOALESCE(NULLIF(title, ''), name), so there is no new column and no migration. Thetitleandnamefilters do not change.display_namefor filter and sort. The org members list now shows the name when the title is empty.SearchUserschecks its RQL query against a newuser.SearchFieldsstruct, souser.Userno longer has rql tags. An unsupported filter operator onSearchUsersnow returnsErrBadInput.