Fix FLEXIAPI-402 Handle empty emails cases when importing accounts, handle...

This commit is contained in:
Timothée Jaussoin 2025-10-14 09:24:28 +00:00
parent 57e09cc4de
commit 9aeeb0fa73

View file

@ -153,7 +153,7 @@ class ImportController extends Controller
// Emails // Emails
if ($emails = $lines->pluck('email')->filter(function ($value) { 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()) { if ($emails->isNotEmpty()) {
$this->errors['Some emails are not correct'] = $emails->join(', ', ' and '); $this->errors['Some emails are not correct'] = $emails->join(', ', ' and ');
@ -167,7 +167,7 @@ class ImportController extends Controller
$this->errors['Those emails numbers already exists'] = $existingEmails->join(', ', ' and '); $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()) { if ($emails->isNotEmpty()) {
$this->errors['Those emails are declared several times'] = $emails->join(', ', ' and '); $this->errors['Those emails are declared several times'] = $emails->join(', ', ' and ');
} }
@ -175,6 +175,8 @@ class ImportController extends Controller
// External account // External account
$checkExternalUsernameDomains = collect();
foreach ($lines as $line) { foreach ($lines as $line) {
if ($line->external_username != null && ($line->external_password == null || $line->external_domain == null)) { 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'] = ''; $this->errors['Line ' . $line->line . ': The mandatory external account columns must be filled'] = '';
@ -191,6 +193,12 @@ class ImportController extends Controller
$this->errors['Line ' . $line->line . ': External protocol must be UDP, TCP or TLS'] = ''; $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() $filePath = $this->errors->isEmpty()