Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ColissimoLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>3.1.0</version>
<version>3.1.1</version>
<authors>
<author>
<name>Gilles Bourgeat</name>
Expand Down
8 changes: 7 additions & 1 deletion Controller/Admin/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
10 changes: 7 additions & 3 deletions Form/ConfigureColissimoLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions I18n/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions I18n/fr_FR.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
</div>
<div class="mb-3">
{{ 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']) }}
</div>
<div class="form-check mb-3">
Expand Down
25 changes: 25 additions & 0 deletions tests/ContractPasswordTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace ColissimoLabel\Tests;

use ColissimoLabel\ColissimoLabel;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class ContractPasswordTest extends TestCase
{
public static function submissions(): iterable
{
yield 'empty field keeps the saved password' => ['', '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));
}
}
Loading