GLM-5.3 · 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
2 of 10
Comments published
5
Comments matching a bug
2
Comments not matching
3
Cost of this PR
$1.213

Published comments (5)

highbugapp/controllers/groups_controller.rb:22-26

Public group members page silently hides members beyond first 50 — Add next/previous controls like the admin page, or restore the unbounded listing for this consumer.

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

`automatic` resolves against member context, not group; remove icon shown for automatic groups — Since `automatic` is undefined on the member context, the remove icon appears even for automatic groups, where the server always rejects removal with 422. Resolve the flag against the group, e.g. `controller.automatic`, so the icon only renders when removal can succeed.

mediumbugapp/assets/javascripts/discourse/models/group.js:22-24

Stale offset after member removal can reload an empty members page — After removing the only member on the last page, `findMembers` reloads with the stale `offset`, so the server returns an empty list and the UI shows a blank page. Reset the offset when the current page empties or clamp it against the freshly returned `meta.total`.

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

Group member add/remove failures are silently swallowed — When the server rejects the request, the unhandled promises in `removeMember` and `addMembers` swallow the error, so the admin gets no feedback and the list silently stays unchanged. Add a rejection handler that displays the error, as the replaced save flow did.

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

add_members raises RecordNotUnique when adding an existing member — The unique index on `group_users` means `group.add(user)` raises `ActiveRecord::RecordNotUnique` — a 500 — whenever a username is already a member, and nothing on the client prevents resubmitting one. Guard each add with a membership check or reuse the diffing semantics of the old `Group#usernames=` setter.

Gold bugs found (2)

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.

Gold bugs missed (8)

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