GLM-5.3 · 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
4 of 10
Comments published
8
Comments matching a bug
4
Comments not matching
4
Cost of this PR
$2.993

Published comments (8)

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

remove_member passes an integer to association delete, raising AssociationTypeMismatch — Rails' collection `delete` type-checks arguments, so the bare integer in `group.users.delete(user_id)` raises `ActiveRecord::AssociationTypeMismatch` and removes no one. Load the `User` record first, delete the `group_users` join record directly, or call the model's `remove`.

highbugconfig/routes.rb:49-50

Group member routes deliver params[:id] but controller requires params[:group_id] — As member routes under `resources :groups`, the id arrives as `params[:id]`, so `params.require(:group_id)` in `add_members` and `remove_member` raises `ActionController::ParameterMissing` and every request fails (the specs pass `group_id:` directly, masking it). Read `params[:id]` or rename the route param. **Also found in:** - `app/controllers/admin/groups_controller.rb:65-76` - `app/controllers/admin/groups_controller.rb:84-90`

highbugapp/controllers/groups_controller.rb:22-26

Members endpoint caps list at 50; public page has no pager so rest unreachable — The unconditional 50 default leaves the public page — `group/members.hbs` iterates `members` with no pagination controls — showing only the first 50 of a larger group, the rest unreachable. Add pagination there or fetch without the cap. **Also found in:** - `app/assets/javascripts/discourse/routes/group-members.js.es6:8-12`

mediumbugapp/assets/javascripts/discourse/models/group.js:23-29

findMembers clamps offset with stale user_count, leaving an empty page after removal — Removing the last member of the last page makes `findMembers` clamp the offset with the stale previous-load `user_count`, landing the admin on an empty page with no way forward. Recompute the offset from the fresh response meta, or step back a page when `members` is empty.

mediumsecurityapp/controllers/groups_controller.rb:22-26

Unbounded limit/offset params cause 500 errors on public members endpoint — Unbounded `params[:limit]` and `params[:offset]` now reach the query for any visible group, so a negative `offset` raises `ActiveRecord::StatementInvalid` and a 500 from this public endpoint. Clamp both to a minimum of 0 and cap `limit` at a sane maximum.

mediumbugapp/assets/javascripts/admin/templates/group.hbs:12-14

{{#if id}} hides members of the "everyone" group whose id is 0 — The persisted `everyone` group has `id` 0 (`Group::AUTO_GROUPS[:everyone]`), so `{{#if id}}` treats it as unsaved and hides its member list and count. Detect a new group explicitly — e.g. a computed `isNew` via `Em.isNone(id)` — instead of relying on truthiness.

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

totalPages counts phantom page when user_count is exact multiple of limit — Use `Math.ceil(user_count / limit)` in `totalPages`.

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

add_members raises RecordNotUnique when adding an existing member — Because `group_users` has a unique index on `(group_id, user_id)`, `group.add(user)` on an existing member raises `ActiveRecord::RecordNotUnique` and a 500 — easy to hit since the selector isn't cleared after an add (see the `addMembers` TODO). Guard with a `GroupUser` existence check or rescue and skip duplicates.

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

Gold bugs missed (6)

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