DeepSeek V4.1 Flash · Balanced
fix-proper-handling-of-group-memberships-discourse-cursor
Discourse · Ruby · L · 300–799 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Haiku 5.5.
- Gold bugs found
- 5 of 10
- Comments published
- 5
- Comments matching a bug
- 5
- Comments not matching
- 0
- Cost of this PR
- $0.165
Published comments (5)
Public group members endpoint truncates default member list — Groups with more than 50 members silently hide the rest because the public members template has no pagination and never sends `limit` or `offset`. Page the endpoint from the client or return the full list for visible groups.
add_members fails when adding existing group members — Adding an existing member or repeating a name raises `ActiveRecord::RecordNotUnique` and the request 500s, which is common since the admin UI never filters existing members. Skip usernames already in the group before calling `group.add`.
remove_member raises RecordNotFound when user is not a group member — A stale list, concurrent removal, or double submit turns this into `ActiveRecord::RecordNotFound` instead of a no-op. Look the user up through `group.users.where(id: user_id).first` and delete only when found, still returning success.
totalPages overcounts pages when user_count is a multiple of limit — An exact multiple of `limit` reports a page that does not exist, so `showingLast` stays false and the next arrow loads an empty list. Use `Math.ceil(user_count / limit)` so the last-page guard matches the real page count.
group.users.delete bypasses primary group cleanup and counter cache — Deleting the join row directly bypasses `destroy_deletions`, so a removed user keeps `primary_group_id` set and `user_count` drifts. Route removal through `usernames=` or explicitly clear `primary_group_id` for the removed user.