Skip to content

Commit

Permalink
Merge branch 'develop' #3164
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinx13 committed Oct 14, 2024
2 parents 80214fc + 454669b commit f5d4215
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 24 deletions.
57 changes: 57 additions & 0 deletions migrations/Version20241004142515.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20241004142515 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add unique index on created_from_id column in signalement table';
}

public function up(Schema $schema): void
{
$queryDuplicates = '
SELECT id, created_from_id, statut
FROM signalement
WHERE created_from_id IN (
SELECT created_from_id
FROM signalement
GROUP BY created_from_id
HAVING COUNT(*) > 1
)
ORDER BY created_from_id ASC, statut desc
';
$list = $this->connection->fetchAllAssociative($queryDuplicates);
$createdFrom = 0;
$lastId = 0;
foreach ($list as $item) {
// lorsqu'on a parcouru tous les doublons pour un même draft on garde uniquement le dernier de la liste (correspondant au statut le plus bas)
if ($createdFrom !== $item['created_from_id']) {
$this->keepSingleSignalementWithCreatedFrom($createdFrom, $lastId);
$createdFrom = $item['created_from_id'];
}
$lastId = $item['id'];
}
$this->keepSingleSignalementWithCreatedFrom($createdFrom, $lastId);
$this->addSql('ALTER TABLE signalement DROP INDEX IDX_F4B551143EA4CB4D, ADD UNIQUE INDEX UNIQ_F4B551143EA4CB4D (created_from_id)');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE signalement DROP INDEX UNIQ_F4B551143EA4CB4D, ADD INDEX IDX_F4B551143EA4CB4D (created_from_id)');
}

private function keepSingleSignalementWithCreatedFrom(int $createdFrom, int $lastId): void
{
$this->addSql('UPDATE signalement SET created_from_id = NULL WHERE created_from_id = :created_from_id AND id != :id', [
'created_from_id' => $createdFrom,
'id' => $lastId,
]);
}
}
29 changes: 15 additions & 14 deletions src/Controller/Back/SignalementFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,22 @@ public function deleteFileSignalement(
$type = $file->getFileType();
if ($uploadHandlerService->deleteFile($file)) {
$suivi = $suiviFactory->createInstanceFrom($this->getUser(), $signalement);
/** @var User $user */
$user = $this->getUser();
$description = $user->getNomComplet().' a supprimé ';
$description .= File::FILE_TYPE_DOCUMENT === $type ? 'le document suivant :' : 'la photo suivante :';
$suivi->setDescription(
$description
.'<ul><li>'
.$filename
.'</li></ul>'
);
$suivi->setType(Suivi::TYPE_AUTO);

$entityManager->persist($suivi);
$entityManager->flush();
if (!$this->isGranted('ROLE_ADMIN')) {
/** @var User $user */
$user = $this->getUser();
$description = $user->getNomComplet().' a supprimé ';
$description .= File::FILE_TYPE_DOCUMENT === $type ? 'le document suivant :' : 'la photo suivante :';
$suivi->setDescription(
$description
.'<ul><li>'
.$filename
.'</li></ul>'
);
$suivi->setType(Suivi::TYPE_AUTO);

$entityManager->persist($suivi);
$entityManager->flush();
}
if (File::FILE_TYPE_DOCUMENT === $type) {
$this->addFlash('success', 'Le document a bien été supprimé.');
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/DataFixtures/Files/NewSignalement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ signalements:
nb_pieces_logement: 5
nb_occupants_logement: 4
score: 35.194711538462
created_from_uuid: '00000000-0000-0000-2023-locataire003'
created_from_uuid: '00000000-0000-0000-2024-locataire001'
profile_declarant: "LOCATAIRE"
civilite_occupant: "mme"
type_composition_logement: "{\"bail_dpe_dpe\": \"oui\", \"bail_dpe_bail\": \"oui\", \"type_logement_rdc\": null, \"type_logement_nature\": \"maison\", \"bail_dpe_etat_des_lieux\": \"oui\", \"bail_dpe_date_emmenagement\": \"2019-12-01\", \"type_logement_commodites_wc\": \"oui\", \"type_logement_dernier_etage\": null, \"composition_logement_enfants\": \"oui\", \"composition_logement_hauteur\": \"oui\", \"composition_logement_nb_pieces\": \"5\", \"composition_logement_superficie\": \"67\", \"type_logement_commodites_cuisine\": \"oui\", \"composition_logement_piece_unique\": \"plusieurs_pieces\", \"type_logement_commodites_wc_cuisine\": \"non\", \"type_logement_sous_sol_sans_fenetre\": null, \"composition_logement_nombre_personnes\": \"4\", \"type_logement_commodites_salle_de_bain\": \"oui\", \"type_logement_commodites_wc_collective\": null, \"type_logement_sous_comble_sans_fenetre\": null, \"type_logement_commodites_piece_a_vivre_9m\": \"oui\", \"type_logement_commodites_cuisine_collective\": null, \"type_logement_commodites_salle_de_bain_collective\": null}"
Expand Down Expand Up @@ -295,7 +295,7 @@ signalements:
nb_pieces_logement: 5
nb_occupants_logement: 4
score: 35.194711538462
created_from_uuid: '00000000-0000-0000-2024-locataire002'
created_from_uuid: '00000000-0000-0000-2023-locataire004'
profile_declarant: "LOCATAIRE"
civilite_occupant: "mme"
type_composition_logement: "{\"bail_dpe_dpe\": \"oui\", \"bail_dpe_bail\": \"oui\", \"type_logement_rdc\": null, \"type_logement_nature\": \"maison\", \"bail_dpe_etat_des_lieux\": \"oui\", \"bail_dpe_date_emmenagement\": \"2019-12-01\", \"type_logement_commodites_wc\": \"oui\", \"type_logement_dernier_etage\": null, \"composition_logement_enfants\": \"oui\", \"composition_logement_hauteur\": \"oui\", \"composition_logement_nb_pieces\": \"5\", \"composition_logement_superficie\": \"67\", \"type_logement_commodites_cuisine\": \"oui\", \"composition_logement_piece_unique\": \"plusieurs_pieces\", \"type_logement_commodites_wc_cuisine\": \"non\", \"type_logement_sous_sol_sans_fenetre\": null, \"composition_logement_nombre_personnes\": \"4\", \"type_logement_commodites_salle_de_bain\": \"oui\", \"type_logement_commodites_wc_collective\": null, \"type_logement_sous_comble_sans_fenetre\": null, \"type_logement_commodites_piece_a_vivre_9m\": \"oui\", \"type_logement_commodites_cuisine_collective\": null, \"type_logement_commodites_salle_de_bain_collective\": null}"
Expand Down Expand Up @@ -381,7 +381,7 @@ signalements:
nb_pieces_logement: 5
nb_occupants_logement: 4
score: 35.194711538462
created_from_uuid: '00000000-0000-0000-2024-locataire002'
created_from_uuid: '00000000-0000-0000-2024-bailleuroc01'
profile_declarant: "LOCATAIRE"
civilite_occupant: "mme"
type_composition_logement: "{\"bail_dpe_dpe\": \"oui\", \"bail_dpe_bail\": \"oui\", \"type_logement_rdc\": null, \"type_logement_nature\": \"maison\", \"bail_dpe_etat_des_lieux\": \"oui\", \"bail_dpe_date_emmenagement\": \"2019-12-01\", \"type_logement_commodites_wc\": \"oui\", \"type_logement_dernier_etage\": null, \"composition_logement_enfants\": \"oui\", \"composition_logement_hauteur\": \"oui\", \"composition_logement_nb_pieces\": \"5\", \"composition_logement_superficie\": \"67\", \"type_logement_commodites_cuisine\": \"oui\", \"composition_logement_piece_unique\": \"plusieurs_pieces\", \"type_logement_commodites_wc_cuisine\": \"non\", \"type_logement_sous_sol_sans_fenetre\": null, \"composition_logement_nombre_personnes\": \"4\", \"type_logement_commodites_salle_de_bain\": \"oui\", \"type_logement_commodites_wc_collective\": null, \"type_logement_sous_comble_sans_fenetre\": null, \"type_logement_commodites_piece_a_vivre_9m\": \"oui\", \"type_logement_commodites_cuisine_collective\": null, \"type_logement_commodites_salle_de_bain_collective\": null}"
Expand Down Expand Up @@ -466,7 +466,7 @@ signalements:
nb_pieces_logement: 5
nb_occupants_logement: 4
score: 35.194711538462
created_from_uuid: '00000000-0000-0000-2024-locataire002'
created_from_uuid: '00000000-0000-0000-2024-bailleuroc02'
profile_declarant: "LOCATAIRE"
civilite_occupant: "mme"
type_composition_logement: "{\"bail_dpe_dpe\": \"oui\", \"bail_dpe_bail\": \"oui\", \"type_logement_rdc\": null, \"type_logement_nature\": \"maison\", \"bail_dpe_etat_des_lieux\": \"oui\", \"bail_dpe_date_emmenagement\": \"2019-12-01\", \"type_logement_commodites_wc\": \"oui\", \"type_logement_dernier_etage\": null, \"composition_logement_enfants\": \"non\", \"composition_logement_hauteur\": \"oui\", \"composition_logement_nb_pieces\": \"5\", \"composition_logement_superficie\": \"67\", \"type_logement_commodites_cuisine\": \"oui\", \"composition_logement_piece_unique\": \"plusieurs_pieces\", \"type_logement_commodites_wc_cuisine\": \"non\", \"type_logement_sous_sol_sans_fenetre\": null, \"composition_logement_nombre_personnes\": \"4\", \"type_logement_commodites_salle_de_bain\": \"oui\", \"type_logement_commodites_wc_collective\": null, \"type_logement_sous_comble_sans_fenetre\": null, \"type_logement_commodites_piece_a_vivre_9m\": \"oui\", \"type_logement_commodites_cuisine_collective\": null, \"type_logement_commodites_salle_de_bain_collective\": null}"
Expand Down
13 changes: 13 additions & 0 deletions src/DataFixtures/Files/SignalementDraft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ signalements_draft:
profile_declarant: 'LOCATAIRE'
email_declarant: '[email protected]'
payload: 'locataire_all_in.json'
status: 'EN_SIGNALEMENT'
-
uuid: '00000000-0000-0000-2023-bailleuroc01'
profile_declarant: 'BAILLEUR_OCCUPANT'
Expand Down Expand Up @@ -79,3 +80,15 @@ signalements_draft:
email_declarant: '[email protected]'
payload: 'step/validation_signalement/service_secours.json'
created_at_period: '-7 months'
-
uuid: '00000000-0000-0000-2024-bailleuroc01'
profile_declarant: 'BAILLEUR_OCCUPANT'
email_declarant: '[email protected]'
payload: 'bailleur_occupant.json'
status: 'EN_SIGNALEMENT'
-
uuid: '00000000-0000-0000-2024-bailleuroc02'
profile_declarant: 'BAILLEUR_OCCUPANT'
email_declarant: '[email protected]'
payload: 'bailleur_occupant.json'
status: 'EN_SIGNALEMENT'
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function onSignalementDraftCompleted(SignalementDraftCompletedEvent $even
} catch (\Throwable $exception) {
$this->logger->critical($exception->getMessage());
$this->entityManager->rollback();
throw $exception;
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/Manager/SignalementDraftManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
use App\Event\SignalementDraftCompletedEvent;
use App\Factory\SignalementDraftFactory;
use App\Repository\SignalementDraftRepository;
use App\Repository\SignalementRepository;
use App\Serializer\SignalementDraftRequestSerializer;
use App\Service\Signalement\SignalementDraftHelper;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Expand All @@ -28,6 +30,7 @@ public function __construct(
protected UrlGeneratorInterface $urlGenerator,
protected SignalementDraftRequestSerializer $signalementDraftRequestSerializer,
protected SignalementDraftRepository $signalementDraftRepository,
protected SignalementRepository $signalementRepository,
protected string $entityName = SignalementDraft::class,
) {
parent::__construct($managerRegistry, $entityName);
Expand Down Expand Up @@ -59,7 +62,12 @@ public function update(
if (SignalementDraftStatus::EN_SIGNALEMENT === $signalementDraft->getStatus()) {
$signalement = $signalementDraft->getSignalements()->first();
} else {
$signalement = $this->dispatchSignalementDraftCompleted($signalementDraft);
try {
$signalement = $this->dispatchSignalementDraftCompleted($signalementDraft);
} catch (UniqueConstraintViolationException $exception) {
$signalement = $this->signalementRepository->findOneBy(['createdFrom' => $signalementDraft]);
$this->managerRegistry->resetManager();
}
}
}
$this->save($signalementDraft);
Expand Down
4 changes: 4 additions & 0 deletions src/Security/Voter/FileVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ private function canEdit(File $file, User $user): bool

private function canDelete(File $file, User $user): bool
{
if ($user->isSuperAdmin()) {
return true;
}

return $this->canCreate($file, $user)
&& (
$this->isFileUploadedByUser($file, $user)
Expand Down
46 changes: 41 additions & 5 deletions templates/front/_partials/_suivi_signalement_tab_infos.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,54 @@ and signalement.profileDeclarant is not same as enum('App\\Entity\\Enum\\Profile
{% endif %}
</div>

<h4 class="fr-mb-2v">Photos</h4>
<h4 class="fr-mb-2v">Vos photos</h4>
<div class="fr-mb-4v">
{% if signalement.files|filter(photo => photo.fileType == 'photo')|length %}
{% if signalement.files|filter(photo => photo.fileType == 'photo' and photo.isUsagerFile)|length %}
Les photos que vous avez ajoutées.
<br>
Cliquez sur la photo pour l'ouvrir dans un nouvel onglet.
<br>
{% for photo in signalement.files|filter(photo => photo.fileType == 'photo') %}
<a href="{{ path('show_file', {uuid: photo.uuid}) }}?variant=resize" class="photo-preview" target="_blank" rel="noopener">
{% for photo in signalement.files|filter(photo => photo.fileType == 'photo' and photo.isUsagerFile) %}
<a href="{{ path('show_file', {uuid: photo.uuid}) }}?variant=resize" class="photo-preview" target="_blank" rel="noopener"
title="Voir la photo {{photo.title}} - ouvre une nouvelle fenêtre">
<img src="{{ path('show_file', {uuid: photo.uuid}) }}?variant=thumb" alt="{{photo.title}}">
</a>
{% endfor %}
{% else %}
Aucune photo à afficher, si vous avez ajouté des photos dans votre signalement, rafraîchissez la page pour les voir apparaître.
Aucune photo à afficher. Si vous avez ajouté des photos dans votre signalement, rafraîchissez la page pour les voir apparaître.
{% endif %}
</div>

{% if signalement.files|filter(photo => photo.fileType == 'photo' and photo.isUsagerFile is same as(false))|length %}
<h4 class="fr-mb-2v">Photos supplémentaires</h4>
<div class="fr-mb-4v">
Les photos ajoutées à votre dossier par l'administration.
<br>
Cliquez sur la photo pour l'ouvrir dans un nouvel onglet.
<br>
{% for photo in signalement.files|filter(photo => photo.fileType == 'photo' and photo.isUsagerFile is same as(false)) %}
<a href="{{ path('show_file', {uuid: photo.uuid}) }}?variant=resize" class="photo-preview" target="_blank" rel="noopener"
title="Voir la photo {{photo.title}} - ouvre une nouvelle fenêtre">
<img src="{{ path('show_file', {uuid: photo.uuid}) }}?variant=thumb" alt="{{photo.title}}">
</a>
{% endfor %}
</div>
{% endif %}

<h4 class="fr-mb-2v">Documents</h4>
<div class="fr-mb-4v">
{% if signalement.files|filter(doc => doc.fileType == 'document' and doc.isUsagerFile)|length %}
Cliquez sur le document pour l'ouvrir dans un nouvel onglet.
<br>
{% for doc in signalement.files|filter(doc => doc.fileType == 'document' and doc.isUsagerFile) %}
<a href="{{ path('show_file', {uuid: doc.uuid}) }}" target="_blank" class="fr-link" rel="noopener"
title="Voir le document {{doc.title}} - ouvre une nouvelle fenêtre">
{{doc.title}}
</a>
<br>
{% endfor %}
{% else %}
Aucun document à afficher. Si vous avez ajouté des documents dans votre signalement, rafraîchissez la page pour les voir apparaître.
{% endif %}
</div>

Expand Down
4 changes: 4 additions & 0 deletions tests/Functional/Manager/SignalementDraftManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Factory\SignalementDraftFactory;
use App\Manager\SignalementDraftManager;
use App\Repository\SignalementDraftRepository;
use App\Repository\SignalementRepository;
use App\Serializer\SignalementDraftRequestSerializer;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
Expand All @@ -27,6 +28,7 @@ class SignalementDraftManagerTest extends WebTestCase
private UrlGeneratorInterface $urlGenerator;
private SignalementDraftRequestSerializer $signalementDraftRequestSerializer;
private SignalementDraftRepository $signalementDraftRepository;
private SignalementRepository $signalementRepository;

protected function setUp(): void
{
Expand All @@ -38,6 +40,7 @@ protected function setUp(): void
$this->urlGenerator = static::getContainer()->get(UrlGeneratorInterface::class);
$this->signalementDraftRequestSerializer = static::getContainer()->get(SignalementDraftRequestSerializer::class);
$this->signalementDraftRepository = static::getContainer()->get(SignalementDraftRepository::class);
$this->signalementRepository = static::getContainer()->get(SignalementRepository::class);

$this->signalementDraftManager = new SignalementDraftManager(
$this->signalementDraftFactory,
Expand All @@ -46,6 +49,7 @@ protected function setUp(): void
$this->urlGenerator,
$this->signalementDraftRequestSerializer,
$this->signalementDraftRepository,
$this->signalementRepository,
);

$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => '[email protected]']);
Expand Down

0 comments on commit f5d4215

Please sign in to comment.