refactor(integration): generalizar el requisito de configuracion
Renombra requires_client_configuration a requires_configuration conservando los valores existentes y su rollback. Actualiza el modelo, la validacion, los seeders y los consumidores del campo para permitir configuraciones de cliente o tipo de sitio.
This commit is contained in:
@@ -14,12 +14,12 @@ class Integration extends Model
|
||||
'name',
|
||||
'url',
|
||||
'integration_data_schema',
|
||||
'requires_client_configuration',
|
||||
'requires_configuration',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'integration_data_schema' => 'array',
|
||||
'requires_client_configuration' => 'boolean',
|
||||
'requires_configuration' => 'boolean',
|
||||
];
|
||||
|
||||
/** @return HasMany<IntegrationInstance, $this> */
|
||||
|
||||
@@ -18,7 +18,7 @@ class StoreIntegrationRequest extends FormRequest
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'url' => ['nullable', 'url', 'max:255'],
|
||||
'integration_data_schema' => ['nullable', 'array'],
|
||||
'requires_client_configuration' => ['sometimes', 'boolean'],
|
||||
'requires_configuration' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class UpdateIntegrationRequest extends FormRequest
|
||||
'name' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
'url' => ['nullable', 'url', 'max:255'],
|
||||
'integration_data_schema' => ['nullable', 'array'],
|
||||
'requires_client_configuration' => ['sometimes', 'boolean'],
|
||||
'requires_configuration' => ['sometimes', 'boolean'],
|
||||
// the code shouldn't ideally be updatable, but if it is:
|
||||
'integration_code' => ['sometimes', 'required', 'string', 'unique:integrations,integration_code,'.($integration->id ?? '')],
|
||||
];
|
||||
|
||||
@@ -108,7 +108,7 @@ abstract class BaseIntegrationService
|
||||
->where('integration_code', $this->integrationCode)
|
||||
->first();
|
||||
|
||||
if (! $this->clientIntegration && $this->integration->requires_client_configuration) {
|
||||
if (! $this->clientIntegration && $this->integration->requires_configuration) {
|
||||
throw new Exception("Client '{$this->clientContext->code}' does not have integration '{$this->integrationCode}' configured.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('integrations', function (Blueprint $table): void {
|
||||
$table->renameColumn('requires_client_configuration', 'requires_configuration');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('integrations', function (Blueprint $table): void {
|
||||
$table->renameColumn('requires_configuration', 'requires_client_configuration');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -17,7 +17,7 @@ class EmailIntegrationSeeder extends Seeder
|
||||
[
|
||||
'name' => 'Email',
|
||||
'url' => null,
|
||||
'requires_client_configuration' => false,
|
||||
'requires_configuration' => false,
|
||||
'integration_data_schema' => [
|
||||
'MAIL_MAILER' => 'required|string|in:smtp',
|
||||
'MAIL_SCHEME' => 'required|string|in:smtp',
|
||||
|
||||
@@ -17,7 +17,7 @@ class TelepagosIntegrationSeeder extends Seeder
|
||||
[
|
||||
'name' => 'Telepagos',
|
||||
'url' => 'https://api.telepagos.com.ar',
|
||||
'requires_client_configuration' => true,
|
||||
'requires_configuration' => true,
|
||||
'integration_data_schema' => [
|
||||
'username' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
@@ -30,7 +30,7 @@ class TelepagosIntegrationSeeder extends Seeder
|
||||
[
|
||||
'name' => 'Telepagos Homologación',
|
||||
'url' => 'https://api.homo.telepagos.com.ar',
|
||||
'requires_client_configuration' => true,
|
||||
'requires_configuration' => true,
|
||||
'integration_data_schema' => [
|
||||
'username' => 'required|string',
|
||||
'password' => 'required|string',
|
||||
|
||||
@@ -65,7 +65,7 @@ class MailServiceTest extends TestCase
|
||||
Integration::create([
|
||||
'integration_code' => 'email',
|
||||
'name' => 'Email',
|
||||
'requires_client_configuration' => false,
|
||||
'requires_configuration' => false,
|
||||
]);
|
||||
|
||||
$service = (new MailService)->forTenant($tenant->codigo);
|
||||
|
||||
@@ -35,7 +35,7 @@ class NotificationMailServiceTest extends TestCase
|
||||
'integration_code' => 'email',
|
||||
'name' => 'Email',
|
||||
'url' => null,
|
||||
'requires_client_configuration' => false,
|
||||
'requires_configuration' => false,
|
||||
'integration_data_schema' => [],
|
||||
]);
|
||||
$header = Attachment::query()->create([
|
||||
|
||||
@@ -53,6 +53,9 @@ class IntegrationInstanceSchemaTest extends TestCase
|
||||
$table->string('codigo')->unique();
|
||||
});
|
||||
(require __DIR__.'/../../database/migrations/2026_07_03_000001_create_integrations_table.php')->up();
|
||||
$schema->table('integrations', function (Blueprint $table): void {
|
||||
$table->boolean('requires_client_configuration')->default(true);
|
||||
});
|
||||
$schema->create('client_integrations', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('client_id')->constrained('clients')->cascadeOnDelete();
|
||||
|
||||
Reference in New Issue
Block a user