From e2eaa6f319a41b91765b7211d61ca75c4c8dac49 Mon Sep 17 00:00:00 2001 From: Thomas Da Silva Date: Wed, 28 Oct 2026 16:37:14 +0100 Subject: [PATCH 1/2] fix(hors-ticket): stop showing the Colissimo contract password in the configuration form --- ColissimoLabel.php | 8 ++++++ Config/module.xml | 2 +- Controller/Admin/ConfigurationController.php | 8 +++++- Form/ConfigureColissimoLabel.php | 10 +++++--- I18n/en_US.php | 1 + I18n/fr_FR.php | 1 + Readme.md | 4 +++ .../module-configuration.html.twig | 4 ++- tests/ContractPasswordTest.php | 25 +++++++++++++++++++ 9 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 tests/ContractPasswordTest.php diff --git a/ColissimoLabel.php b/ColissimoLabel.php index 161942b..28556a7 100644 --- a/ColissimoLabel.php +++ b/ColissimoLabel.php @@ -413,6 +413,14 @@ public static function canCountryBeNotSigned(string $countryIsoCode): bool || in_array($countryIsoCode, Service::EUROPE_ISOCODES, true); } + /** + * The configuration form never shows the saved contract password: an empty field keeps it. + */ + public static function passwordToSave(?string $submittedPassword, ?string $savedPassword): ?string + { + return null === $submittedPassword || '' === $submittedPassword ? $savedPassword : $submittedPassword; + } + /** * Remove the accentuated and special characters from a string an replace them with * latin ASCII characters. Does the same to cyrillic. diff --git a/Config/module.xml b/Config/module.xml index a0147af..56dce6f 100644 --- a/Config/module.xml +++ b/Config/module.xml @@ -13,7 +13,7 @@ en_US fr_FR - 3.1.0 + 3.1.1 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..9e382f7 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'}}) }} + {{ form_help(form['password']) }} {{ 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)); + } +} From 579d629df83d98999fa6a00e71c8298a743dff20 Mon Sep 17 00:00:00 2001 From: Thomas Da Silva Date: Wed, 28 Oct 2026 16:42:09 +0100 Subject: [PATCH 2/2] fix(hors-ticket): style the password help and link it to the field --- .../colissimo-label/module-configuration.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 9e382f7..e5abd7b 100644 --- a/templates/backOffice/default-twig/colissimo-label/module-configuration.html.twig +++ b/templates/backOffice/default-twig/colissimo-label/module-configuration.html.twig @@ -42,8 +42,8 @@
{{ form_label(form['password']) }} {# new-password: keeps the browser from filling in the administrator's own password. #} - {{ form_widget(form['password'], {attr: {class: 'form-control', autocomplete: 'new-password'}}) }} - {{ form_help(form['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']) }}