Fix FLEXIAPI-332 Check if the first line was untouched and that the number of...

This commit is contained in:
Timothée Jaussoin 2025-06-16 14:33:41 +00:00
parent 724e4c4e5b
commit 8f4da0dc7b
4 changed files with 24 additions and 5 deletions

View file

@ -55,9 +55,23 @@ class AccountImportController extends Controller
'domain' => 'required|exists:accounts'
]);
$lines = $this->csvToCollection($request->file('csv'));
$domain = $request->get('domain');
/**
* General formating checking
*/
$csv = fopen($request->file('csv'), 'r');
$line = fgets($csv);
fclose($csv);
$lines = collect();
$this->errors['Wrong file format'] = "The number of columns doesn't matches the reference file. The first MUST be the same as the reference file";
if ($line == "Username,Password,Role,Status,Phone,Email,External Username,External Domain,External Password,External Realm, External Registrar,External Outbound Proxy,External Protocol\n") {
$lines = $this->csvToCollection($request->file('csv'));
unset($this->errors['Wrong file format']);
}
/**
* Error checking
*/
@ -314,6 +328,12 @@ class AccountImportController extends Controller
$i = 1;
while (!feof($csv)) {
if ($line = fgetcsv($csv, 1000, ',')) {
if (count($line) != 13) {
$this->errors['Parsing error at line ' . $i] = 'The number of columns is incorrect';
$i++;
continue;
}
$lines->push((object)[
'line' => $i,
'username' => !empty($line[0]) ? $line[0] : null,
@ -329,7 +349,6 @@ class AccountImportController extends Controller
'external_registrar' => !empty($line[10]) ? $line[10] : null,
'external_outbound_proxy' => !empty($line[11]) ? $line[11] : null,
'external_protocol' => $line[12],
]);
$i++;

View file

@ -189,7 +189,7 @@
"The code is not valid": "Le code n'est pas valide",
"We will send you a verification code to recover your account.": "Nous vous enverrons un code de vérification pour récupérer votre compte.",
"The contact doesn't exists": "Le contact n'existe pas",
"The file must be in CSV following this template": "Le fichier doit être au format CSV et respecter le modèle suivant",
"The file MUST be in CSV following this template": "Le fichier doit être au format CSV et respecter le modèle suivant",
"The first line contains the labels": "La premières ligne contient les étiquettes",
"The link can only be visited once": "Le lien ne peut être utilisé qu'une fois",
"Third-party SIP account": "Compte SIP tiers",

View file

@ -1,4 +1,4 @@
Username,Password,Role,Status,Phone,Email,External Username,External Domain,External Password,External Realm, External Registrar,External Outbound Proxy,External Encrypted,External Protocol
Username,Password,Role,Status,Phone,Email,External Username,External Domain,External Password,External Realm, External Registrar,External Outbound Proxy,External Protocol
john,number9,user,active,+12341234,john@lennon.com,extjohn,ext.lennon.com,123ext,,,,UDP
paul,a_day_in_the_life,admin,active,,paul@apple.com,,,,,,,
ringo,allUneedIsL3ve,user,inactive,+123456,ringo@star.co.uk,extringo,ext.star.co.uk,123456,another.realm,,,UDP
1 Username,Password,Role,Status,Phone,Email,External Username,External Domain,External Password,External Realm, External Registrar,External Outbound Proxy,External Encrypted,External Protocol Username Password Role Status Phone Email External Username External Domain External Password External Realm External Registrar External Outbound Proxy External Protocol
2 john,number9,user,active,+12341234,john@lennon.com,extjohn,ext.lennon.com,123ext,,,,UDP john number9 user active +12341234 john@lennon.com extjohn ext.lennon.com 123ext UDP
3 paul,a_day_in_the_life,admin,active,,paul@apple.com,,,,,,, paul a_day_in_the_life admin active paul@apple.com
4 ringo,allUneedIsL3ve,user,inactive,+123456,ringo@star.co.uk,extringo,ext.star.co.uk,123456,another.realm,,,UDP ringo allUneedIsL3ve user inactive +123456 ringo@star.co.uk extringo ext.star.co.uk 123456 another.realm UDP

View file

@ -18,7 +18,7 @@
<li>{{ __('Import') }}</li>
</ol>
<p>{{ __('The file must be in CSV following this template') }}: <a href="{{ route('account.home') }}/accounts_example.csv">example_template.csv</a></p>
<p>{{ __('The file MUST be in CSV following this template') }}: <a href="{{ route('account.home') }}/accounts_example.csv">example_template.csv</a></p>
<h4>{{ __('User') }}</h4>
<p>{{ __('The first line contains the labels') }}</p>