DeepSeek V4.1 Flash · 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 Haiku 5.5.

Gold bugs found
7 of 10
Comments published
8
Comments matching a bug
7
Comments not matching
1
Cost of this PR
$0.304

Published comments (8)

highbugapp/controllers/groups_controller.rb:22-26

Non-automatic group members silently truncated to 50 — Regular groups now return at most 50 members, and the public group page has no pager, so members past 50 are unreachable. Return all members when no `limit` param is supplied, or add pagination to `group-members.js.es6` and `members.hbs`.

mediumbugapp/controllers/admin/groups_controller.rb:22-32

Group creation ignores alias_level parameter — Any alias level picked while creating a group is silently dropped, so the group is saved with the default 0. Assign `group.alias_level = params[:alias_level].to_i if params[:alias_level].present?` as `update` does.

mediumbugapp/controllers/admin/groups_controller.rb:84-97

remove_member bypasses Group#remove and leaves primary_group_id stale — Deleting the join row directly skips `Group#destroy_deletions`, leaving `users.primary_group_id` pointing at a group the user left and skippng the `user_count` decrement. Resolve the user and call `group.remove(user)` instead of `group.users.delete(user_id)`.

mediumbugapp/controllers/admin/groups_controller.rb:84-90

remove_member raises when user is not a group member — Removing a user who is not a member raises `ActiveRecord::RecordNotFound`, so a stale admin UI or a concurrent removal returns an error. Look up the membership with `group.group_users.find_by(user_id: user_id)` and no-op when it is nil.

mediumperformanceapp/controllers/groups_controller.rb:22-26

Group members endpoint allows unbounded limit parameter — Any visitor can request an unbounded `limit` and force a full member load plus serialization of the whole group. Clamp `params[:limit]` to a maximum of 200 before applying `limit`/`offset`.

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

add_members re-adds existing members and raises RecordNotUnique — Re-adding an existing member violates the unique index on `(group_id, user_id)`, raising `ActiveRecord::RecordNotUnique` after earlier users in the batch were already inserted. Call `group.add(user)` only unless `group.users.include?(user)`.

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

totalPages computes an extra page when user_count is a multiple of limit — With exactly `limit` members, `totalPages` reports an extra page, so Next stays enabled and lands on an empty list. Use Math.ceil with a 0 guard so the counter matches the data.

mediumbugapp/assets/javascripts/admin/templates/group_member.hbs:1

Automatic group members incorrectly show remove link — `{{#unless automatic}}` cannot resolve in the member item view context, so automatic groups show a remove link whose DELETE returns 422. Reference the group explicitly via `view.parentView.model.automatic`. **Also found in:** - `app/assets/javascripts/admin/views/group-member.js.es6:1-4`

Gold bugs found (7)

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

Gold bugs missed (3)

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