Skip to content

Keep agent assigned on team change if they belong to the new team#297

Open
mageaustralia wants to merge 1 commit intoabhinavxd:mainfrom
mageaustralia:feat/smart-team-reassign
Open

Keep agent assigned on team change if they belong to the new team#297
mageaustralia wants to merge 1 commit intoabhinavxd:mainfrom
mageaustralia:feat/smart-team-reassign

Conversation

@mageaustralia
Copy link
Copy Markdown

What this changes

Reassigning a conversation to a different team currently always clears the assigned user. That's annoying when an agent legitimately sits on both teams (common with shared inboxes / multi-team agents) — they have to be re-picked manually after every team move.

This PR adds a UserBelongsToTeam check before unassigning. If the agent belongs to the new team they stay, otherwise the existing unassign behaviour kicks in. The membership helper already exists on the team store, so this is a small surgical change in UpdateConversationTeamAssignee.

Drive-by fix on the way

The teamStore interface declared UserBelongsToTeam(userID, teamID) but the implementation is UserBelongsToTeam(teamID, userID) and the SQL binds team_id = $1 AND user_id = $2. Impl + SQL agree; the interface label was reversed. With the two out of sync, an honest caller passing args in the order the interface advertises would silently get wrong results.

I caught this by writing the call against the (misleading) interface, then having the change reviewed before opening — landed on fixing the interface to match the impl rather than papering over the call site. Updated the interface declaration so the next person isn't trapped.

Why no test

There are currently no _test.go files under internal/conversation/ or internal/team/, so adding one would require introducing test scaffolding (mock teamStore, etc.) for what's effectively a 3-line behaviour change. Happy to add a focused test if you'd prefer — just say the word.

Test plan

  • Conversation assigned to Agent A on Team X → reassign to Team Y where Agent A is also a member → Agent A stays assigned, no assigned_user_change activity emitted
  • Same setup but Agent A is NOT on Team Y → Agent A unassigned, activity emitted (existing behaviour)
  • Conversation with no user assignee → reassign team → no-op on the user side, just the team change
  • Same team selected (no actual change) → no-op (existing fast-path)

Reassigning a conversation to a different team currently always clears
the user assignee. That's frustrating when an agent legitimately sits on
both teams (common with shared inboxes / multi-team agents) — they have
to be re-picked manually after every team move.

Adds a UserBelongsToTeam check before unassigning. The helper already
exists on the team store, so this is a small surgical change in
UpdateConversationTeamAssignee.

Also fixes the teamStore interface declaration whose param order
(`userID, teamID`) didn't match the implementation
(`teamID, userID`) — the SQL binds `team_id = $1 AND user_id = $2`,
so the impl was correct and the interface was just mislabeled. With the
two out of sync, an honest call against the interface produced
silently-wrong results.
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