From 80d10bed7a72830e0dd653a6f2d86060253b9027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Tue, 14 Oct 2025 09:30:36 +0000 Subject: [PATCH] Fix FLEXIAPI-402 Handle empty emails cases when importing accounts, handle... --- .../Controllers/Admin/AccountImportController.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/flexiapi/app/Http/Controllers/Admin/AccountImportController.php b/flexiapi/app/Http/Controllers/Admin/AccountImportController.php index 7c4574e..a523efe 100644 --- a/flexiapi/app/Http/Controllers/Admin/AccountImportController.php +++ b/flexiapi/app/Http/Controllers/Admin/AccountImportController.php @@ -153,7 +153,7 @@ class AccountImportController extends Controller // Emails if ($emails = $lines->pluck('email')->filter(function ($value) { - return !filter_var($value, FILTER_VALIDATE_EMAIL); + return $value != '' && !filter_var($value, FILTER_VALIDATE_EMAIL); })) { if ($emails->isNotEmpty()) { $this->errors['Some emails are not correct'] = $emails->join(', ', ' and '); @@ -167,7 +167,7 @@ class AccountImportController extends Controller $this->errors['Those emails numbers already exists'] = $existingEmails->join(', ', ' and '); } - if ($emails = $lines->pluck('email')->duplicates()) { + if ($emails = $lines->pluck('email')->filter(fn (string $value) => $value != '')->duplicates()) { if ($emails->isNotEmpty()) { $this->errors['Those emails are declared several times'] = $emails->join(', ', ' and '); } @@ -175,6 +175,8 @@ class AccountImportController extends Controller // External account + $checkExternalUsernameDomains = collect(); + foreach ($lines as $line) { if ($line->external_username != null && ($line->external_password == null || $line->external_domain == null)) { $this->errors['Line ' . $line->line . ': The mandatory external account columns must be filled'] = ''; @@ -191,6 +193,12 @@ class AccountImportController extends Controller $this->errors['Line ' . $line->line . ': External protocol must be UDP, TCP or TLS'] = ''; } } + + $checkExternalUsernameDomains->push($line->external_username . ',' . $line->external_domain); + } + + foreach ($checkExternalUsernameDomains->duplicates() as $duplicate) { + $this->errors['The following external account is used several times: ' . $duplicate] = ''; } $filePath = $this->errors->isEmpty()