feat(inboxes): enforce chatwoot inbox limits
This commit is contained in:
@@ -107,6 +107,13 @@ func (h *GoogleChannelHandler) OAuthCallback(c *gin.Context) {
|
||||
}
|
||||
|
||||
ctx := c.Request.Context()
|
||||
if err := h.inboxSvc.EnsureCanCreateInbox(ctx, uint(accountID)); err != nil {
|
||||
if renderInboxLimitExceeded(c, err) {
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to create google inbox"})
|
||||
return
|
||||
}
|
||||
|
||||
// Exchange the code for tokens
|
||||
tokenResult, err := h.goProvider.ExchangeToken(ctx, req.Code, req.RedirectURL)
|
||||
@@ -146,6 +153,12 @@ func (h *GoogleChannelHandler) OAuthCallback(c *gin.Context) {
|
||||
inbox, err := h.inboxSvc.Create(ctx, uint(accountID), inboxReq)
|
||||
if err != nil {
|
||||
applogger.L().Errorf("Failed to create Google inbox: %v", err)
|
||||
if delErr := h.goService.Delete(ctx, goChannel.ID); delErr != nil {
|
||||
applogger.L().Warnf("Failed to rollback Google channel after inbox creation failure: %v", delErr)
|
||||
}
|
||||
if renderInboxLimitExceeded(c, err) {
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "failed to create google inbox"})
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user