update
This commit is contained in:
@@ -120,6 +120,7 @@ func (h *AgentHandler) Create(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.JSON(http.StatusOK, serializeAgentDetail(agent, accountID))
|
||||
}
|
||||
|
||||
@@ -188,6 +189,30 @@ func (h *AgentHandler) Delete(c *gin.Context) {
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
// ResetPassword generates a new temporary password for an email agent.
|
||||
// POST /api/v1/accounts/:account_id/agents/:agent_id/reset_password
|
||||
func (h *AgentHandler) ResetPassword(c *gin.Context) {
|
||||
accountID := getAccountID(c)
|
||||
if accountID == 0 {
|
||||
response.AbortWithStatusError(c, http.StatusUnauthorized, response.ErrUnauthorized, "account not identified")
|
||||
return
|
||||
}
|
||||
id, err := strconv.ParseUint(c.Param("agent_id"), 10, 32)
|
||||
if err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrBadRequest, "invalid agent id")
|
||||
return
|
||||
}
|
||||
|
||||
temporaryPassword, svcErr := h.svc.ResetPassword(c.Request.Context(), uint(id), accountID)
|
||||
if svcErr != nil {
|
||||
applogger.L().Errorf("Reset password for agent %d in account %d: %v", id, accountID, svcErr)
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.JSON(http.StatusOK, gin.H{"temporary_password": temporaryPassword})
|
||||
}
|
||||
|
||||
// BulkCreate adds multiple agents to the account by email.
|
||||
// POST /api/v1/accounts/:account_id/agents/bulk_create
|
||||
// Reference: Chatwoot agents_controller.rb#bulk_create
|
||||
@@ -222,14 +247,15 @@ func (h *AgentHandler) BulkCreate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
_, svcErr := h.svc.BulkCreate(c.Request.Context(), accountID, userID, req)
|
||||
agents, svcErr := h.svc.BulkCreate(c.Request.Context(), accountID, userID, req)
|
||||
if svcErr != nil {
|
||||
applogger.L().Errorf("BulkCreate agents for account %d: %v", accountID, svcErr)
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.JSON(http.StatusOK, serializeAgentDetails(agents, accountID))
|
||||
}
|
||||
|
||||
func serializeAgentDetails(agents []repository.AgentDetail, accountID uint) []map[string]any {
|
||||
@@ -244,7 +270,11 @@ func serializeAgentDetail(agent *repository.AgentDetail, accountID uint) map[str
|
||||
if agent == nil {
|
||||
return map[string]any{}
|
||||
}
|
||||
return serializeAgentUser(&agent.User, accountID, agent.Role, agent.Availability, agent.AutoOffline, agent.CustomRoleID)
|
||||
payload := serializeAgentUser(&agent.User, accountID, agent.Role, agent.Availability, agent.AutoOffline, agent.CustomRoleID)
|
||||
if agent.TemporaryPassword != "" {
|
||||
payload["temporary_password"] = agent.TemporaryPassword
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
func serializeAgentUser(user *model.User, accountID uint, role string, availability string, autoOffline bool, customRoleID uint) map[string]any {
|
||||
|
||||
Reference in New Issue
Block a user