diff --git a/config/packages/backoffice_menu.yaml b/config/packages/backoffice_menu.yaml index 57ddf37cc..5f4454bdf 100644 --- a/config/packages/backoffice_menu.yaml +++ b/config/packages/backoffice_menu.yaml @@ -369,6 +369,8 @@ parameters: url: '/admin/antennes' extra_routes: - admin_antennes_list + - admin_antennes_add + - admin_antennes_edit divers: nom: 'Divers' niveau: 'ROLE_SUPER_ADMIN' diff --git a/config/routing/admin_antennes.yml b/config/routing/admin_antennes.yml index c178cf4bf..15ff40092 100644 --- a/config/routing/admin_antennes.yml +++ b/config/routing/admin_antennes.yml @@ -1,3 +1,13 @@ admin_antennes_list: path: / defaults: {_controller: AppBundle\Controller\Admin\Antennes\AntenneListAction} + +admin_antennes_add: + path: /add + defaults: {_controller: AppBundle\Controller\Admin\Antennes\AntenneAddAction} + +admin_antennes_edit: + path: /edit/{code} + defaults: {_controller: AppBundle\Controller\Admin\Antennes\AntenneEditAction} + requirements: + code: '[a-z0-9-]+' diff --git a/db/seeds/Users.php b/db/seeds/Users.php index e4d57b391..912df9cd5 100644 --- a/db/seeds/Users.php +++ b/db/seeds/Users.php @@ -16,6 +16,7 @@ class Users extends AbstractSeed public const ID_USER_PERSONNE_PHYSIQUE_FIXED_COTISATIONS = 6; public const ID_USER_PERSONNE_LIE_PERSONNE_MORALE_FIXED_COTISATIONS = 7; public const ID_USER_GESTIONNAIRE_MEMBRES = 8; + public const ID_USER_LECTEUR_ANTENNES = 9; public const ID_PERSONNE_MORALE_MY_CORP = 1; public const ID_PERSONNE_MORALE_HELIOS_AEROSPACE = 2; @@ -158,6 +159,18 @@ public function run(): void 'etat' => User::STATUS_ACTIVE, 'adresse' => '', ], + // lecteur du module Antennes, sans droit d'écriture + [ + 'id' => self::ID_USER_LECTEUR_ANTENNES, + 'login' => 'lecteurantennes', + 'mot_de_passe' => md5('lecteurantennes'), + 'nom' => 'Lecteur', + 'prenom' => 'Antennes', + 'email' => 'lecteur.antennes@afup.test', + 'roles' => json_encode(['ROLE_ANTENNES_READER']), + 'etat' => User::STATUS_ACTIVE, + 'adresse' => '', + ], ]; $table = $this->table('afup_personnes_physiques'); diff --git a/sources/AppBundle/Antennes/Entity/Antenne.php b/sources/AppBundle/Antennes/Entity/Antenne.php index 58bc8ff34..9e35f8631 100644 --- a/sources/AppBundle/Antennes/Entity/Antenne.php +++ b/sources/AppBundle/Antennes/Entity/Antenne.php @@ -15,7 +15,7 @@ /** * `meetup` est une propriété virtuelle calculée à partir des colonnes `meetup_nom_url` / `meetup_id_externe`. - * La classe ne peut pas être `readonly` à cause de ce hook : `readonly` est donc porté par chaque propriété. + * Seul `code` (clé primaire, référencée ailleurs) est immuable ; le reste est modifiable via `modifier()`. */ #[ORM\Entity(repositoryClass: AntenneRepository::class)] #[ORM\Table(name: 'afup_antenne')] @@ -28,10 +28,10 @@ final class Antenne } #[ORM\Column(length: 255, nullable: true)] - private readonly ?string $meetupNomUrl; + private ?string $meetupNomUrl; #[ORM\Column(length: 50, nullable: true)] - private readonly ?string $meetupIdExterne; + private ?string $meetupIdExterne; /** * @param string[]|null $departements @@ -42,24 +42,51 @@ public function __construct( #[ORM\Column(length: 50)] public readonly string $code, #[ORM\Column(length: 255)] - public readonly string $libelle, + public private(set) string $libelle, ?Meetup $meetup, #[ORM\Column(length: 255)] - public readonly string $urlLogo, + public private(set) string $urlLogo, #[ORM\Column(type: AntenneReseauxSociauxType::NAME)] - public readonly ReseauxSociaux $reseauxSociaux, + public private(set) ReseauxSociaux $reseauxSociaux, #[ORM\Column(type: AntenneCarteType::NAME, nullable: true)] - public readonly ?Carte $carte, + public private(set) ?Carte $carte, #[ORM\Column(type: Types::JSON, nullable: true)] - public readonly ?array $departements = null, + public private(set) ?array $departements = null, #[ORM\Column(type: Types::JSON, nullable: true)] - public readonly ?array $pays = null, + public private(set) ?array $pays = null, #[ORM\Column(length: 255, nullable: true)] - public readonly ?string $region = null, + public private(set) ?string $region = null, #[ORM\Column(options: ['default' => false])] - public readonly bool $masqueePageAntennes = false, + public private(set) bool $masqueePageAntennes = false, ) { $this->meetupNomUrl = $meetup?->nomUrl; $this->meetupIdExterne = $meetup?->id; } + + /** + * @param string[]|null $departements + * @param string[]|null $pays + */ + public function modifier( + string $libelle, + ?Meetup $meetup, + string $urlLogo, + ReseauxSociaux $reseauxSociaux, + ?Carte $carte, + ?array $departements, + ?array $pays, + ?string $region, + bool $masqueePageAntennes, + ): void { + $this->libelle = $libelle; + $this->meetupNomUrl = $meetup?->nomUrl; + $this->meetupIdExterne = $meetup?->id; + $this->urlLogo = $urlLogo; + $this->reseauxSociaux = $reseauxSociaux; + $this->carte = $carte; + $this->departements = $departements; + $this->pays = $pays; + $this->region = $region; + $this->masqueePageAntennes = $masqueePageAntennes; + } } diff --git a/sources/AppBundle/Antennes/Form/AntenneFormData.php b/sources/AppBundle/Antennes/Form/AntenneFormData.php new file mode 100644 index 000000000..382674034 --- /dev/null +++ b/sources/AppBundle/Antennes/Form/AntenneFormData.php @@ -0,0 +1,161 @@ +reseauxSociaux = new ReseauxSociauxFormData(); + $this->carte = new CarteFormData(); + } + + public static function fromEntity(Antenne $antenne): self + { + $data = new self(); + $data->code = $antenne->code; + $data->libelle = $antenne->libelle; + $data->urlLogo = $antenne->urlLogo; + $data->meetupNomUrl = $antenne->meetup?->nomUrl; + $data->meetupIdExterne = $antenne->meetup?->id; + $data->reseauxSociaux = ReseauxSociauxFormData::fromReseauxSociaux($antenne->reseauxSociaux); + $data->carte = CarteFormData::fromCarte($antenne->carte); + $data->departements = $antenne->departements; + $data->pays = $antenne->pays; + $data->region = $antenne->region; + $data->actif = !$antenne->masqueePageAntennes; + + return $data; + } + + #[Assert\Callback] + public function validateMeetup(ExecutionContextInterface $context): void + { + $nomUrlRenseigne = self::nullIfEmpty($this->meetupNomUrl) !== null; + $idRenseigne = self::nullIfEmpty($this->meetupIdExterne) !== null; + + if ($nomUrlRenseigne && !$idRenseigne) { + $context->buildViolation("L'identifiant Meetup est obligatoire quand le nom d'URL est renseigné.") + ->atPath('meetupIdExterne') + ->addViolation(); + } + + if ($idRenseigne && !$nomUrlRenseigne) { + $context->buildViolation("Le nom d'URL Meetup est obligatoire quand l'identifiant est renseigné.") + ->atPath('meetupNomUrl') + ->addViolation(); + } + } + + public function toEntity(): Antenne + { + return new Antenne( + code: (string) $this->code, + libelle: (string) $this->libelle, + meetup: $this->meetup(), + urlLogo: (string) $this->urlLogo, + reseauxSociaux: $this->reseauxSociaux->toReseauxSociaux(), + carte: $this->carte->toCarte(), + departements: $this->departements, + pays: $this->pays, + region: self::nullIfEmpty($this->region), + masqueePageAntennes: !$this->actif, + ); + } + + public function appliquerA(Antenne $antenne): void + { + $antenne->modifier( + libelle: (string) $this->libelle, + meetup: $this->meetup(), + urlLogo: (string) $this->urlLogo, + reseauxSociaux: $this->reseauxSociaux->toReseauxSociaux(), + carte: $this->carte->toCarte(), + departements: $this->departements, + pays: $this->pays, + region: self::nullIfEmpty($this->region), + masqueePageAntennes: !$this->actif, + ); + } + + private function meetup(): ?Meetup + { + $nomUrl = self::nullIfEmpty($this->meetupNomUrl); + $id = self::nullIfEmpty($this->meetupIdExterne); + + return $nomUrl !== null && $id !== null ? new Meetup($nomUrl, $id) : null; + } + + private static function nullIfEmpty(?string $value): ?string + { + $value = $value !== null ? trim($value) : null; + + return $value === '' ? null : $value; + } +} diff --git a/sources/AppBundle/Antennes/Form/AntenneType.php b/sources/AppBundle/Antennes/Form/AntenneType.php new file mode 100644 index 000000000..f4cdf6bfb --- /dev/null +++ b/sources/AppBundle/Antennes/Form/AntenneType.php @@ -0,0 +1,137 @@ + + */ +final class AntenneType extends AbstractType +{ + public function __construct(private readonly AntenneRepository $antenneRepository) {} + + public function buildForm(FormBuilderInterface $builder, array $options): void + { + if ($options['creation']) { + $builder->add('code', TextType::class, [ + 'label' => 'Code', + 'help' => 'Identifiant technique (ex. lyon) : lettres minuscules, chiffres et tirets. Il ne pourra plus être modifié.', + ]); + } + + $builder + ->add('libelle', TextType::class, [ + 'label' => 'Nom', + ]) + ->add('urlLogo', UrlType::class, [ + 'label' => 'Logo', + 'default_protocol' => 'https', + 'help' => 'URL du logo (ex. hébergé sur https://identity.afup.org/)', + ]) + ->add('actif', CheckboxType::class, [ + 'label' => 'Active', + 'help' => "Une antenne inactive n'est pas affichée sur la page des antennes.", + 'required' => false, + ]) + ->add('meetupNomUrl', TextType::class, [ + 'label' => "Nom d'URL Meetup", + 'help' => 'Ex. afup-lyon-php pour https://www.meetup.com/afup-lyon-php/', + 'required' => false, + ]) + ->add('meetupIdExterne', TextType::class, [ + 'label' => 'Identifiant Meetup', + 'help' => 'Identifiant numérique du groupe Meetup', + 'required' => false, + ]) + ->add('reseauxSociaux', ReseauxSociauxType::class, [ + 'label' => false, + ]) + ->add('region', TextType::class, [ + 'label' => 'Région', + 'required' => false, + ]) + ->add('departements', TextType::class, [ + 'label' => 'Départements', + 'help' => 'Numéros séparés par des virgules (ex. 69, 01)', + 'required' => false, + ]) + ->add('pays', TextType::class, [ + 'label' => 'Pays', + 'help' => 'Codes séparés par des virgules, pour les antennes hors de France (ex. luxembourg)', + 'required' => false, + ]) + ->add('carte', CarteType::class, [ + 'label' => false, + ]); + + $listeTransformer = new CallbackTransformer(self::listeVersTexte(...), self::texteVersListe(...)); + + $builder->get('departements')->addModelTransformer($listeTransformer); + $builder->get('pays')->addModelTransformer($listeTransformer); + + if ($options['creation']) { + $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event): void { + /** @var AntenneFormData $data */ + $data = $event->getData(); + + if ($data->code === null || $data->code === '') { + return; + } + + if ($this->antenneRepository->find($data->code) instanceof Antenne) { + $event->getForm()->get('code')->addError( + new FormError("Une antenne existe déjà avec le code « {$data->code} »."), + ); + } + }); + } + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => AntenneFormData::class, + 'creation' => false, + 'validation_groups' => fn(Options $options): array => $options['creation'] + ? ['Default', AntenneFormData::GROUPE_CREATION] + : ['Default'], + ]); + $resolver->setAllowedTypes('creation', 'bool'); + } + + /** + * @param string[]|null $valeurs + */ + private static function listeVersTexte(?array $valeurs): string + { + return implode(', ', $valeurs ?? []); + } + + /** + * @return string[]|null + */ + private static function texteVersListe(?string $texte): ?array + { + $valeurs = array_values(array_filter( + array_map(trim(...), explode(',', (string) $texte)), + fn(string $valeur): bool => $valeur !== '', + )); + + return $valeurs === [] ? null : $valeurs; + } +} diff --git a/sources/AppBundle/Antennes/Form/CarteFormData.php b/sources/AppBundle/Antennes/Form/CarteFormData.php new file mode 100644 index 000000000..4e551760c --- /dev/null +++ b/sources/AppBundle/Antennes/Form/CarteFormData.php @@ -0,0 +1,91 @@ +premiereVille = new VilleFormData(); + } + + public static function fromCarte(?Carte $carte): self + { + $data = new self(); + + if (!$carte instanceof Carte) { + return $data; + } + + $data->afficherSurCarte = true; + $data->utiliserSecondeCouleur = $carte->utiliserSecondeCouleur; + $data->ancrageLegende = $carte->ancrageLegende; + $data->premiereVille = VilleFormData::fromVille($carte->premiereVille); + $data->secondeVille = $carte->secondeVille !== null ? VilleFormData::fromVille($carte->secondeVille) : null; + + return $data; + } + + #[Assert\Callback] + public function validate(ExecutionContextInterface $context): void + { + if (!$this->afficherSurCarte) { + return; + } + + if (!$this->ancrageLegende instanceof AncrageLegende) { + $context->buildViolation("L'ancrage de la légende est obligatoire pour afficher l'antenne sur la carte.") + ->atPath('ancrageLegende') + ->addViolation(); + } + + if (!$this->premiereVille instanceof VilleFormData || !$this->premiereVille->estComplete()) { + $context->buildViolation("Tous les champs de la première ville sont obligatoires pour afficher l'antenne sur la carte.") + ->atPath('premiereVille') + ->addViolation(); + } + + if ($this->secondeVille instanceof VilleFormData && !$this->secondeVille->estVide() && !$this->secondeVille->estComplete()) { + $context->buildViolation('La seconde ville doit être soit entièrement remplie, soit vide.') + ->atPath('secondeVille') + ->addViolation(); + } + } + + public function toCarte(): ?Carte + { + if (!$this->afficherSurCarte + || !$this->ancrageLegende instanceof AncrageLegende + || !$this->premiereVille instanceof VilleFormData) { + return null; + } + + $secondeVille = $this->secondeVille instanceof VilleFormData && !$this->secondeVille->estVide() + ? $this->secondeVille->toVille() + : null; + + return new Carte( + $this->utiliserSecondeCouleur, + $this->ancrageLegende, + $this->premiereVille->toVille(), + $secondeVille, + ); + } +} diff --git a/sources/AppBundle/Antennes/Form/CarteType.php b/sources/AppBundle/Antennes/Form/CarteType.php new file mode 100644 index 000000000..bcbbf083d --- /dev/null +++ b/sources/AppBundle/Antennes/Form/CarteType.php @@ -0,0 +1,59 @@ + + */ +final class CarteType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('afficherSurCarte', CheckboxType::class, [ + 'label' => 'Afficher sur la carte', + 'required' => false, + ]) + ->add('utiliserSecondeCouleur', CheckboxType::class, [ + 'label' => 'Utiliser la seconde couleur', + 'help' => 'Pour distinguer deux antennes voisines sur la carte.', + 'required' => false, + ]) + ->add('ancrageLegende', EnumType::class, [ + 'label' => 'Ancrage de la légende', + 'class' => AncrageLegende::class, + 'choice_label' => fn(AncrageLegende $ancrage): string => match ($ancrage) { + AncrageLegende::Haut => 'En haut', + AncrageLegende::Bas => 'En bas', + AncrageLegende::Gauche => 'À gauche', + AncrageLegende::Droite => 'À droite', + }, + 'required' => false, + 'placeholder' => false, + ]) + ->add('premiereVille', VilleType::class, [ + 'label' => 'Première ville', + ]) + ->add('secondeVille', VilleType::class, [ + 'label' => 'Seconde ville', + 'required' => false, + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => CarteFormData::class, + 'error_bubbling' => false, + ]); + } +} diff --git a/sources/AppBundle/Antennes/Form/ReseauxSociauxFormData.php b/sources/AppBundle/Antennes/Form/ReseauxSociauxFormData.php new file mode 100644 index 000000000..6ce3aa596 --- /dev/null +++ b/sources/AppBundle/Antennes/Form/ReseauxSociauxFormData.php @@ -0,0 +1,67 @@ +youtube = $reseauxSociaux->youtube; + $data->blog = $reseauxSociaux->blog; + $data->twitter = $reseauxSociaux->twitter; + $data->linkedin = $reseauxSociaux->linkedin; + $data->bluesky = $reseauxSociaux->bluesky; + $data->cfp = $reseauxSociaux->cfp; + $data->github = $reseauxSociaux->github; + $data->discord = $reseauxSociaux->discord; + + return $data; + } + + public function toReseauxSociaux(): ReseauxSociaux + { + return new ReseauxSociaux( + youtube: self::nullIfEmpty($this->youtube), + blog: self::nullIfEmpty($this->blog), + twitter: self::nullIfEmpty($this->twitter), + linkedin: self::nullIfEmpty($this->linkedin), + bluesky: self::nullIfEmpty($this->bluesky), + cfp: self::nullIfEmpty($this->cfp), + github: self::nullIfEmpty($this->github), + discord: self::nullIfEmpty($this->discord), + ); + } + + private static function nullIfEmpty(?string $value): ?string + { + $value = $value !== null ? trim($value) : null; + + return $value === '' ? null : $value; + } +} diff --git a/sources/AppBundle/Antennes/Form/ReseauxSociauxType.php b/sources/AppBundle/Antennes/Form/ReseauxSociauxType.php new file mode 100644 index 000000000..310f51c8f --- /dev/null +++ b/sources/AppBundle/Antennes/Form/ReseauxSociauxType.php @@ -0,0 +1,69 @@ + + */ +final class ReseauxSociauxType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder + ->add('blog', UrlType::class, [ + 'label' => 'Blog', + 'default_protocol' => 'https', + 'required' => false, + ]) + ->add('youtube', UrlType::class, [ + 'label' => 'YouTube', + 'default_protocol' => 'https', + 'help' => 'URL de la chaîne (ex. https://www.youtube.com/@afuplyon)', + 'required' => false, + ]) + ->add('linkedin', TextType::class, [ + 'label' => 'LinkedIn', + 'help' => 'Identifiant de la page entreprise (ex. afup-lyon pour https://www.linkedin.com/company/afup-lyon/)', + 'required' => false, + ]) + ->add('bluesky', TextType::class, [ + 'label' => 'Bluesky', + 'help' => 'Identifiant du compte (ex. lyon.afup.org)', + 'required' => false, + ]) + ->add('twitter', TextType::class, [ + 'label' => 'Twitter', + 'help' => 'Identifiant du compte, sans @ (ex. AFUP_Lyon)', + 'required' => false, + ]) + ->add('github', TextType::class, [ + 'label' => 'GitHub', + 'required' => false, + ]) + ->add('discord', UrlType::class, [ + 'label' => 'Discord', + 'default_protocol' => 'https', + 'required' => false, + ]) + ->add('cfp', UrlType::class, [ + 'label' => 'CFP', + 'default_protocol' => 'https', + 'required' => false, + ]); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => ReseauxSociauxFormData::class, + ]); + } +} diff --git a/sources/AppBundle/Antennes/Form/VilleFormData.php b/sources/AppBundle/Antennes/Form/VilleFormData.php new file mode 100644 index 000000000..6512c93fd --- /dev/null +++ b/sources/AppBundle/Antennes/Form/VilleFormData.php @@ -0,0 +1,86 @@ +premierPointX = $ville->premierPoint->x; + $data->premierPointY = $ville->premierPoint->y; + $data->deuxiemePointX = $ville->deuxiemePoint->x; + $data->deuxiemePointY = $ville->deuxiemePoint->y; + $data->troisiemePointX = $ville->troisiemePoint->x; + $data->troisiemePointY = $ville->troisiemePoint->y; + $data->latitude = $ville->position->latitude; + $data->longitude = $ville->position->longitude; + + return $data; + } + + public function estVide(): bool + { + return array_filter($this->valeurs(), fn(int|float|null $valeur): bool => $valeur !== null) === []; + } + + public function estComplete(): bool + { + return !\in_array(null, $this->valeurs(), true); + } + + public function toVille(): Ville + { + if (!$this->estComplete()) { + throw new \LogicException('La ville doit être complète pour être convertie.'); + } + + return new Ville( + new Point((int) $this->premierPointX, (int) $this->premierPointY), + new Point((int) $this->deuxiemePointX, (int) $this->deuxiemePointY), + new Point((int) $this->troisiemePointX, (int) $this->troisiemePointY), + new Position((float) $this->latitude, (float) $this->longitude), + ); + } + + /** + * @return list + */ + private function valeurs(): array + { + return [ + $this->premierPointX, + $this->premierPointY, + $this->deuxiemePointX, + $this->deuxiemePointY, + $this->troisiemePointX, + $this->troisiemePointY, + $this->latitude, + $this->longitude, + ]; + } +} diff --git a/sources/AppBundle/Antennes/Form/VilleType.php b/sources/AppBundle/Antennes/Form/VilleType.php new file mode 100644 index 000000000..7c184e418 --- /dev/null +++ b/sources/AppBundle/Antennes/Form/VilleType.php @@ -0,0 +1,47 @@ + + */ +final class VilleType extends AbstractType +{ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $points = [ + 'premierPoint' => 'Premier point', + 'deuxiemePoint' => 'Deuxième point', + 'troisiemePoint' => 'Troisième point', + ]; + + foreach ($points as $point => $label) { + $builder + ->add($point . 'X', IntegerType::class, ['label' => $label . ' (x)', 'required' => false]) + ->add($point . 'Y', IntegerType::class, ['label' => $label . ' (y)', 'required' => false]); + } + + // html5 : la valeur est rendue et lue au format « 45.759723 », quelle que soit la locale + $coordonnee = ['scale' => 6, 'html5' => true, 'required' => false, 'attr' => ['step' => 'any']]; + + $builder + ->add('latitude', NumberType::class, ['label' => 'Latitude'] + $coordonnee) + ->add('longitude', NumberType::class, ['label' => 'Longitude'] + $coordonnee); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => VilleFormData::class, + 'error_bubbling' => false, + ]); + } +} diff --git a/sources/AppBundle/Command/GenerateOfficesMapCommand.php b/sources/AppBundle/Command/GenerateOfficesMapCommand.php deleted file mode 100644 index d1b9b9205..000000000 --- a/sources/AppBundle/Command/GenerateOfficesMapCommand.php +++ /dev/null @@ -1,48 +0,0 @@ -templatesDir . self::MAP_TEMPLATE; - - $this->filesystem->dumpFile( - $path, - $this->generator->generate($this->antenneRepository->getAllSortedByLabels()), - ); - - new SymfonyStyle($input, $output)->success(sprintf('Carte générée dans %s', $path)); - - return Command::SUCCESS; - } -} diff --git a/sources/AppBundle/Controller/Admin/Antennes/AntenneAddAction.php b/sources/AppBundle/Controller/Admin/Antennes/AntenneAddAction.php new file mode 100644 index 000000000..8e68bfd62 --- /dev/null +++ b/sources/AppBundle/Controller/Admin/Antennes/AntenneAddAction.php @@ -0,0 +1,45 @@ +createForm(AntenneType::class, $data, ['creation' => true]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $antenne = $data->toEntity(); + $this->antenneRepository->save($antenne); + $this->audit->log("Ajout de l'antenne " . $antenne->code); + $this->addFlash('notice', "L'antenne " . $antenne->libelle . ' a été ajoutée'); + + return $this->redirectToRoute('admin_antennes_list'); + } + + return $this->render('admin/antennes/form.html.twig', [ + 'form' => $form->createView(), + 'formTitle' => 'Ajouter une antenne', + 'submitLabel' => 'Ajouter', + ]); + } +} diff --git a/sources/AppBundle/Controller/Admin/Antennes/AntenneEditAction.php b/sources/AppBundle/Controller/Admin/Antennes/AntenneEditAction.php new file mode 100644 index 000000000..d8e606e28 --- /dev/null +++ b/sources/AppBundle/Controller/Admin/Antennes/AntenneEditAction.php @@ -0,0 +1,53 @@ +antenneRepository->find($code); + + if (!$antenne instanceof Antenne) { + throw $this->createNotFoundException('Antenne non trouvée'); + } + + $data = AntenneFormData::fromEntity($antenne); + $form = $this->createForm(AntenneType::class, $data, ['creation' => false]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $data->appliquerA($antenne); + $this->antenneRepository->save($antenne); + $this->audit->log("Modification de l'antenne " . $antenne->code); + $this->addFlash('notice', "L'antenne " . $antenne->libelle . ' a été modifiée'); + + return $this->redirectToRoute('admin_antennes_list'); + } + + return $this->render('admin/antennes/form.html.twig', [ + 'form' => $form->createView(), + 'formTitle' => "Modifier l'antenne " . $antenne->libelle, + 'submitLabel' => 'Modifier', + 'antenne' => $antenne, + ]); + } +} diff --git a/sources/AppBundle/Controller/Admin/Antennes/AntenneListAction.php b/sources/AppBundle/Controller/Admin/Antennes/AntenneListAction.php index 5055b52ca..60f0e8a5b 100644 --- a/sources/AppBundle/Controller/Admin/Antennes/AntenneListAction.php +++ b/sources/AppBundle/Controller/Admin/Antennes/AntenneListAction.php @@ -4,7 +4,6 @@ namespace AppBundle\Controller\Admin\Antennes; -use AppBundle\Antennes\Entity\Antenne; use AppBundle\Antennes\Entity\Repository\AntenneRepository; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -21,15 +20,8 @@ public function __construct( public function __invoke(Request $request): Response { - $antennes = $this->antennesCollection->getAll(); - - uasort( - $antennes, - fn(Antenne $a, Antenne $b): int => strcmp($a->libelle, $b->libelle), - ); - return new Response($this->twig->render('admin/antennes/list.html.twig', [ - 'antennes' => $antennes, + 'antennes' => $this->antennesCollection->findBy([], ['libelle' => 'ASC']), ])); } } diff --git a/sources/AppBundle/Controller/Website/Static/OfficesAction.php b/sources/AppBundle/Controller/Website/Static/OfficesAction.php index 77cdfabaa..9c24b9f83 100644 --- a/sources/AppBundle/Controller/Website/Static/OfficesAction.php +++ b/sources/AppBundle/Controller/Website/Static/OfficesAction.php @@ -5,6 +5,7 @@ namespace AppBundle\Controller\Website\Static; use AppBundle\Antennes\Entity\Repository\AntenneRepository; +use AppBundle\Antennes\OfficesMapSvgGenerator; use AppBundle\Twig\ViewRenderer; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; @@ -14,12 +15,18 @@ final class OfficesAction extends AbstractController public function __construct( private readonly ViewRenderer $view, private readonly AntenneRepository $antennesRepository, + private readonly OfficesMapSvgGenerator $officesMapSvgGenerator, ) {} public function __invoke(): Response { + $antennes = $this->antennesRepository->getAllSortedByLabels(); + return $this->view->render('site/offices.html.twig', [ - 'antennes' => $this->antennesRepository->getAllSortedByLabels(), + 'antennes' => $antennes, + // Généré à chaque affichage (moins d'une milliseconde) pour refléter tout de suite + // les modifications faites dans l'admin ; les textes sont échappés par XMLWriter. + 'carteSvg' => $this->officesMapSvgGenerator->generate($antennes), ]); } } diff --git a/templates/admin/antennes/form.html.twig b/templates/admin/antennes/form.html.twig new file mode 100644 index 000000000..3b89365af --- /dev/null +++ b/templates/admin/antennes/form.html.twig @@ -0,0 +1,116 @@ +{% extends 'admin/base_with_header.html.twig' %} + +{% form_theme form 'form_theme_admin.html.twig' %} + +{% macro ville(form) %} + {{ form_errors(form) }} + {{ form_row(form.premierPointX) }} + {{ form_row(form.premierPointY) }} + {{ form_row(form.deuxiemePointX) }} + {{ form_row(form.deuxiemePointY) }} + {{ form_row(form.troisiemePointX) }} + {{ form_row(form.troisiemePointY) }} + {{ form_row(form.latitude) }} + {{ form_row(form.longitude) }} +{% endmacro %} + +{% block content %} +

{{ formTitle }}

+ + {{ form_start(form) }} + {{ form_errors(form) }} + +
+

Général

+
+ {% if form.code is defined %} + {{ form_row(form.code) }} + {% else %} +
+
+
{{ antenne.code }}
+
+ {% endif %} + {{ form_row(form.libelle) }} + {{ form_row(form.urlLogo) }} + {% if form.urlLogo.vars.value %} +
+
+
+ Logo actuel +
+
+ {% endif %} + {{ form_row(form.actif) }} +
+
+ +
+

Meetup

+
+ {{ form_row(form.meetupNomUrl) }} + {{ form_row(form.meetupIdExterne) }} +
+
+ +
+

Réseaux sociaux

+
+ {{ form_row(form.reseauxSociaux.blog) }} + {{ form_row(form.reseauxSociaux.youtube) }} + {{ form_row(form.reseauxSociaux.linkedin) }} + {{ form_row(form.reseauxSociaux.bluesky) }} + {{ form_row(form.reseauxSociaux.twitter) }} + {{ form_row(form.reseauxSociaux.github) }} + {{ form_row(form.reseauxSociaux.discord) }} + {{ form_row(form.reseauxSociaux.cfp) }} +
+
+ +
+

Localisation

+
+ {{ form_row(form.region) }} + {{ form_row(form.departements) }} + {{ form_row(form.pays) }} +
+
+ +
+

Carte

+
+

+ Les points x/y tracent le trait de légende sur la carte des antennes ; la latitude et la longitude + placent la ville sur la carte et servent à trouver l'antenne la plus proche d'un membre. + Laisser la seconde ville vide si l'antenne ne couvre qu'une ville. +

+
+
+ {{ form_errors(form.carte) }} + {{ form_row(form.carte.afficherSurCarte) }} + {{ form_row(form.carte.utiliserSecondeCouleur) }} + {{ form_row(form.carte.ancrageLegende) }} + +

Première ville

+ {{ _self.ville(form.carte.premiereVille) }} + +

Seconde ville

+ {{ _self.ville(form.carte.secondeVille) }} +
+
+ +
+
+
+
+ Annuler +
+
+ +
+
+
+
+ + {{ form_end(form) }} +{% endblock %} diff --git a/templates/admin/antennes/list.html.twig b/templates/admin/antennes/list.html.twig index 25db5c7ca..cdb58c097 100644 --- a/templates/admin/antennes/list.html.twig +++ b/templates/admin/antennes/list.html.twig @@ -3,13 +3,14 @@ {% block content %}

Antennes

-
-
- Liste en lecture seule + {% if is_granted('ROLE_ANTENNES_WRITER') %} + - -

Les modifications sont à faire dans le code (il faut demander au pole outils).

-
+ {% endif %}
{% if antennes|length > 0 %} @@ -60,6 +61,9 @@
+ {% if is_granted('ROLE_ANTENNES_WRITER') %} + Actions + {% endif %} @@ -153,6 +157,19 @@ {% endif %}
+ {% if is_granted('ROLE_ANTENNES_WRITER') %} + + + + + + {% endif %} {% endfor %} diff --git a/templates/site/offices.html.twig b/templates/site/offices.html.twig index 7b013e1aa..703a1140c 100644 --- a/templates/site/offices.html.twig +++ b/templates/site/offices.html.twig @@ -46,7 +46,7 @@
-
{{ source('site/partials/_offices_map.svg') }}
+
{{ carteSvg|raw }}
diff --git a/templates/site/partials/_offices_map.svg b/templates/site/partials/_offices_map.svg deleted file mode 100644 index 6a00df576..000000000 --- a/templates/site/partials/_offices_map.svg +++ /dev/null @@ -1,283 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Aix-Marseille - - - - - - Bordeaux - - - - - - - - Hauts de France - - - - - - Limoges - - - - - - - - Lorraine - - - - - - Luxembourg - - - - - - Lyon - - - - - - Montpellier - - - - - - Nantes - - - - - - Paris - - - - - - Poitiers - - - - - - Reims - - - - - - Rennes - - - - - - Toulouse - - - - - - Tours - - diff --git a/tests/behat/features/Admin/AdminPersonnesPhysiques.feature b/tests/behat/features/Admin/AdminPersonnesPhysiques.feature index a35b1b6a1..9b6378f74 100644 --- a/tests/behat/features/Admin/AdminPersonnesPhysiques.feature +++ b/tests/behat/features/Admin/AdminPersonnesPhysiques.feature @@ -37,10 +37,10 @@ Feature: Administration - Partie Personnes physiques Then I should not see "Cette valeur ne doit pas être vide" # les droits sont relus depuis les rôles de la personne - # l'id 9 correspond à la personne créée ci-dessus : les seeds insèrent 8 personnes + # l'id 10 correspond à la personne créée ci-dessus : les seeds insèrent 9 personnes # avec des identifiants explicites (cf. db/seeds/Users.php), le compteur auto-incrément - # est donc à 8 - When I am on "/admin/members/users/edit?id=9" + # est donc à 9 + When I am on "/admin/members/users/edit?id=10" Then the "user_edit_access_veille_2" checkbox should be checked And the "user_edit_access_site_1" checkbox should be checked And the "user_edit_access_membres_0" checkbox should be checked diff --git a/tests/behat/features/Admin/Antennes/List.feature b/tests/behat/features/Admin/Antennes/List.feature index ae8b74e1c..c7ff8b7d5 100644 --- a/tests/behat/features/Admin/Antennes/List.feature +++ b/tests/behat/features/Admin/Antennes/List.feature @@ -18,3 +18,103 @@ Feature: Administration - Partie Antennes And the "tr[data-qa='antenne-montpellier']" element should contain "Active" And the "tr[data-qa='antenne-clermont']" element should contain "Inactive" + + @reloadDbWithTestData + Scenario: Ajout d'une antenne + Given I am logged in as admin and on the Administration + And I follow "afup-main-menu-item--antennes_index" + When I follow "Ajouter une antenne" + Then I should see "Ajouter une antenne" + When I fill in "antenne[code]" with "grenoble" + And I fill in "antenne[libelle]" with "Grenoble" + And I fill in "antenne[urlLogo]" with "https://identity.afup.org/logos/grenoble.svg" + And I fill in "antenne[meetupNomUrl]" with "afup-grenoble-php" + And I fill in "antenne[meetupIdExterne]" with "12345678" + And I fill in "antenne[reseauxSociaux][linkedin]" with "afup-grenoble" + And I fill in "antenne[region]" with "Auvergne-Rhône-Alpes" + And I fill in "antenne[departements]" with "38" + And I check "antenne[carte][afficherSurCarte]" + And I select "left" from "antenne[carte][ancrageLegende]" + And I fill in "antenne[carte][premiereVille][premierPointX]" with "600" + And I fill in "antenne[carte][premiereVille][premierPointY]" with "430" + And I fill in "antenne[carte][premiereVille][deuxiemePointX]" with "680" + And I fill in "antenne[carte][premiereVille][deuxiemePointY]" with "460" + And I fill in "antenne[carte][premiereVille][troisiemePointX]" with "710" + And I fill in "antenne[carte][premiereVille][troisiemePointY]" with "460" + And I fill in "antenne[carte][premiereVille][latitude]" with "45.188529" + And I fill in "antenne[carte][premiereVille][longitude]" with "5.724524" + And I press "Ajouter" + Then I should see "L'antenne Grenoble a été ajoutée" + And the "tr[data-qa='antenne-grenoble']" element should contain "Grenoble" + And the "tr[data-qa='antenne-grenoble']" element should contain "meetup.com" + And the "tr[data-qa='antenne-grenoble']" element should contain "linkedin.com" + And the "tr[data-qa='antenne-grenoble']" element should contain "Active" + When I follow "antenne-edit-grenoble" + Then the "antenne[departements]" field should contain "38" + And the "antenne[carte][premiereVille][latitude]" field should contain "45.188529" + + @reloadDbWithTestData + Scenario: Modification d'une antenne + Given I am logged in as admin and on the Administration + And I follow "afup-main-menu-item--antennes_index" + When I follow "antenne-edit-lyon" + Then I should see "Modifier l'antenne Lyon" + And I should not see an "#antenne_code" element + And the "antenne[reseauxSociaux][linkedin]" field should contain "afup-lyon" + When I fill in "antenne[libelle]" with "Lyon et environs" + And I fill in "antenne[reseauxSociaux][linkedin]" with "afup-lyon-officiel" + And I press "Modifier" + Then I should see "L'antenne Lyon et environs a été modifiée" + And the "tr[data-qa='antenne-lyon']" element should contain "Lyon et environs" + And the "tr[data-qa='antenne-lyon']" element should contain "linkedin.com/company/afup-lyon-officiel" + And the "tr[data-qa='antenne-lyon']" element should contain "youtube.com" + # la carte publique est générée à l'affichage : la modification y est visible immédiatement + When I go to "/association/antennes" + Then the response should contain "aria-label=\"Lyon et environs\"" + + @reloadDbWithTestData + Scenario: Désactivation d'une antenne + Given I am logged in as admin and on the Administration + And I follow "afup-main-menu-item--antennes_index" + And the "tr[data-qa='antenne-montpellier']" element should contain "Active" + When I go to "/association/antennes" + Then the response should contain "aria-label=\"Montpellier\"" + When I go to "/admin/antennes/" + And I follow "antenne-edit-montpellier" + And I uncheck "antenne[actif]" + And I press "Modifier" + Then I should see "L'antenne Montpellier a été modifiée" + And the "tr[data-qa='antenne-montpellier']" element should contain "Inactive" + # une antenne inactive disparaît de la carte publique + When I go to "/association/antennes" + Then the response should not contain "aria-label=\"Montpellier\"" + + Scenario: Le code d'une nouvelle antenne doit être unique + Given I am logged in as admin and on the Administration + And I am on "/admin/antennes/add" + When I fill in "antenne[code]" with "lyon" + And I fill in "antenne[libelle]" with "Lyon bis" + And I fill in "antenne[urlLogo]" with "https://identity.afup.org/logos/lyon.svg" + And I press "Ajouter" + Then I should see "Une antenne existe déjà avec le code « lyon »." + + Scenario: Le logo doit être une URL valide + Given I am logged in as admin and on the Administration + And I am on "/admin/antennes/add" + When I fill in "antenne[code]" with "grenoble" + And I fill in "antenne[libelle]" with "Grenoble" + And I fill in "antenne[urlLogo]" with "pas-une-url" + And I press "Ajouter" + Then I should see "Le logo doit être une URL valide" + + Scenario: Un lecteur des antennes ne peut pas les modifier + Given I am logged-in with the user "lecteurantennes" and the password "lecteurantennes" + When I go to "/admin/antennes/" + Then the response status code should be 200 + And the "tr[data-qa='antenne-lyon']" element should contain "Lyon" + And I should not see "Ajouter une antenne" + And I should not see an "[data-qa='antenne-edit-lyon']" element + When I go to "/admin/antennes/add" + Then the response status code should be 403 + When I go to "/admin/antennes/edit/lyon" + Then the response status code should be 403 diff --git a/tests/behat/features/Admin/Members/AdminMembersReporting.feature b/tests/behat/features/Admin/Members/AdminMembersReporting.feature index d6b86b4a8..2a73e6613 100644 --- a/tests/behat/features/Admin/Members/AdminMembersReporting.feature +++ b/tests/behat/features/Admin/Members/AdminMembersReporting.feature @@ -5,5 +5,5 @@ Feature: Administration - Partie Reporting Given I am logged in as admin and on the Administration And I follow "Reporting" Then the ".content h2" element should contain "Statistiques concernant les membres" - Then I should see "3 Personnes physiques totales*" - Then I should see "2 Personnes physiques non rattachées à une personne morale*" + Then I should see "4 Personnes physiques totales*" + Then I should see "3 Personnes physiques non rattachées à une personne morale*" diff --git a/tests/integration/AppBundle/Antennes/Entity/Repository/AntenneRepositoryTest.php b/tests/integration/AppBundle/Antennes/Entity/Repository/AntenneRepositoryTest.php index 0a98e3fe6..1b12d50a2 100644 --- a/tests/integration/AppBundle/Antennes/Entity/Repository/AntenneRepositoryTest.php +++ b/tests/integration/AppBundle/Antennes/Entity/Repository/AntenneRepositoryTest.php @@ -8,22 +8,9 @@ use AppBundle\Antennes\Entity\Antenne; use AppBundle\Antennes\Entity\Repository\AntenneRepository; use AppBundle\Antennes\AncrageLegende; -use AppBundle\Antennes\OfficesMapSvgGenerator; -use AppBundle\Command\GenerateOfficesMapCommand; final class AntenneRepositoryTest extends IntegrationTestCase { - public function testCommittedMapIsUpToDate(): void - { - $generated = new OfficesMapSvgGenerator()->generate($this->repository()->getAllSortedByLabels()); - - self::assertStringEqualsFile( - __DIR__ . '/../../../../../../templates/' . GenerateOfficesMapCommand::MAP_TEMPLATE, - $generated, - 'La carte des antennes n\'est plus à jour : lancer `bin/console antennes:generate-map`.', - ); - } - public function testGetAll(): void { $antennes = $this->repository()->getAll(); diff --git a/tests/unit/AppBundle/Antennes/Form/AntenneFormDataTest.php b/tests/unit/AppBundle/Antennes/Form/AntenneFormDataTest.php new file mode 100644 index 000000000..1dcf3177d --- /dev/null +++ b/tests/unit/AppBundle/Antennes/Form/AntenneFormDataTest.php @@ -0,0 +1,194 @@ +toEntity()); + } + + public function testFromEntitySansCarteNiMeetup(): void + { + $antenne = new Antenne( + code: 'clermont', + libelle: 'Clermont', + meetup: null, + urlLogo: '/images/offices/clermont.svg', + reseauxSociaux: new ReseauxSociaux(), + carte: null, + masqueePageAntennes: true, + ); + + $data = AntenneFormData::fromEntity($antenne); + + self::assertNull($data->meetupNomUrl); + self::assertNull($data->meetupIdExterne); + self::assertFalse($data->carte->afficherSurCarte); + self::assertFalse($data->actif); + self::assertEquals($antenne, $data->toEntity()); + } + + public function testActifEstLInverseDeMasqueePageAntennes(): void + { + $data = AntenneFormData::fromEntity(self::antenne()); + self::assertTrue($data->actif); + + $data->actif = false; + self::assertTrue($data->toEntity()->masqueePageAntennes); + + $data->actif = true; + self::assertFalse($data->toEntity()->masqueePageAntennes); + } + + public function testAppliquerAModifieLAntenneSansToucherAuCode(): void + { + $antenne = self::antenne(); + $data = AntenneFormData::fromEntity($antenne); + $data->code = 'autre-code'; + $data->libelle = 'Lyon et environs'; + $data->meetupNomUrl = ''; + $data->meetupIdExterne = ''; + $data->reseauxSociaux->linkedin = 'afup-lyon-officiel'; + $data->reseauxSociaux->blog = ''; + $data->carte->afficherSurCarte = false; + $data->departements = ['69', '01']; + $data->region = ''; + $data->actif = false; + + $data->appliquerA($antenne); + + self::assertSame('lyon', $antenne->code); + self::assertSame('Lyon et environs', $antenne->libelle); + self::assertNull($antenne->meetup); + self::assertSame('afup-lyon-officiel', $antenne->reseauxSociaux->linkedin); + self::assertNull($antenne->reseauxSociaux->blog); + self::assertNull($antenne->carte); + self::assertSame(['69', '01'], $antenne->departements); + self::assertNull($antenne->region); + self::assertTrue($antenne->masqueePageAntennes); + } + + public function testMeetupIncompletEstIgnore(): void + { + $data = AntenneFormData::fromEntity(self::antenne()); + $data->meetupIdExterne = ' '; + + self::assertNull($data->toEntity()->meetup); + } + + public function testReseauxSociauxVidesDeviennentNull(): void + { + $data = new ReseauxSociauxFormData(); + $data->youtube = ''; + $data->blog = ' '; + $data->twitter = 'AFUP_Lyon'; + + self::assertEquals(new ReseauxSociaux(twitter: 'AFUP_Lyon'), $data->toReseauxSociaux()); + } + + public function testCarteNonAfficheeDonneNull(): void + { + $data = CarteFormData::fromCarte(self::carte()); + $data->afficherSurCarte = false; + + self::assertNull($data->toCarte()); + } + + public function testCarteAvecUneVille(): void + { + $data = CarteFormData::fromCarte(self::carte()); + + self::assertEquals(self::carte(), $data->toCarte()); + } + + public function testCarteAvecUneSecondeVilleVideLIgnore(): void + { + $data = CarteFormData::fromCarte(self::carte()); + $data->secondeVille = new VilleFormData(); + + self::assertEquals(self::carte(), $data->toCarte()); + } + + public function testCarteAvecDeuxVilles(): void + { + $carte = self::carte(self::ville(46.0, 5.0)); + + self::assertEquals($carte, CarteFormData::fromCarte($carte)->toCarte()); + } + + public function testCompletudeDUneVille(): void + { + $ville = new VilleFormData(); + self::assertTrue($ville->estVide()); + self::assertFalse($ville->estComplete()); + + $ville->latitude = 45.0; + self::assertFalse($ville->estVide()); + self::assertFalse($ville->estComplete()); + + $ville = VilleFormData::fromVille(self::ville(45.0, 4.0)); + self::assertFalse($ville->estVide()); + self::assertTrue($ville->estComplete()); + } + + private static function antenne(?Ville $secondeVille = null): Antenne + { + return new Antenne( + code: 'lyon', + libelle: 'Lyon', + meetup: new Meetup('afup-lyon-php', '19630036'), + urlLogo: '/images/offices/lyon.svg', + reseauxSociaux: new ReseauxSociaux( + youtube: 'https://www.youtube.com/@afuplyon', + blog: 'https://lyon.afup.org', + twitter: 'AFUP_Lyon', + linkedin: 'afup-lyon', + bluesky: 'lyon.afup.org', + ), + carte: self::carte($secondeVille), + departements: ['69'], + pays: null, + region: 'Auvergne-Rhône-Alpes', + ); + } + + private static function carte(?Ville $secondeVille = null): Carte + { + return new Carte( + utiliserSecondeCouleur: false, + ancrageLegende: AncrageLegende::Gauche, + premiereVille: self::ville(45.759723, 4.842223), + secondeVille: $secondeVille, + ); + } + + private static function ville(float $latitude, float $longitude): Ville + { + return new Ville( + new Point(570, 380), + new Point(680, 320), + new Point(710, 320), + new Position($latitude, $longitude), + ); + } +}