feat(integration): add requires_tenant_configuration field and update related logic and tests

This commit is contained in:
2026-07-22 09:23:58 -03:00
parent 03d8361e5f
commit 7e1ffbf417
9 changed files with 70 additions and 3 deletions

View File

@@ -94,7 +94,7 @@ abstract class BaseIntegrationService
->where('integration_code', $this->integrationCode)
->first();
if (!$this->tenantIntegration) {
if (!$this->tenantIntegration && $this->integration->requires_tenant_configuration) {
throw new Exception("Tenant '{$this->tenantCode}' does not have integration '{$this->integrationCode}' configured.");
}
}

View File

@@ -29,6 +29,8 @@ class MailService extends BaseIntegrationService
private ?Tenant $tenant = null;
private bool $usesTenantMailer = false;
public function __construct(?MailFactory $mailFactory = null)
{
$this->mailFactory = $mailFactory ?? app(MailFactory::class);
@@ -41,7 +43,14 @@ class MailService extends BaseIntegrationService
$this->tenant = Tenant::query()
->where('codigo', $tenantCode)
->firstOrFail();
$this->mailer = $this->resolveMailer();
if ($this->tenantIntegration) {
$this->mailer = $this->resolveMailer();
$this->usesTenantMailer = true;
} else {
$this->mailer = $this->mailFactory->mailer();
$this->usesTenantMailer = false;
}
return $this;
}
@@ -82,7 +91,9 @@ class MailService extends BaseIntegrationService
public function mailerName(): string
{
return 'tenant-smtp';
return $this->usesTenantMailer
? 'tenant-smtp'
: (string) config('mail.default');
}
public function onSetup(): void