MiniMax M3 · 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
1 of 10
Comments published
4
Comments matching a bug
1
Comments not matching
3
Cost of this PR
$0.214

Published comments (4)

mediumbugapp/controllers/admin/groups_controller.rb:40

`update` renames group to "" when an empty name param is posted — A blank `params[:name]` is truthy in Ruby, so `group.name = params[:name] if params[:name] && !group.automatic` overwrites the group's name with `""` and fails the 422 on `group.save`. Switch the guard to `params[:name].present?` to match the `alias_level` style on the line above.

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

add_members drops usernames with surrounding whitespace — `add_members` splits on commas but `User.find_by_username` matches `username_lower`, so a token like `" bob"` returns `nil` and that user is silently dropped while the invite appears to succeed. Trim each token with `username.strip` before the lookup.

mediumbugspec/controllers/admin/groups_controller_spec.rb:112-117

remove_member spec uses wrong HTTP verb for DELETE-only route — The first `.remove_member` example issues `xhr :put, :remove_member` even though the route registers `delete "members"`, masking that the endpoint is DELETE-only and tempting readers to copy the wrong verb. Change the line to `xhr :delete, :remove_member, …` to match the `is able to remove a member` example.

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

totalPages reports an extra empty page when user_count is an exact multiple of limit — `totalPages` in `admin-group.js.es6` uses `Math.floor(user_count / limit) + 1`, which yields a phantom page when `user_count` is an exact multiple of `limit` and pushes `offset` past the data on `next`. Use `Math.ceil(user_count / limit)` so the pager only lists pages with content.

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