fix: move apply SLA on team change from handler to conversations pkg as automations will also change assigned team and that should also set the appropriate SLA defined for the team.

This commit is contained in:
Abhinav Raut
2025-03-06 20:47:19 +05:30
parent 9892f9dae7
commit 6fb35b90b3
2 changed files with 26 additions and 14 deletions

View File

@@ -380,7 +380,7 @@ func handleUpdateTeamAssignee(r *fastglue.Request) error {
return sendErrorEnvelope(r, err)
}
conversation, err := enforceConversationAccess(app, uuid, user)
_, err = enforceConversationAccess(app, uuid, user)
if err != nil {
return sendErrorEnvelope(r, err)
}
@@ -391,18 +391,6 @@ func handleUpdateTeamAssignee(r *fastglue.Request) error {
// Evaluate automation rules on team assignment.
app.automation.EvaluateConversationUpdateRules(uuid, models.EventConversationTeamAssigned)
// Apply SLA policy if team has changed and the new team has an SLA policy.
if conversation.AssignedTeamID.Int != assigneeID && assigneeID != 0 {
team, err := app.team.Get(assigneeID)
if err != nil {
return sendErrorEnvelope(r, err)
}
if team.SLAPolicyID.Int != 0 {
if err := app.conversation.ApplySLA(*conversation, team.SLAPolicyID.Int, user); err != nil {
return sendErrorEnvelope(r, err)
}
}
}
return r.SendEnvelope("Team assigned successfully")
}

View File

@@ -452,8 +452,32 @@ func (c *Manager) UpdateConversationTeamAssignee(uuid string, teamID int, actor
if err := c.UpdateAssignee(uuid, teamID, models.AssigneeTypeTeam); err != nil {
return envelope.NewError(envelope.GeneralError, "Error updating assignee", nil)
}
// Assignment successful, any errors now are non-critical and can be ignored.
if err := c.RecordAssigneeTeamChange(uuid, teamID, actor); err != nil {
return envelope.NewError(envelope.GeneralError, "Error recording assignee change", nil)
return nil
}
conversation, err := c.GetConversation(0, uuid)
if err != nil {
return nil
}
// Apply SLA policy if team has changed and the new team has an SLA policy.
if conversation.AssignedTeamID.Int != teamID && teamID > 0 {
team, err := c.teamStore.Get(teamID)
if err != nil {
return nil
}
if team.SLAPolicyID.Int > 0 {
systemUser, err := c.userStore.GetSystemUser()
if err != nil {
return nil
}
if err := c.ApplySLA(conversation, team.SLAPolicyID.Int, systemUser); err != nil {
return nil
}
}
}
return nil
}