DeepSeek V4 Pro · 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 Opus 5.5.

Gold bugs found
1 of 13
Comments published
3
Comments matching a bug
1
Comments not matching
2
Cost of this PR
$0.522

Published comments (3)

highbugconfig/routes.rb:49-50

Member routes for add/remove members use :id but actions require :group_id — Every add/remove request raises `ActionController::ParameterMissing` and 500s because the group id arrives as `params[:id]`, while `add_members` and `remove_member` read `params.require(:group_id)`. Read `params.require(:id)` in both actions, or use the collection routes shown in the fix.

highbugapp/assets/javascripts/discourse/templates/group/members.hbs:6

Group members template iterates undefined `members` instead of `model.members` — The public group members page renders an empty table because `members` is undefined on the generated plain controller. Iterate `model.members` instead.

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

totalPages is one page too high when user_count is an exact multiple of limit — The real last page never registers as last, and `next` can land the admin on an empty page. Use `Math.ceil(this.get("user_count") / this.get("limit"))`.

Gold bugs found (1)

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.

Gold bugs missed (12)

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.
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.
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.
mediumGroupsController#members now returns {members, meta} with pagination, but the public groups controller spec still expects a bare array and stays pending, so the new response contract is untested.
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.
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.
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.
mediumGroup#removeMember and #addMembers have no rejection handler and the admin controller discards their promises, so failed member additions/removals are silently swallowed with no error shown to the admin.
mediumAfter removeMember succeeds, findMembers reloads with the old offset, clamped only by the stale user_count; removing the only member on the last page (e.g. 51 members, offset 50) requests offset equal to the new total and the admin sees an empty, out-of-range page.