Claude Sonnet 5.5 · 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
3 of 10
Comments published
3
Comments matching a bug
3
Comments not matching
0
Cost of this PR
$0.350

Published comments (3)

highbugapp/assets/javascripts/discourse/routes/group-members.js.es6:8-12

Group members page only loads the first 50 members with no paging — `model.findMembers()` runs once with the default limit of 50, and the `group/members.hbs` template has no paging controls, so larger groups silently show only 50 members. Add pagination to the public members view, or request a limit that covers the whole group.

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

totalPages overcounts by one when user_count is a multiple of limit — When `user_count` is an exact multiple of `limit`, `totalPages` counts an extra page, so `showingLast` stays false on the real last page and 'next' loads an empty page. Use `Math.ceil(user_count / limit)`.

mediumperformanceapp/controllers/groups_controller.rb:22-26

Unbounded limit and negative offset in group members endpoint — `limit` comes straight from `params[:limit].to_i`, so a huge value serializes an entire large group in one request and a negative value causes a database error. Clamp `limit` between 1 and 200, and use `[offset, 0].max` for `offset`.

Gold bugs found (3)

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

Gold bugs missed (7)

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