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)

highbugapp/controllers/groups_controller.rb:22-26

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.

mediumbugapp/controllers/admin/groups_controller.rb:71-75

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`.

mediumbugapp/controllers/admin/groups_controller.rb:90

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.

mediumbugapp/assets/javascripts/admin/controllers/admin-group.js.es6:11-14

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.

mediumbugapp/controllers/admin/groups_controller.rb:90

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.

Gold bugs found (5)

mediumThe admin group pager computes total pages as floor(user_count / limit) + 1, so when the member count is an exact multiple of the limit it shows an extra page and Next navigates to an empty member list.
highThe public members endpoint now always caps results at 50 per page, but the public group members page has no pagination, so groups with more than 50 members are silently truncated for users.
mediumRemoving a member deletes the membership row directly and skips clearing the user's primary_group_id, so a removed user can keep this group as their primary group.
mediumAdmin add_members pushes every username into group.users without skipping existing members, so adding someone already in the group hits the unique group_users index, returns a 500 and leaves earlier users partially added.
mediumAdmin remove_member calls group.users.delete with a raw integer id, which raises RecordNotFound (404/500) when the user is not or no longer a member, e.g. on concurrent removal.

Gold bugs missed (5)

mediumPaging actions fire overlapping member requests and each response unconditionally overwrites offset and members, so a stale response arriving last can revert the list to an earlier page.
mediumCreating a group ignores the alias_level the admin selected, saving only name and visibility, so new groups keep the default alias level.
mediumGroup member pagination is off by one when user_count is a multiple of limit: Next moves to offset == user_count and shows an empty page.
mediumAdmin remove_member deletes memberships with group.users.delete, which skips GroupUser callbacks, so the cached groups.user_count is never decremented and stays inflated.
mediumThe public group members endpoint takes `limit` from params with no upper bound or positivity check, letting a visitor request huge pages or trigger a 500 with a negative limit.