Gilles Bourgeat
diff --git a/Controller/Admin/ConfigurationController.php b/Controller/Admin/ConfigurationController.php
index 87eba5d..eacd20e 100644
--- a/Controller/Admin/ConfigurationController.php
+++ b/Controller/Admin/ConfigurationController.php
@@ -65,7 +65,13 @@ public function saveConfig()
/* General config values */
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_CONTRACT_NUMBER, $vform->get(ColissimoLabel::CONFIG_KEY_CONTRACT_NUMBER)->getData());
- ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_PASSWORD, $vform->get(ColissimoLabel::CONFIG_KEY_PASSWORD)->getData());
+ ColissimoLabel::setConfigValue(
+ ColissimoLabel::CONFIG_KEY_PASSWORD,
+ ColissimoLabel::passwordToSave(
+ $vform->get(ColissimoLabel::CONFIG_KEY_PASSWORD)->getData(),
+ ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_PASSWORD)
+ )
+ );
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_DEFAULT_SIGNED, (int) $vform->get(ColissimoLabel::CONFIG_KEY_DEFAULT_SIGNED)->getData());
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_GENERATE_BORDEREAU, (int) $vform->get(ColissimoLabel::CONFIG_KEY_GENERATE_BORDEREAU)->getData());
ColissimoLabel::setConfigValue(ColissimoLabel::CONFIG_KEY_DEFAULT_LABEL_FORMAT, $vform->get(ColissimoLabel::CONFIG_KEY_DEFAULT_LABEL_FORMAT)->getData());
diff --git a/Form/ConfigureColissimoLabel.php b/Form/ConfigureColissimoLabel.php
index d046652..ce97994 100644
--- a/Form/ConfigureColissimoLabel.php
+++ b/Form/ConfigureColissimoLabel.php
@@ -7,6 +7,7 @@
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
+use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
@@ -17,6 +18,7 @@ class ConfigureColissimoLabel extends BaseForm
protected function buildForm(): void
{
$translator = Translator::getInstance();
+ $hasPassword = '' !== (string) ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_PASSWORD);
$this->formBuilder
->add(
ColissimoLabel::CONFIG_KEY_CONTRACT_NUMBER,
@@ -30,12 +32,14 @@ protected function buildForm(): void
)
->add(
ColissimoLabel::CONFIG_KEY_PASSWORD,
- TextType::class,
+ PasswordType::class,
[
- 'constraints' => [new NotBlank()],
- 'data' => ColissimoLabel::getConfigValue(ColissimoLabel::CONFIG_KEY_PASSWORD),
+ // The saved password is never sent back to the browser: an empty field keeps it.
+ 'required' => !$hasPassword,
+ 'constraints' => $hasPassword ? [] : [new NotBlank()],
'label' => $translator->trans('Password', [], ColissimoLabel::DOMAIN_NAME),
'label_attr' => ['for' => ColissimoLabel::CONFIG_KEY_PASSWORD],
+ 'help' => $hasPassword ? $translator->trans('Leave empty to keep the saved password', [], ColissimoLabel::DOMAIN_NAME) : null,
]
)
->add(
diff --git a/I18n/en_US.php b/I18n/en_US.php
index ce1dc8d..98310a4 100644
--- a/I18n/en_US.php
+++ b/I18n/en_US.php
@@ -18,6 +18,7 @@
'Nom de société' => 'Company\'s name',
'Order status after export' => 'Order status after export',
'Password' => 'Password',
+ 'Leave empty to keep the saved password' => 'Leave empty to keep the saved password',
'Pays' => 'Country',
'Please enter a weight for every selected order' => 'Please enter a weight for every selected order',
'Product HS Code for Customs invoices' => 'Product HS Code for Customs invoices',
diff --git a/I18n/fr_FR.php b/I18n/fr_FR.php
index d6166eb..9c20df5 100644
--- a/I18n/fr_FR.php
+++ b/I18n/fr_FR.php
@@ -18,6 +18,7 @@
'Nom de société' => 'Nom de société',
'Order status after export' => 'Status de commande après l\'export',
'Password' => 'Mot de passe',
+ 'Leave empty to keep the saved password' => 'Laisser vide pour conserver le mot de passe enregistré',
'Pays' => 'Pays',
'Postal Partner Network' => 'Réseau Partenaire Postal',
'Default' => 'Par défaut',
diff --git a/Readme.md b/Readme.md
index 472949c..8422045 100644
--- a/Readme.md
+++ b/Readme.md
@@ -79,6 +79,10 @@ If your module declare one or more loop, describe them here like this :
Same as an order loop, but only order that weren't sent or cancelled and that are paid for will be searched for.
+## Changes in 3.1.1
+
+- The contract password is no longer shown in the configuration form. Leave the field empty to keep the saved password.
+
## Changes in 3.1.0
- Deleting a label is a POST with a token (`_token`, `number`), no longer a GET link.
diff --git a/templates/backOffice/default-twig/colissimo-label/module-configuration.html.twig b/templates/backOffice/default-twig/colissimo-label/module-configuration.html.twig
index a68ab69..e5abd7b 100644
--- a/templates/backOffice/default-twig/colissimo-label/module-configuration.html.twig
+++ b/templates/backOffice/default-twig/colissimo-label/module-configuration.html.twig
@@ -41,7 +41,9 @@
{{ form_label(form['password']) }}
- {{ form_widget(form['password'], {attr: {class: 'form-control'}}) }}
+ {# new-password: keeps the browser from filling in the administrator's own password. #}
+ {{ form_widget(form['password'], {attr: {class: 'form-control', autocomplete: 'new-password'}|merge(form['password'].vars.help ? {'aria-describedby': form['password'].vars.id ~ '_help'} : {})}) }}
+ {{ form_help(form['password'], {help_attr: {class: 'form-text'}}) }}
{{ form_errors(form['password']) }}
diff --git a/tests/ContractPasswordTest.php b/tests/ContractPasswordTest.php
new file mode 100644
index 0000000..fcb1297
--- /dev/null
+++ b/tests/ContractPasswordTest.php
@@ -0,0 +1,25 @@
+ ['', 'saved', 'saved'];
+ yield 'missing field keeps the saved password' => [null, 'saved', 'saved'];
+ yield 'new password replaces the saved one' => ['new', 'saved', 'new'];
+ yield 'first password is saved' => ['new', null, 'new'];
+ yield 'nothing saved and nothing typed' => ['', null, null];
+ }
+
+ #[DataProvider('submissions')]
+ public function testTheConfigurationNeverErasesTheSavedPassword(?string $submitted, ?string $saved, ?string $expected): void
+ {
+ self::assertSame($expected, ColissimoLabel::passwordToSave($submitted, $saved));
+ }
+}