RejectPendingCore is the HTTP-free core of HITL reject: optional expected-agent-email match (mirrors the legacy URL guard), then RejectPending + publish. Shared by the legacy handler and the v1 layer.
(ctx context.Context, userID, messageID, expectedAgentEmail, reason string)
| 208 | // expected-agent-email match (mirrors the legacy URL guard), then |
| 209 | // RejectPending + publish. Shared by the legacy handler and the v1 layer. |
| 210 | func (a *API) RejectPendingCore(ctx context.Context, userID, messageID, expectedAgentEmail, reason string) (*identity.Message, *OutboundError) { |
| 211 | if expectedAgentEmail != "" { |
| 212 | preview, err := a.store.GetOutboundMessageForUser(ctx, messageID, userID) |
| 213 | if err != nil { |
| 214 | return nil, &OutboundError{http.StatusNotFound, "not_found", "message not found"} |
| 215 | } |
| 216 | agent, err := a.store.GetAgentByID(ctx, preview.AgentID) |
| 217 | if err != nil || agent.Email != expectedAgentEmail { |
| 218 | return nil, &OutboundError{http.StatusNotFound, "not_found", "message not found"} |
| 219 | } |
| 220 | } |
| 221 | rejected, err := a.store.RejectPending(ctx, messageID, userID, reason) |
| 222 | if err != nil { |
| 223 | switch { |
| 224 | case errors.Is(err, identity.ErrMessageNotFound): |
| 225 | return nil, &OutboundError{http.StatusNotFound, "not_found", "message not found"} |
| 226 | case errors.Is(err, identity.ErrNotPendingApproval): |
| 227 | return nil, &OutboundError{http.StatusConflict, "message_not_pending", "message is not pending approval"} |
| 228 | default: |
| 229 | log.Printf("[api] reject: %v", err) |
| 230 | return nil, &OutboundError{http.StatusInternalServerError, "internal_error", "failed to reject message"} |
| 231 | } |
| 232 | } |
| 233 | log.Printf("[mail:%s] dir=outbound type=%s status=%s agent=%s rejected_by=user:%s reason=%q", |
| 234 | rejected.ID, rejected.Type, rejected.Status, rejected.AgentID, userID, reason) |
| 235 | a.publishRejected(ctx, a.buildRejectedEvent(userID, rejected, reason), rejected.ID) |
| 236 | return rejected, nil |
| 237 | } |
| 238 | |
| 239 | // ApproveInboundReviewCore releases a held INBOUND message to its agent's inbox |
| 240 | // (status pending_review → review_approved, now readable) and fires |
nothing calls this directly
no test coverage detected