Skip to content

Fix user role update workspace#373

Open
Lazygarde wants to merge 2 commits into
colanode:mainfrom
Lazygarde:fix-user-role-update-workspace
Open

Fix user role update workspace#373
Lazygarde wants to merge 2 commits into
colanode:mainfrom
Lazygarde:fix-user-role-update-workspace

Conversation

@Lazygarde
Copy link
Copy Markdown

Fix: User Role Update in Workspace

Problems

Two bugs were found in the workspace user role management flow:

1. Wrong user ID sent in role update API call

UserRoleUpdateMutationHandler was using input.userId (the current logged-in user) as the target in the API URL instead of input.targetUserId (the user whose role is being changed). This caused the role update request to target the wrong user.

Additionally, WorkspaceUserRoleDropdown was passing accountId and workspaceId directly from the component into the mutation input, while the handler already resolves these from workspace context — leading to confusion between the acting user and the target user.

2. UI not reflecting role changes after update

UserService.upsertUser() and UserService.syncServerUser() always emitted a user.created event even when the user record already existed (i.e., an upsert/update scenario). Components listening for user.updated events never received the signal, so the UI did not re-render after a role change.


Changes

packages/client/src/mutations/users/user-role-update.ts

  • Added targetUserId field to UserRoleUpdateMutationInput to explicitly distinguish the target user from the acting user (userId).

packages/client/src/handlers/mutations/users/user-role-update.ts

  • Fixed API URL to use input.targetUserId instead of input.userId.

packages/ui/src/components/workspaces/workspace-user-role-dropdown.tsx

  • Renamed prop userIdtargetUserId for clarity.
  • Fixed mutation input: pass userId: workspace.userId (acting user) and targetUserId (target user) instead of incorrectly passing accountId/workspaceId.

packages/ui/src/components/workspaces/workspace-users-container.tsx

  • Updated prop name to targetUserId to match the dropdown component change.

packages/client/src/services/workspaces/user-service.ts

  • Before upserting, check whether the user already exists in the local SQLite database.
  • Emit user.updated event if the record existed, or user.created if it is new.
  • Applied to both upsertUser() and syncServerUser().

Testing

  1. Open workspace settings → Members.
  2. Change the role of any member.
  3. Verify the dropdown immediately reflects the new role without a page refresh.
  4. Verify the correct user's role is updated (not the acting admin's).

@Lazygarde Lazygarde force-pushed the fix-user-role-update-workspace branch from a56c91c to 221ec5f Compare May 19, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant