fix(users): send --role on users update instead of dropping it - #1
fix(users): send --role on users update instead of dropping it#1joalves wants to merge 1 commit into
users update instead of dropping it#1Conversation
`abs users update <id> --role <role>` accepted a --role option but
silently ignored it: updateUser() in src/core/users/update.ts built the
request body from params.name only and never added params.role. As a
result `abs users update 256 --role 34` failed with "At least one update
field is required", and even with a name the role change was never sent.
The API expects roles as an array of `{ role_id: number }` objects for
the user's global team. This is confirmed by the OpenAPI UpdateUserBody
schema (`data.roles: { role_id: number }[]`) and the backend handler
which does `data.roles.map(({ role_id }) => ...)`. A bare `roles: [34]`
array is rejected (500), which is why passing the field naively fails.
Fix:
- update.ts now adds `roles: [{ role_id }]` to the request body when
--role is provided, parsing the option to a positive integer role ID
and counting it toward the "at least one field" guard so `--role X`
alone works.
- Introduce an `UpdateUserData` type derived from the OpenAPI
UpdateUserBody schema and use it for the core `data` object and the
api-client `updateUser(id, data)` signature (previously `Partial<User>`,
which has no `roles` field), so role updates are type-checked.
Tested: extended src/core/users/users.test.ts (role-only, name+role,
invalid-role) and src/commands/users/users.test.ts (--role wiring); both
suites pass. `tsc` compiles clean. Verified end-to-end against the
compiled output that `--role 34` sends `{ roles: [{ role_id: 34 }] }`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughThe user update API now uses the OpenAPI-derived Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/core/users/users.test.ts (1)
176-180: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd boundary cases for invalid role values.
The test only covers the non-numeric path (
"admin"). Add cases for0, negative values, and fractional values to protect the positive-integer validation contract.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/core/users/users.test.ts` around lines 176 - 180, Add boundary-case assertions to the invalid-role tests around updateUser: cover role values 0, negative numbers, and fractional numbers, and verify each rejects with “Invalid role” without calling mockClient.updateUser. Preserve the existing non-numeric case and positive-integer validation contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/core/users/users.test.ts`:
- Around line 176-180: Add boundary-case assertions to the invalid-role tests
around updateUser: cover role values 0, negative numbers, and fractional
numbers, and verify each rejects with “Invalid role” without calling
mockClient.updateUser. Preserve the existing non-numeric case and
positive-integer validation contract.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9a461c13-62ef-47e8-a321-5a81c8477808
📒 Files selected for processing (6)
src/api-client/api-client.tssrc/api-client/types.tssrc/commands/users/users.test.tssrc/core/users/update.tssrc/core/users/users.test.tssrc/lib/api/openapi-types.ts
The bug
abs users update <id> --role <role>accepts a--roleoption but silently ignores it. Running e.g.abs users update 256 --role 34fails with:even though a role was provided — and when a name is also given, the role change is never sent to the API.
Root cause
In
src/core/users/update.ts,updateUser()builds the request body fromparams.nameonly (split intofirst_name/last_name), then checksif (Object.keys(data).length === 0) throw new Error('At least one update field is required').params.roleis typed onUpdateUserParamsbut never added todata, so role updates are dropped before the request is ever made.The fix
updateUser()now addsroles: [{ role_id }]to the request body when--roleis provided, parses the option to a positive-integer role ID, and counts it toward the "at least one field" guard so--role Xalone works.UpdateUserDatatype derived from the OpenAPIUpdateUserBodyschema and used it for the coredataobject and the api-clientupdateUser(id, data)signature (previouslyPartial<User>, which has norolesfield), so role updates are type-checked end to end.Why
roles: [{ role_id }]and notroles: [34]The backend expects roles as an array of
{ role_id: number }objects for the user's global team. Confirmed from two sources, not by trial and error:UpdateUserBody.data.rolesis typed{ role_id: number }[].data.roles.map(({ role_id }) => ...)— it destructuresrole_idfrom each element, which is why a bareroles: [34]array fails (the backend readsundefinedforrole_id).Testing
src/core/users/users.test.ts: role-only update, name + role together, and invalid-role rejection.src/commands/users/users.test.ts:--roleflows through the command wiring toupdateUser(id, { roles: [{ role_id: 34 }] }).tsccompiles clean.abs users update 256 --role 34producesupdateUser(256, { roles: [{ role_id: 34 }] })— the original "At least one update field is required" error is gone.(Note: 3 pre-existing failures in
src/lib/api/oauth-refresh.test.tsare unrelated to this change — they fail identically on the base branch.)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
--roleoption.Bug Fixes