Skip to content

Commit

Permalink
Merge pull request #1467 from MTES-MCT/hotfix/1466-saisie-prolonge
Browse files Browse the repository at this point in the history
[FO - Signalement] Problème d'enregistrement des signalements pour les utilisateurs avec une saisie prolongée
  • Loading branch information
hmeneuvrier authored Jul 12, 2023
2 parents 9598dcf + 7ea9fae commit fb208bd
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 58 deletions.
10 changes: 10 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,16 @@ forms.forEach((form) => {

if (nextTabBtn) {
if (nextTabBtn.hasAttribute('data-fr-last-step')) {
let inputHiddenElement = document.querySelector(
'#signalement-step-last-panel input[type=hidden]'
);

fetch('/signalement/csrf-token')
.then(response => response.json())
.then(obj => {
inputHiddenElement.value = obj.csrf_token.value;
});

var nbDocs = 0;
var nbPhotos = 0;
document.querySelector('#recap-signalement-situation').innerHTML = '';
Expand Down
9 changes: 5 additions & 4 deletions src/Controller/FrontSignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use App\Form\SignalementType;
use App\Manager\SuiviManager;
use App\Manager\UserManager;
use App\Repository\CritereRepository;
use App\Repository\SignalementRepository;
use App\Repository\SituationRepository;
use App\Repository\TerritoryRepository;
Expand Down Expand Up @@ -115,7 +114,6 @@ public function envoi(
ReferenceGenerator $referenceGenerator,
PostalCodeHomeChecker $postalCodeHomeChecker,
EventDispatcherInterface $eventDispatcher,
CritereRepository $critereRepository,
SignalementQualificationFactory $signalementQualificationFactory,
QualificationStatusService $qualificationStatusService,
ValidatorInterface $validator,
Expand Down Expand Up @@ -182,8 +180,11 @@ public function envoi(
break;

case 'dateNaissanceOccupant':
if ('' !== $value['year'] && '' !== $value['month'] && '' !== $value['day']) {
$value = new DateTimeImmutable($value['year'].'-'.$value['month'].'-'.$value['day']);
$year = trim($value['year']);
$month = trim($value['month']);
$day = trim($value['day']);
if ('' !== $year && '' !== $month && '' !== $day) {
$value = new DateTimeImmutable($year.'-'.$month.'-'.$day);
$signalement->$method($value);
}
break;
Expand Down
10 changes: 10 additions & 0 deletions src/Controller/Security/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;

class SecurityController extends AbstractController
Expand Down Expand Up @@ -76,4 +78,12 @@ public function logout(): void
{
throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}

#[Route('/signalement/csrf-token', name: 'app_csrf_token', methods: ['GET'])]
public function generateFormSignalementCsrfToken(CsrfTokenManagerInterface $csrfTokenManager): JsonResponse
{
return $this->json([
'csrf_token' => $csrfTokenManager->getToken('new_signalement'),
]);
}
}
2 changes: 1 addition & 1 deletion src/Service/Signalement/PostalCodeHomeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function isActive(string $postalCode, ?string $inseeCode = null): bool

public function getZipCode(string $postalCode): string
{
$zipChunk = substr($postalCode, 0, 3);
$zipChunk = substr(trim($postalCode), 0, 3);

return match ($zipChunk) {
'200', '201' => self::CORSE_DU_SUD_CODE_DEPARTMENT_2A,
Expand Down
Loading

0 comments on commit fb208bd

Please sign in to comment.