mirror of
https://github.com/abhinavxd/libredesk.git
synced 2025-10-23 16:14:12 +00:00
Refactor: assigned user removal when changing assigned team
This commit is contained in:
@@ -541,6 +541,10 @@ func (c *Manager) UpdateConversationTeamAssignee(uuid string, teamID int, actor
|
|||||||
|
|
||||||
// Team changed?
|
// Team changed?
|
||||||
if previousAssignedTeamID != teamID {
|
if previousAssignedTeamID != teamID {
|
||||||
|
// Remove assigned user if team has changed.
|
||||||
|
c.RemoveConversationAssignee(uuid, models.AssigneeTypeUser, actor)
|
||||||
|
|
||||||
|
// Apply SLA policy if this new team has a SLA policy.
|
||||||
team, err := c.teamStore.Get(teamID)
|
team, err := c.teamStore.Get(teamID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -582,8 +586,6 @@ func (c *Manager) UpdateAssignee(uuid string, assigneeID int, assigneeType strin
|
|||||||
c.lo.Error("error updating conversation assignee", "error", err)
|
c.lo.Error("error updating conversation assignee", "error", err)
|
||||||
return fmt.Errorf("updating assignee: %w", err)
|
return fmt.Errorf("updating assignee: %w", err)
|
||||||
}
|
}
|
||||||
// Clear assigned user ID.
|
|
||||||
c.BroadcastConversationUpdate(uuid, "assigned_user_id", nil)
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid assignee type: %s", assigneeType)
|
return fmt.Errorf("invalid assignee type: %s", assigneeType)
|
||||||
}
|
}
|
||||||
@@ -962,7 +964,7 @@ func (m *Manager) ApplyAction(action amodels.RuleAction, conv models.Conversatio
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveConversationAssignee removes the assignee from the conversation.
|
// RemoveConversationAssignee removes assigned user from a conversation.
|
||||||
func (m *Manager) RemoveConversationAssignee(uuid, typ string, actor umodels.User) error {
|
func (m *Manager) RemoveConversationAssignee(uuid, typ string, actor umodels.User) error {
|
||||||
if _, err := m.q.RemoveConversationAssignee.Exec(uuid, typ); err != nil {
|
if _, err := m.q.RemoveConversationAssignee.Exec(uuid, typ); err != nil {
|
||||||
m.lo.Error("error removing conversation assignee", "error", err)
|
m.lo.Error("error removing conversation assignee", "error", err)
|
||||||
@@ -977,6 +979,14 @@ func (m *Manager) RemoveConversationAssignee(uuid, typ string, actor umodels.Use
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Broadcast ws update.
|
||||||
|
switch typ {
|
||||||
|
case models.AssigneeTypeUser:
|
||||||
|
m.BroadcastConversationUpdate(uuid, "assigned_user_id", nil)
|
||||||
|
case models.AssigneeTypeTeam:
|
||||||
|
m.BroadcastConversationUpdate(uuid, "assigned_team_id", nil)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -215,8 +215,6 @@ WHERE uuid = $1;
|
|||||||
-- name: update-conversation-assigned-team
|
-- name: update-conversation-assigned-team
|
||||||
UPDATE conversations
|
UPDATE conversations
|
||||||
SET assigned_team_id = $2,
|
SET assigned_team_id = $2,
|
||||||
assigned_user_id = NULL,
|
|
||||||
assignee_last_seen_at = NULL,
|
|
||||||
updated_at = NOW()
|
updated_at = NOW()
|
||||||
WHERE uuid = $1;
|
WHERE uuid = $1;
|
||||||
|
|
||||||
@@ -355,6 +353,7 @@ WHERE uuid = $1;
|
|||||||
UPDATE conversations
|
UPDATE conversations
|
||||||
SET
|
SET
|
||||||
assigned_user_id = CASE WHEN $2 = 'user' THEN NULL ELSE assigned_user_id END,
|
assigned_user_id = CASE WHEN $2 = 'user' THEN NULL ELSE assigned_user_id END,
|
||||||
|
assignee_last_seen_at = CASE WHEN $2 = 'user' THEN NULL ELSE assignee_last_seen_at END,
|
||||||
assigned_team_id = CASE WHEN $2 = 'team' THEN NULL ELSE assigned_team_id END,
|
assigned_team_id = CASE WHEN $2 = 'team' THEN NULL ELSE assigned_team_id END,
|
||||||
updated_at = NOW()
|
updated_at = NOW()
|
||||||
WHERE uuid = $1;
|
WHERE uuid = $1;
|
||||||
|
Reference in New Issue
Block a user