feat(captain): gate custom tools
This commit is contained in:
@@ -20,8 +20,9 @@ import (
|
||||
// CaptainCustomToolService implements business logic for CaptainCustomTool operations.
|
||||
// Reference: Chatwoot enterprise/app/controllers/api/v1/captain/custom_tools_controller.rb
|
||||
type CaptainCustomToolService struct {
|
||||
toolRepo *repository.CaptainCustomToolRepo
|
||||
httpClient HTTPDoer
|
||||
toolRepo *repository.CaptainCustomToolRepo
|
||||
accountRepo *repository.AccountRepo
|
||||
httpClient HTTPDoer
|
||||
}
|
||||
|
||||
type HTTPDoer interface {
|
||||
@@ -29,8 +30,12 @@ type HTTPDoer interface {
|
||||
}
|
||||
|
||||
// NewCaptainCustomToolService creates a new CaptainCustomToolService.
|
||||
func NewCaptainCustomToolService(toolRepo *repository.CaptainCustomToolRepo) *CaptainCustomToolService {
|
||||
return &CaptainCustomToolService{toolRepo: toolRepo, httpClient: &http.Client{Timeout: 30 * time.Second}}
|
||||
func NewCaptainCustomToolService(toolRepo *repository.CaptainCustomToolRepo, accountRepo ...*repository.AccountRepo) *CaptainCustomToolService {
|
||||
svc := &CaptainCustomToolService{toolRepo: toolRepo, httpClient: &http.Client{Timeout: 30 * time.Second}}
|
||||
if len(accountRepo) > 0 {
|
||||
svc.accountRepo = accountRepo[0]
|
||||
}
|
||||
return svc
|
||||
}
|
||||
|
||||
func (s *CaptainCustomToolService) SetHTTPClient(client HTTPDoer) {
|
||||
@@ -39,6 +44,17 @@ func (s *CaptainCustomToolService) SetHTTPClient(client HTTPDoer) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CaptainCustomToolService) CustomToolsEnabled(ctx context.Context, accountID uint) bool {
|
||||
if s.accountRepo == nil {
|
||||
return true
|
||||
}
|
||||
account, err := s.accountRepo.FindByID(ctx, accountID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return featureFlagStringEnabled(account.FeatureFlags, "custom_tools") || featureFlagStringEnabled(account.FeatureFlags, "captain_integration_v2")
|
||||
}
|
||||
|
||||
// --- Request DTOs ---
|
||||
|
||||
// CreateCustomToolRequest is the DTO for creating a custom tool.
|
||||
|
||||
Reference in New Issue
Block a user