From 050a4feab586c8b0624c017692d267202aeedfaf Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 25 Jan 2023 11:55:13 +0100 Subject: [PATCH 1/5] Fix: [export][aggregator] group by user job, not by job --- .../AccompanyingCourseAggregators/JobAggregator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php index 5019d3a8b..1278bc21c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php @@ -40,11 +40,11 @@ final class JobAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('acpjob', $qb->getAllAliases(), true)) { - $qb->leftJoin('acp.job', 'acpjob'); + if (!in_array('acpuser', $qb->getAllAliases(), true)) { + $qb->leftJoin('acp.user', 'acpuser'); } - $qb->addSelect('IDENTITY(acp.job) AS job_aggregator'); + $qb->addSelect('IDENTITY(acpuser.userJob) AS job_aggregator'); $qb->addGroupBy('job_aggregator'); } From 8e3a83de850d6798925512b70c85f69385d741be Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 25 Jan 2023 12:03:39 +0100 Subject: [PATCH 2/5] DX: [export] Rename JobAggregator to more logical UserJobAggregator --- .../{JobAggregator.php => UserJobAggregator.php} | 2 +- .../{JobAggregatorTest.php => UserJobAggregatorTest.php} | 6 +++--- .../config/services/exports_accompanying_course.yaml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/{JobAggregator.php => UserJobAggregator.php} (97%) rename src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/{JobAggregatorTest.php => UserJobAggregatorTest.php} (90%) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php similarity index 97% rename from src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php rename to src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php index 1278bc21c..a8acdcf12 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php @@ -19,7 +19,7 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; use function in_array; -final class JobAggregator implements AggregatorInterface +final class UserJobAggregator implements AggregatorInterface { private UserJobRepository $jobRepository; diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/JobAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php similarity index 90% rename from src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/JobAggregatorTest.php rename to src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php index 18ef84c15..1ed748e32 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/JobAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregatorTest.php @@ -13,16 +13,16 @@ namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregato use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\JobAggregator; +use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserJobAggregator; use Doctrine\ORM\EntityManagerInterface; /** * @internal * @coversNothing */ -final class JobAggregatorTest extends AbstractAggregatorTest +final class UserJobAggregatorTest extends AbstractAggregatorTest { - private JobAggregator $aggregator; + private UserJobAggregator $aggregator; protected function setUp(): void { diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index 6d0e160fd..bb2cfa556 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -136,7 +136,7 @@ services: - { name: chill.export_aggregator, alias: accompanyingcourse_scope_aggregator } chill.person.export.aggregator_referrer_job: - class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\JobAggregator + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserJobAggregator tags: - { name: chill.export_aggregator, alias: accompanyingcourse_referrer_job_aggregator } From 2f091a639b57121d1c3bef4607f32a953d8a285b Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 26 Jan 2023 11:52:45 +0100 Subject: [PATCH 3/5] remove unused private function --- .../Filter/AccompanyingCourseFilters/UserJobFilter.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php index b97f97dda..2b69c528b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php @@ -126,12 +126,4 @@ class UserJobFilter implements FilterInterface { return 'Filter by user job'; } - - private function getUserJob(): UserJob - { - /** @var User $user */ - $user = $this->security->getUser(); - - return $user->getUserJob(); - } } From 2d013e110a88bc3dbf72a2a0127564824f65ebcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 9 Feb 2023 18:08:20 +0100 Subject: [PATCH 4/5] Fixed: [budget] force budget kind and resource kind to have a unique `kind` field in database --- .../ChillBudgetBundle/Entity/ChargeKind.php | 9 +++++- .../ChillBudgetBundle/Entity/ResourceKind.php | 9 +++++- .../Form/Admin/ChargeKindType.php | 7 ++++- .../Form/Admin/ResourceKindType.php | 7 ++++- .../migrations/Version20230209161546.php | 30 +++++++++++++++++++ .../translations/messages.fr.yml | 7 +++++ .../translations/validators.fr.yml | 8 ++++- 7 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 src/Bundle/ChillBudgetBundle/migrations/Version20230209161546.php diff --git a/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php b/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php index d1393eafb..b6ebcf347 100644 --- a/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php +++ b/src/Bundle/ChillBudgetBundle/Entity/ChargeKind.php @@ -12,12 +12,17 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Validator\Constraints as Assert; /** * Type of charge. * - * @ORM\Table(name="chill_budget.charge_type") + * @ORM\Table(name="chill_budget.charge_type", + * uniqueConstraints={@ORM\UniqueConstraint(name="charge_kind_unique_type_idx", fields={"kind"})} + * ) * @ORM\Entity + * @UniqueEntity(fields={"kind"}) */ class ChargeKind { @@ -35,6 +40,8 @@ class ChargeKind /** * @ORM\Column(type="string", length=255, options={"default": ""}, nullable=false) + * @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric") + * @Assert\Length(min=3) */ private string $kind = ''; diff --git a/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php b/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php index 5d88af298..4b90be5e1 100644 --- a/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php +++ b/src/Bundle/ChillBudgetBundle/Entity/ResourceKind.php @@ -12,12 +12,17 @@ declare(strict_types=1); namespace Chill\BudgetBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; +use Symfony\Component\Validator\Constraints as Assert; /** * Type of resource. * - * @ORM\Table(name="chill_budget.resource_type") + * @ORM\Table(name="chill_budget.resource_type", uniqueConstraints={ + * @ORM\UniqueConstraint(name="resource_kind_unique_type_idx", fields={"kind"}) + * }) * @ORM\Entity + * @UniqueEntity(fields={"kind"}) */ class ResourceKind { @@ -35,6 +40,8 @@ class ResourceKind /** * @ORM\Column(type="string", length=255, nullable=false, options={"default": ""}) + * @Assert\Regex(pattern="/^[a-z0-9\-_]{1,}$/", message="budget.admin.form.kind.only_alphanumeric") + * @Assert\Length(min=3) */ private string $kind = ''; diff --git a/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php b/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php index 661199aec..59adf49af 100644 --- a/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php +++ b/src/Bundle/ChillBudgetBundle/Form/Admin/ChargeKindType.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\NumberType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -25,7 +26,11 @@ class ChargeKindType extends AbstractType { $builder ->add('name', TranslatableStringFormType::class, [ - 'label' => 'Nom', + 'label' => 'Title', + ]) + ->add('kind', TextType::class, [ + 'label' => 'budget.admin.form.Charge_kind_key', + 'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document' ]) ->add('ordering', NumberType::class) ->add('isActive', CheckboxType::class, [ diff --git a/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php b/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php index 7b2622c5d..0605b8731 100644 --- a/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php +++ b/src/Bundle/ChillBudgetBundle/Form/Admin/ResourceKindType.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Form\Type\TranslatableStringFormType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\NumberType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -25,7 +26,11 @@ class ResourceKindType extends AbstractType { $builder ->add('name', TranslatableStringFormType::class, [ - 'label' => 'Nom', + 'label' => 'Title', + ]) + ->add('kind', TextType::class, [ + 'label' => 'budget.admin.form.Resource_kind_key', + 'help' => 'budget.admin.form.This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document' ]) ->add('ordering', NumberType::class) ->add('isActive', CheckboxType::class, [ diff --git a/src/Bundle/ChillBudgetBundle/migrations/Version20230209161546.php b/src/Bundle/ChillBudgetBundle/migrations/Version20230209161546.php new file mode 100644 index 000000000..618b0c982 --- /dev/null +++ b/src/Bundle/ChillBudgetBundle/migrations/Version20230209161546.php @@ -0,0 +1,30 @@ +addSql("UPDATE chill_budget.resource_type SET kind=md5(random()::text) WHERE kind = ''"); + $this->addSql("UPDATE chill_budget.charge_type SET kind=md5(random()::text) WHERE kind = ''"); + $this->addSql('CREATE UNIQUE INDEX resource_kind_unique_type_idx ON chill_budget.resource_type (kind);'); + $this->addSql('CREATE UNIQUE INDEX charge_kind_unique_type_idx ON chill_budget.charge_type (kind);'); + } + + public function down(Schema $schema): void + { + $this->addSql('DROP INDEX resource_kind_unique_type_idx'); + $this->addSql('DROP INDEX charge_kind_unique_type_idx'); + } +} diff --git a/src/Bundle/ChillBudgetBundle/translations/messages.fr.yml b/src/Bundle/ChillBudgetBundle/translations/messages.fr.yml index 8337dff87..b20477150 100644 --- a/src/Bundle/ChillBudgetBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillBudgetBundle/translations/messages.fr.yml @@ -77,6 +77,13 @@ The balance: Différence entre ressources et charges Valid since %startDate% until %endDate%: Valide depuis le %startDate% jusqu'au %endDate% Valid since %startDate%: Valide depuis le %startDate% +budget: + admin: + form: + Charge_kind_key: Clé d'identification + Resource_kind_key: Clé d'identification + This kind must contains only alphabeticals characters, and dashes. This string is in use during document generation. Changes may have side effect on document: Cette clé sert à identifier le type de charge ou de revenu lors de la génération de document. Seuls les caractères alpha-numériques sont autorisés. Modifier cette clé peut avoir un effet lors de la génération de nouveaux documents. + # ROLES Budget elements: Budget CHILL_BUDGET_ELEMENT_CREATE: Créer une ressource/charge diff --git a/src/Bundle/ChillBudgetBundle/translations/validators.fr.yml b/src/Bundle/ChillBudgetBundle/translations/validators.fr.yml index 7281b6380..01b240eac 100644 --- a/src/Bundle/ChillBudgetBundle/translations/validators.fr.yml +++ b/src/Bundle/ChillBudgetBundle/translations/validators.fr.yml @@ -1,2 +1,8 @@ The amount cannot be empty: Le montant ne peut pas être vide ou égal à zéro -The budget element's end date must be after the start date: La date de fin doit être après la date de début \ No newline at end of file +The budget element's end date must be after the start date: La date de fin doit être après la date de début + +budget: + admin: + form: + kind: + only_alphanumeric From 25cbb528ec20f4a343f101dfe661301de9df25a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 9 Feb 2023 18:18:30 +0100 Subject: [PATCH 5/5] Fixed: [budget] in admin list, show pagination and kind in resource_kind and charge_kind pages --- .../Resources/views/Admin/Charge/index.html.twig | 7 ++++++- .../Resources/views/Admin/Resource/index.html.twig | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig b/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig index 2486aaecf..4f56c92cb 100644 --- a/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig +++ b/src/Bundle/ChillBudgetBundle/Resources/views/Admin/Charge/index.html.twig @@ -19,7 +19,10 @@ {% for entity in entities %} {{ entity.ordering }} - {{ entity|chill_entity_render_box }} + + {{ entity|chill_entity_render_box }}
+ {{ 'budget.admin.form.Charge_kind_key'|trans }} : {{ entity.kind }} + {%- if entity.isActive -%} @@ -39,6 +42,8 @@ + {{ chill_pagination(paginator) }} +