DeepSeek V4 Pro · Heavy

fix-proper-handling-of-group-memberships-discourse-cursor

Discourse · Ruby · L · 300–799 lines · 6 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
4 of 13
Comments published
6
Comments matching a bug
4
Comments not matching
2
Cost of this PR
$1.617

Published comments (6)

highbugapp/controllers/admin/groups_controller.rb:66

add_members and remove_member read missing :group_id param — These routes expose the id as `params[:id]`, not `params[:group_id]`, so every add/remove request raises `ActionController::ParameterMissing` and returns 400. Read `params[:id]` like `update` and `destroy` do. **Also found in:** - `app/controllers/admin/groups_controller.rb:85-85`

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

add_members re-adds existing members causing RecordNotUnique — Re-adding an existing member hits the unique `(group_id, user_id)` index and returns a 500 instead of succeeding silently. Skip usernames that are already members before calling `group.add`.

mediumbugapp/assets/javascripts/discourse/models/group.js:45-47

Reset group members offset after deleting last member on page — The stored `offset` can point past the last member after a delete, so `findMembers()` requests an empty page while members exist on the previous one. Clamp the offset before reloading.

mediumbugapp/controllers/groups_controller.rb:22-23

Default 50 member limit truncates public group member lists — Any public group over 50 members is silently truncated because the endpoint now paginates by default and the public template has no pager. Add pagination to the public page or fetch all members for that consumer.

mediumbugspec/controllers/admin/groups_controller_spec.rb:114-116

Use DELETE verb in remove_member spec — Controller specs bypass routing, so this would still pass if the DELETE route broke or was removed. Use `xhr :delete` to match the endpoint defined in `config/routes.rb`.

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

totalPages overcounts pages when user_count is an exact multiple of limit — This reports an extra empty page whenever `user_count` is an exact multiple of `limit`, so `next` can navigate past the last member. Use `Math.ceil(user_count / limit)` instead.

Gold bugs found (4)

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

Gold bugs missed (9)

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