From 2c774e814e2f212c927848f80f8faa8d53b3ee6e Mon Sep 17 00:00:00 2001 From: juminet Date: Sun, 16 Jan 2022 22:51:29 +0000 Subject: [PATCH] localisation type not available to edit by users --- CHANGELOG.md | 1 + .../Controller/LocationTypeApiController.php | 1 + .../ChillMainBundle/Entity/LocationType.php | 18 ++++++++++ .../ChillMainBundle/Form/LocationTypeType.php | 11 ++++++ .../views/LocationType/index.html.twig | 8 +++++ .../migrations/Version20220112150413.php | 36 +++++++++++++++++++ .../translations/messages.fr.yml | 1 + 7 files changed, 76 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20220112150413.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 91ba040ae..e5666a064 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [main] Add editableByUser field to locationType entity, adapt the admin template and add this condition in the location-type endpoint (see https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/297) * [main] Add mainLocation field to User entity and add it in user form type * rewrite page which allow to select activity * [main] Add mainLocation field to User entity and add it in user form type diff --git a/src/Bundle/ChillMainBundle/Controller/LocationTypeApiController.php b/src/Bundle/ChillMainBundle/Controller/LocationTypeApiController.php index 1c7fbdb89..ce1b5e825 100644 --- a/src/Bundle/ChillMainBundle/Controller/LocationTypeApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/LocationTypeApiController.php @@ -24,6 +24,7 @@ class LocationTypeApiController extends ApiController $query->andWhere( $query->expr()->andX( $query->expr()->eq('e.availableForUsers', "'TRUE'"), + $query->expr()->eq('e.editableByUsers', "'TRUE'"), $query->expr()->eq('e.active', "'TRUE'"), ) ); diff --git a/src/Bundle/ChillMainBundle/Entity/LocationType.php b/src/Bundle/ChillMainBundle/Entity/LocationType.php index 9081304c8..2fd4dbfea 100644 --- a/src/Bundle/ChillMainBundle/Entity/LocationType.php +++ b/src/Bundle/ChillMainBundle/Entity/LocationType.php @@ -67,6 +67,12 @@ class LocationType */ private ?string $defaultFor = null; + /** + * @ORM\Column(type="boolean") + * @Serializer\Groups({"read"}) + */ + private bool $editableByUsers = true; + /** * @ORM\Id * @ORM\GeneratedValue @@ -107,6 +113,11 @@ class LocationType return $this->defaultFor; } + public function getEditableByUsers(): ?bool + { + return $this->editableByUsers; + } + public function getId(): ?int { return $this->id; @@ -152,6 +163,13 @@ class LocationType return $this; } + public function setEditableByUsers(bool $editableByUsers): self + { + $this->editableByUsers = $editableByUsers; + + return $this; + } + public function setTitle(array $title): self { $this->title = $title; diff --git a/src/Bundle/ChillMainBundle/Form/LocationTypeType.php b/src/Bundle/ChillMainBundle/Form/LocationTypeType.php index aa096b3e6..2ecaa56c8 100644 --- a/src/Bundle/ChillMainBundle/Form/LocationTypeType.php +++ b/src/Bundle/ChillMainBundle/Form/LocationTypeType.php @@ -39,6 +39,17 @@ final class LocationTypeType extends AbstractType 'expanded' => true, ] ) + ->add( + 'editableByUsers', + ChoiceType::class, + [ + 'choices' => [ + 'Yes' => true, + 'No' => false, + ], + 'expanded' => true, + ] + ) ->add( 'addressRequired', ChoiceType::class, diff --git a/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig index 5402d5e89..22cb6de44 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/LocationType/index.html.twig @@ -8,6 +8,7 @@ {{ 'Title'|trans }} {{ 'Available for users'|trans }} + {{ 'Editable by users'|trans }} {{ 'Address required'|trans }} {{ 'Contact data'|trans }} {{ 'Active'|trans }} @@ -25,6 +26,13 @@ {%- endif -%} + + {%- if entity.editableByUsers -%} + + {%- else -%} + + {%- endif -%} + {{ entity.addressRequired|trans }} {{ entity.contactData|trans }} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220112150413.php b/src/Bundle/ChillMainBundle/migrations/Version20220112150413.php new file mode 100644 index 000000000..c38649711 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220112150413.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE chill_main_location_type DROP editableByUsers'); + } + + public function getDescription(): string + { + return 'Add editableByUsers field to ChillMain/LocationType'; + } + + public function up(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_location_type ADD editableByUsers BOOLEAN DEFAULT TRUE'); + } +} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index a3a375891..a7503415e 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -202,6 +202,7 @@ Location: Localisation Location type list: Liste des types de localisation Create a new location type: Créer un nouveau type de localisation Available for users: Disponible aux utilisateurs +Editable by users: Éditable par les utilisateurs Address required: Adresse requise? Contact data: Données de contact? optional: optionnel