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)
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`.
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`
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`
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.
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.
{{#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.
totalPages counts phantom page when user_count is exact multiple of limit — Use `Math.ceil(user_count / limit)` in `totalPages`.
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.