Skip to content
Open
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
2 changes: 2 additions & 0 deletions config/packages/backoffice_menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions config/routing/admin_antennes.yml
Original file line number Diff line number Diff line change
@@ -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-]+'
13 changes: 13 additions & 0 deletions db/seeds/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
49 changes: 38 additions & 11 deletions sources/AppBundle/Antennes/Entity/Antenne.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand All @@ -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
Expand All @@ -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;
}
}
161 changes: 161 additions & 0 deletions sources/AppBundle/Antennes/Form/AntenneFormData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php

declare(strict_types=1);

namespace AppBundle\Antennes\Form;

use AppBundle\Antennes\Entity\Antenne;
use AppBundle\Antennes\Meetup;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;

final class AntenneFormData
{
public const string GROUPE_CREATION = 'creation';

/**
* Uniquement saisi à la création : le code est la clé primaire et il est référencé ailleurs
* (super apéros, antenne la plus proche des membres, billets, indexation des meetups).
* Son unicité est vérifiée par AntenneType.
*/
#[Assert\NotBlank(groups: [self::GROUPE_CREATION])]
#[Assert\Length(max: 50, groups: [self::GROUPE_CREATION])]
#[Assert\Regex(
pattern: '/^[a-z0-9-]+$/',
message: 'Le code ne peut contenir que des lettres minuscules non accentuées, des chiffres et des tirets.',
groups: [self::GROUPE_CREATION],
)]
public ?string $code = null;

#[Assert\NotBlank]
#[Assert\Length(max: 255)]
public ?string $libelle = null;

/**
* Les logos existants sont servis par le site (`/images/offices/…`) : un chemin absolu est donc accepté
* en plus d'une URL complète.
*/
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
#[Assert\AtLeastOneOf(
constraints: [
new Assert\Url(requireTld: true),
new Assert\Regex(pattern: '#^/[^/\s]\S*$#'),
],
message: 'Le logo doit être une URL valide (ou un chemin commençant par « / »).',
includeInternalMessages: false,
)]
public ?string $urlLogo = null;

#[Assert\Length(max: 255)]
public ?string $meetupNomUrl = null;

#[Assert\Length(max: 50)]
public ?string $meetupIdExterne = null;

#[Assert\Valid]
public ReseauxSociauxFormData $reseauxSociaux;

#[Assert\Valid]
public CarteFormData $carte;

/** @var string[]|null */
public ?array $departements = null;

/** @var string[]|null */
public ?array $pays = null;

#[Assert\Length(max: 255)]
public ?string $region = null;

public bool $actif = true;

public function __construct()
{
$this->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;
}
}
Loading
Loading