mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-25 03:42:02 +00:00
make updateAssignee private so user assignment can't skip hooks
This commit is contained in:
@@ -680,7 +680,7 @@ func (c *Manager) UpdateConversationWaitingSince(conversationUUID string, at *ti
|
||||
|
||||
// UpdateConversationUserAssignee sets the assignee of a conversation to a specifc user.
|
||||
func (c *Manager) UpdateConversationUserAssignee(uuid string, assigneeID int, actor umodels.User) error {
|
||||
if err := c.UpdateAssignee(uuid, assigneeID, models.AssigneeTypeUser); err != nil {
|
||||
if err := c.updateAssignee(uuid, assigneeID, models.AssigneeTypeUser); err != nil {
|
||||
return envelope.NewError(envelope.GeneralError, c.i18n.T("globals.messages.somethingWentWrong"), nil)
|
||||
}
|
||||
return c.afterUserAssigned(uuid, assigneeID, actor)
|
||||
@@ -760,7 +760,7 @@ func (c *Manager) UpdateConversationTeamAssignee(uuid string, teamID int, actor
|
||||
}
|
||||
previousAssignedTeamID := conversation.AssignedTeamID.Int
|
||||
|
||||
if err := c.UpdateAssignee(uuid, teamID, models.AssigneeTypeTeam); err != nil {
|
||||
if err := c.updateAssignee(uuid, teamID, models.AssigneeTypeTeam); err != nil {
|
||||
return envelope.NewError(envelope.GeneralError, c.i18n.T("globals.messages.somethingWentWrong"), nil)
|
||||
}
|
||||
|
||||
@@ -806,27 +806,6 @@ func (c *Manager) UpdateConversationTeamAssignee(uuid string, teamID int, actor
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateAssignee updates the assignee of a conversation.
|
||||
func (c *Manager) UpdateAssignee(uuid string, assigneeID int, assigneeType string) error {
|
||||
prev, prevErr := c.GetConversationListItem(uuid)
|
||||
switch assigneeType {
|
||||
case models.AssigneeTypeUser:
|
||||
if _, err := c.q.UpdateConversationAssignedUser.Exec(uuid, assigneeID); err != nil {
|
||||
c.lo.Error("error updating conversation assignee", "error", err)
|
||||
return fmt.Errorf("updating assignee: %w", err)
|
||||
}
|
||||
case models.AssigneeTypeTeam:
|
||||
if _, err := c.q.UpdateConversationAssignedTeam.Exec(uuid, assigneeID); err != nil {
|
||||
c.lo.Error("error updating conversation assignee", "error", err)
|
||||
return fmt.Errorf("updating assignee: %w", err)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("invalid assignee type: %s", assigneeType)
|
||||
}
|
||||
c.broadcastReassignment(uuid, prev, prevErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
// broadcastReassignment broadcasts a reassignment to agents, given the conversation's prior list item.
|
||||
func (c *Manager) broadcastReassignment(uuid string, prev models.ConversationListItem, prevErr error) {
|
||||
next, nextErr := c.GetConversationListItem(uuid)
|
||||
@@ -1970,6 +1949,27 @@ func (c *Manager) FilterAuthorizedListUUIDs(agentID int, uuids []string) ([]stri
|
||||
return authorized, nil
|
||||
}
|
||||
|
||||
// updateAssignee updates the assignee of a conversation.
|
||||
func (c *Manager) updateAssignee(uuid string, assigneeID int, assigneeType string) error {
|
||||
prev, prevErr := c.GetConversationListItem(uuid)
|
||||
switch assigneeType {
|
||||
case models.AssigneeTypeUser:
|
||||
if _, err := c.q.UpdateConversationAssignedUser.Exec(uuid, assigneeID); err != nil {
|
||||
c.lo.Error("error updating conversation assignee", "error", err)
|
||||
return fmt.Errorf("updating assignee: %w", err)
|
||||
}
|
||||
case models.AssigneeTypeTeam:
|
||||
if _, err := c.q.UpdateConversationAssignedTeam.Exec(uuid, assigneeID); err != nil {
|
||||
c.lo.Error("error updating conversation assignee", "error", err)
|
||||
return fmt.Errorf("updating assignee: %w", err)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("invalid assignee type: %s", assigneeType)
|
||||
}
|
||||
c.broadcastReassignment(uuid, prev, prevErr)
|
||||
return nil
|
||||
}
|
||||
|
||||
func nullTimeOrNil(t null.Time) any {
|
||||
if !t.Valid || t.Time.IsZero() {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user