feat: driver license check for teamers
closes #869bup9vf
This commit is contained in:
@@ -44,6 +44,8 @@ class IndexController extends AbstractController
|
||||
$newInvoices = $uploadRepository->getNewByType(Upload::TYPE_INVOICE);
|
||||
$newInvoicesCount = $uploadRepository->getCountByStatusAndType(Upload::STATUS_NEW, Upload::TYPE_INVOICE);
|
||||
$pendingInvoicesCount = $uploadRepository->getCountByStatusAndType(Upload::STATUS_PENDING, Upload::TYPE_INVOICE);
|
||||
$newDriverLicenses = $uploadRepository->getNewByType(Upload::TYPE_DRIVER_LICENSE);
|
||||
$newDriverLicensesCount = $uploadRepository->getCountByStatusAndType(Upload::STATUS_NEW, Upload::TYPE_DRIVER_LICENSE);
|
||||
|
||||
$dispositionRepository = $this->entityManager->getRepository(Disposition::class);
|
||||
$overdueContracts = $dispositionRepository->findOverdueContracts();
|
||||
@@ -64,6 +66,8 @@ class IndexController extends AbstractController
|
||||
'newInvoices' => $newInvoices,
|
||||
'newInvoicesCount' => $newInvoicesCount,
|
||||
'pendingInvoicesCount' => $pendingInvoicesCount,
|
||||
'newDriverLicenses' => $newDriverLicenses,
|
||||
'newDriverLicensesCount' => $newDriverLicensesCount,
|
||||
'overdueContracts' => $overdueContracts,
|
||||
'newDispositions' => $newDispositions,
|
||||
'overdueFeedbacks' => $overdueFeedbacks,
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\Teamer\DriverLicense;
|
||||
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Form\DriverLicenseCheckType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Model\DriverLicenseCheckDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class CheckController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/teamer/driver-license/check/{uuid}', name: 'app_administrative_teamer_driver_license_check')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
#[IsGranted('CHECK', subject: 'document')]
|
||||
public function index(Upload $document, Request $request): Response
|
||||
{
|
||||
if (Upload::TYPE_DRIVER_LICENSE !== $document->getType()) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$teamer = $document->getOwner()?->getTeamer();
|
||||
if (false === $teamer instanceof Teamer) {
|
||||
throw $this->createNotFoundException('Teamer not found for upload');
|
||||
}
|
||||
|
||||
$formData = new DriverLicenseCheckDto($document);
|
||||
$form = $this->createForm(DriverLicenseCheckType::class, $formData);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
$status = $formData->getStatus();
|
||||
if (null === $status) {
|
||||
throw $this->createNotFoundException('Status missing');
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$document
|
||||
->setStatus($status)
|
||||
->setComment($formData->getComment())
|
||||
->setApprovedAt(Upload::STATUS_CHECKED === $status ? new \DateTimeImmutable() : null)
|
||||
->setApprovedBy(Upload::STATUS_CHECKED === $status ? $user->getInitials() : null)
|
||||
;
|
||||
|
||||
$teamer
|
||||
->setDriverLicenseDeclaration(true)
|
||||
->setDriverLicenseReviewComment($formData->getComment())
|
||||
->setDriverLicenseReviewedAt(new \DateTimeImmutable())
|
||||
->setDriverLicenseReviewedBy($user->getInitials())
|
||||
;
|
||||
|
||||
if (Upload::STATUS_CHECKED === $status) {
|
||||
$teamer
|
||||
->setDriverLicenseVerified(true)
|
||||
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_APPROVED)
|
||||
->setDriverLicenseUpload(null)
|
||||
;
|
||||
$this->entityManager->remove($document);
|
||||
$this->addFlash('success', 'Der Führerschein wurde bestätigt');
|
||||
} elseif (Upload::STATUS_REJECTED === $status) {
|
||||
$teamer
|
||||
->setDriverLicenseVerified(false)
|
||||
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_DENIED)
|
||||
;
|
||||
$this->addFlash('success', 'Der Führerschein wurde abgelehnt');
|
||||
} else {
|
||||
$teamer
|
||||
->setDriverLicenseVerified(false)
|
||||
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_PENDING_REVIEW)
|
||||
;
|
||||
$this->addFlash('success', 'Der Führerscheinstatus wurde aktualisiert');
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info('Update driver license check', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_admin_index'));
|
||||
}
|
||||
|
||||
return $this->render('administrative/teamer/driver_license/modal_check.html.twig', [
|
||||
'document' => $document,
|
||||
'teamer' => $teamer,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Teamer\Check;
|
||||
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Form\DriverLicenseDeclarationType;
|
||||
use App\Model\DriverLicenseDeclarationDto;
|
||||
use App\Model\UploadSessionDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DriverLicenseController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/teamer/check/driver-license', name: 'app_teamer_check_driver_license')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
if (null === $teamer) {
|
||||
$teamer = new Teamer();
|
||||
$user->setTeamer($teamer);
|
||||
$this->entityManager->persist($teamer);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
if (true === $request->isMethod('POST') && 0 < $uploadSession->getCount()) {
|
||||
$this->updateDriverLicenseUpload($user, $teamer, $uploadSession);
|
||||
}
|
||||
|
||||
$formData = new DriverLicenseDeclarationDto($teamer->getDriverLicenseDeclaration());
|
||||
$form = $this->createForm(DriverLicenseDeclarationType::class, $formData, ['upload_session' => $uploadSession]);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if (true === $form->isSubmitted() && true === $form->isValid()) {
|
||||
if (false === $formData->hasDriverLicense()) {
|
||||
$this->handleNoDriverLicense($teamer);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_teamer_index');
|
||||
}
|
||||
|
||||
if (0 < $form->getErrors(true)->count()) {
|
||||
// Continue rendering form with errors.
|
||||
} elseif (null === $teamer->getDriverLicenseUpload()) {
|
||||
$form->addError(new FormError('Bitte lade ein Foto oder PDF deines Führerscheins hoch.'));
|
||||
} elseif (
|
||||
Teamer::DRIVER_LICENSE_STATUS_DENIED === $teamer->getDriverLicenseStatus()
|
||||
&& Upload::STATUS_REJECTED === $teamer->getDriverLicenseUpload()->getStatus()
|
||||
) {
|
||||
$form->addError(new FormError('Bitte lade einen neuen Führerschein hoch, damit wir ihn erneut prüfen können.'));
|
||||
} else {
|
||||
$teamer
|
||||
->setDriverLicenseDeclaration(true)
|
||||
->setDriverLicenseVerified(false)
|
||||
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_PENDING_REVIEW)
|
||||
->setDriverLicenseReviewComment(null)
|
||||
->setDriverLicenseReviewedAt(null)
|
||||
->setDriverLicenseReviewedBy(null)
|
||||
;
|
||||
|
||||
$upload = $teamer->getDriverLicenseUpload();
|
||||
$upload
|
||||
->setStatus(Upload::STATUS_NEW)
|
||||
->setComment(null)
|
||||
->setApprovedAt(null)
|
||||
->setApprovedBy(null)
|
||||
;
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Dein Führerschein wurde hochgeladen und wird geprüft.');
|
||||
$this->logger->info('Submit driver license for review', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_teamer_index');
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('teamer/check/driver_license.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'teamer' => $teamer,
|
||||
]);
|
||||
}
|
||||
|
||||
private function handleNoDriverLicense(Teamer $teamer): void
|
||||
{
|
||||
if (null !== $existingUpload = $teamer->getDriverLicenseUpload()) {
|
||||
$this->entityManager->remove($existingUpload);
|
||||
}
|
||||
|
||||
$teamer
|
||||
->setDriverLicenseUpload(null)
|
||||
->setDriverLicenseDeclaration(false)
|
||||
->setDriverLicenseVerified(false)
|
||||
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_NONE)
|
||||
->setDriverLicenseReviewComment(null)
|
||||
->setDriverLicenseReviewedAt(null)
|
||||
->setDriverLicenseReviewedBy(null)
|
||||
;
|
||||
|
||||
$this->addFlash('success', 'Deine Angabe wurde gespeichert.');
|
||||
$this->logger->info('Set no driver license', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
]);
|
||||
}
|
||||
|
||||
private function updateDriverLicenseUpload(User $user, Teamer $teamer, UploadSessionDto $uploadSession): void
|
||||
{
|
||||
if (null !== $existingUpload = $teamer->getDriverLicenseUpload()) {
|
||||
$this->entityManager->remove($existingUpload);
|
||||
}
|
||||
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_DRIVER_LICENSE);
|
||||
$upload->setStatus(Upload::STATUS_NEW);
|
||||
|
||||
$teamer->setDriverLicenseUpload($upload);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_DRIVER_LICENSE, $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
|
||||
$this->addFlash('success', 'Der Führerschein wurde hochgeladen.');
|
||||
}
|
||||
}
|
||||
+111
-1
@@ -23,6 +23,11 @@ class Teamer implements TimestampableEntityInterface
|
||||
public const STATUS_NEW = 'new';
|
||||
public const STATUS_EXISTING = 'existing';
|
||||
|
||||
public const DRIVER_LICENSE_STATUS_NONE = 'none';
|
||||
public const DRIVER_LICENSE_STATUS_PENDING_REVIEW = 'pending_review';
|
||||
public const DRIVER_LICENSE_STATUS_APPROVED = 'approved';
|
||||
public const DRIVER_LICENSE_STATUS_DENIED = 'denied';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
@@ -140,6 +145,27 @@ class Teamer implements TimestampableEntityInterface
|
||||
#[ORM\Column]
|
||||
private bool $allowOverlappingApplications = false;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $driverLicenseDeclaration = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private bool $driverLicenseVerified = false;
|
||||
|
||||
#[ORM\Column(length: 64)]
|
||||
private string $driverLicenseStatus = self::DRIVER_LICENSE_STATUS_NONE;
|
||||
|
||||
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
|
||||
private ?Upload $driverLicenseUpload = null;
|
||||
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $driverLicenseReviewComment = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
|
||||
private ?\DateTimeImmutable $driverLicenseReviewedAt = null;
|
||||
|
||||
#[ORM\Column(length: 8, nullable: true)]
|
||||
private ?string $driverLicenseReviewedBy = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->uuid = Uuid::v4();
|
||||
@@ -750,7 +776,91 @@ class Teamer implements TimestampableEntityInterface
|
||||
|
||||
public function hasPickup(int $pickupId): bool
|
||||
{
|
||||
return in_array($pickupId, $this->getPickups());
|
||||
return true === in_array($pickupId, $this->getPickups(), true);
|
||||
}
|
||||
|
||||
public function getDriverLicenseDeclaration(): ?bool
|
||||
{
|
||||
return $this->driverLicenseDeclaration;
|
||||
}
|
||||
|
||||
public function setDriverLicenseDeclaration(?bool $driverLicenseDeclaration): static
|
||||
{
|
||||
$this->driverLicenseDeclaration = $driverLicenseDeclaration;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isDriverLicenseVerified(): bool
|
||||
{
|
||||
return $this->driverLicenseVerified;
|
||||
}
|
||||
|
||||
public function setDriverLicenseVerified(bool $driverLicenseVerified): static
|
||||
{
|
||||
$this->driverLicenseVerified = $driverLicenseVerified;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDriverLicenseStatus(): string
|
||||
{
|
||||
return $this->driverLicenseStatus;
|
||||
}
|
||||
|
||||
public function setDriverLicenseStatus(string $driverLicenseStatus): static
|
||||
{
|
||||
$this->driverLicenseStatus = $driverLicenseStatus;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDriverLicenseUpload(): ?Upload
|
||||
{
|
||||
return $this->driverLicenseUpload;
|
||||
}
|
||||
|
||||
public function setDriverLicenseUpload(?Upload $driverLicenseUpload): static
|
||||
{
|
||||
$this->driverLicenseUpload = $driverLicenseUpload;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDriverLicenseReviewComment(): ?string
|
||||
{
|
||||
return $this->driverLicenseReviewComment;
|
||||
}
|
||||
|
||||
public function setDriverLicenseReviewComment(?string $driverLicenseReviewComment): static
|
||||
{
|
||||
$this->driverLicenseReviewComment = $driverLicenseReviewComment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDriverLicenseReviewedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->driverLicenseReviewedAt;
|
||||
}
|
||||
|
||||
public function setDriverLicenseReviewedAt(?\DateTimeImmutable $driverLicenseReviewedAt): static
|
||||
{
|
||||
$this->driverLicenseReviewedAt = $driverLicenseReviewedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDriverLicenseReviewedBy(): ?string
|
||||
{
|
||||
return $this->driverLicenseReviewedBy;
|
||||
}
|
||||
|
||||
public function setDriverLicenseReviewedBy(?string $driverLicenseReviewedBy): static
|
||||
{
|
||||
$this->driverLicenseReviewedBy = $driverLicenseReviewedBy;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLanguage(): ?string
|
||||
|
||||
@@ -21,6 +21,7 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
public const TYPE_CONTRACT = 'contract';
|
||||
public const TYPE_INVOICE = 'invoice';
|
||||
public const TYPE_DOCUMENT = 'document';
|
||||
public const TYPE_DRIVER_LICENSE = 'driver_license';
|
||||
|
||||
public const STATUS_NEW = 'new';
|
||||
public const STATUS_PENDING = 'pending';
|
||||
@@ -133,6 +134,7 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
self::TYPE_CONTRACT => 'Honorarvertrag',
|
||||
self::TYPE_INVOICE => 'Honorarnote',
|
||||
self::TYPE_DOCUMENT => 'Info',
|
||||
self::TYPE_DRIVER_LICENSE => 'Führerschein',
|
||||
default => 'Dokument',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Security\RequiredCheck\RequiredTeamerCheckRegistry;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
class RequiredTeamerCheckSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Security $security,
|
||||
private readonly UrlGeneratorInterface $urlGenerator,
|
||||
private readonly RequiredTeamerCheckRegistry $requiredTeamerCheckRegistry,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
KernelEvents::REQUEST => ['onKernelRequest', 5],
|
||||
];
|
||||
}
|
||||
|
||||
public function onKernelRequest(RequestEvent $event): void
|
||||
{
|
||||
if (false === $event->isMainRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request = $event->getRequest();
|
||||
$route = (string) $request->attributes->get('_route');
|
||||
|
||||
if ('' === $route || false === str_starts_with($route, 'app_teamer_')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $this->security->getUser();
|
||||
|
||||
if (false === $user instanceof User || false === $this->security->isGranted('ROLE_TEAMER')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$check = $this->requiredTeamerCheckRegistry->getFirstUnresolvedCheck($user);
|
||||
|
||||
if (null === $check) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (true === in_array($route, [
|
||||
$check->getRouteName(),
|
||||
'app_upload_delete',
|
||||
'app_security_logout',
|
||||
], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$event->setResponse(new RedirectResponse($this->urlGenerator->generate($check->getRouteName())));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Model\DriverLicenseCheckDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DriverLicenseCheckType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('status', ChoiceType::class, [
|
||||
'label' => 'neuer Status',
|
||||
'choices' => [
|
||||
'in Bearbeitung' => Upload::STATUS_NEW,
|
||||
'bestätigt' => Upload::STATUS_CHECKED,
|
||||
'abgelehnt' => Upload::STATUS_REJECTED,
|
||||
],
|
||||
])
|
||||
->add('comment', TextareaType::class, [
|
||||
'label' => 'Kommentar/Begründung',
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'rows' => 3,
|
||||
],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => DriverLicenseCheckDto::class,
|
||||
'anti_xss' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Model\DriverLicenseDeclarationDto;
|
||||
use App\Model\UploadSessionDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DriverLicenseDeclarationType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->add('hasDriverLicense', ChoiceType::class, [
|
||||
'label' => 'Besitzt du einen gültigen Führerschein?',
|
||||
'choices' => [
|
||||
'Ja' => true,
|
||||
'Nein' => false,
|
||||
],
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
/** @var UploadSessionDto $uploadSession */
|
||||
$uploadSession = $options['upload_session'];
|
||||
|
||||
$view->vars['upload_session_params'] = [
|
||||
UploadHandler::SESSION_KEY => $uploadSession->getUid(),
|
||||
];
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => DriverLicenseDeclarationDto::class,
|
||||
])
|
||||
->setRequired(['upload_session'])
|
||||
->setAllowedTypes('upload_session', UploadSessionDto::class)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,10 @@ class TeamerFilterType extends AbstractType
|
||||
'label' => 'Snowboardlehrer:innen-Lizenz',
|
||||
'required' => false,
|
||||
])
|
||||
->add('driverLicenseVerified', CheckboxType::class, [
|
||||
'label' => 'Führerschein bestätigt',
|
||||
'required' => false,
|
||||
])
|
||||
->add('jobProfiles', MultiselectEntityType::class, [
|
||||
'label' => 'Job-Profile',
|
||||
'class' => JobProfile::class,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Entity\Upload;
|
||||
|
||||
class DriverLicenseCheckDto
|
||||
{
|
||||
private Upload $upload;
|
||||
private ?string $status;
|
||||
private ?string $comment;
|
||||
|
||||
public function __construct(Upload $upload)
|
||||
{
|
||||
$this->upload = $upload;
|
||||
$this->status = $upload->getStatus();
|
||||
$this->comment = $upload->getComment();
|
||||
}
|
||||
|
||||
public function getUpload(): Upload
|
||||
{
|
||||
return $this->upload;
|
||||
}
|
||||
|
||||
public function getStatus(): ?string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(?string $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
public function setComment(?string $comment): static
|
||||
{
|
||||
$this->comment = $comment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class DriverLicenseDeclarationDto
|
||||
{
|
||||
#[Assert\NotNull(message: 'Bitte gib an, ob du einen Führerschein hast.')]
|
||||
private ?bool $hasDriverLicense = null;
|
||||
|
||||
public function __construct(?bool $hasDriverLicense = null)
|
||||
{
|
||||
$this->hasDriverLicense = $hasDriverLicense;
|
||||
}
|
||||
|
||||
public function hasDriverLicense(): ?bool
|
||||
{
|
||||
return $this->hasDriverLicense;
|
||||
}
|
||||
|
||||
public function setHasDriverLicense(?bool $hasDriverLicense): static
|
||||
{
|
||||
$this->hasDriverLicense = $hasDriverLicense;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ class TeamerFilterDto extends AbstractFilterDto
|
||||
protected string $pickupId = '';
|
||||
protected bool $skiLicense = false;
|
||||
protected bool $snowboardLicense = false;
|
||||
protected bool $driverLicenseVerified = false;
|
||||
protected bool $noTrainings = false;
|
||||
|
||||
public function getName(): ?string
|
||||
@@ -89,6 +90,18 @@ class TeamerFilterDto extends AbstractFilterDto
|
||||
return $this->noTrainings;
|
||||
}
|
||||
|
||||
public function hasDriverLicenseVerified(): bool
|
||||
{
|
||||
return $this->driverLicenseVerified;
|
||||
}
|
||||
|
||||
public function setDriverLicenseVerified(bool $driverLicenseVerified): static
|
||||
{
|
||||
$this->driverLicenseVerified = $driverLicenseVerified;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNoTrainings(bool $noTrainings): void
|
||||
{
|
||||
$this->noTrainings = $noTrainings;
|
||||
|
||||
@@ -97,6 +97,13 @@ class TeamerRepository extends ServiceEntityRepository
|
||||
;
|
||||
}
|
||||
|
||||
if (true === $filterDto->hasDriverLicenseVerified()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq('teamer.driverLicenseVerified', ':driverLicenseVerified'))
|
||||
->setParameter('driverLicenseVerified', true)
|
||||
;
|
||||
}
|
||||
|
||||
return $qb->getQuery();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\BusProNet\UserDataHandler;
|
||||
use App\Entity\User;
|
||||
use App\Security\RequiredCheck\RequiredTeamerCheckRegistry;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
@@ -31,6 +32,7 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly UserDataHandler $userDataHandler,
|
||||
private readonly RequiredTeamerCheckRegistry $requiredTeamerCheckRegistry,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -91,7 +93,15 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$url = $this->urlGenerator->generate($user->getDefaultRoute());
|
||||
$route = $user->getDefaultRoute();
|
||||
if ('app_teamer_index' === $route) {
|
||||
$check = $this->requiredTeamerCheckRegistry->getFirstUnresolvedCheck($user);
|
||||
if (null !== $check) {
|
||||
$route = $check->getRouteName();
|
||||
}
|
||||
}
|
||||
|
||||
$url = $this->urlGenerator->generate($route);
|
||||
|
||||
return new RedirectResponse($url);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security\RequiredCheck;
|
||||
|
||||
use App\Entity\Teamer;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
|
||||
class DriverLicenseRequiredCheck implements RequiredTeamerCheckInterface
|
||||
{
|
||||
public function getCode(): string
|
||||
{
|
||||
return 'driver_license';
|
||||
}
|
||||
|
||||
public function appliesTo(User $user): bool
|
||||
{
|
||||
return true === $user->hasRole('ROLE_TEAMER');
|
||||
}
|
||||
|
||||
public function isSatisfied(User $user): bool
|
||||
{
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
if (null === $teamer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$declaration = $teamer->getDriverLicenseDeclaration();
|
||||
|
||||
if (null === $declaration) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (false === $declaration) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (true === $teamer->isDriverLicenseVerified()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Teamer::DRIVER_LICENSE_STATUS_APPROVED === $teamer->getDriverLicenseStatus()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$upload = $teamer->getDriverLicenseUpload();
|
||||
|
||||
if (null === $upload) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Upload::TYPE_DRIVER_LICENSE !== $upload->getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Teamer::DRIVER_LICENSE_STATUS_DENIED === $teamer->getDriverLicenseStatus()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Upload::STATUS_REJECTED === $upload->getStatus()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRouteName(): string
|
||||
{
|
||||
return 'app_teamer_check_driver_license';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security\RequiredCheck;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
interface RequiredTeamerCheckInterface
|
||||
{
|
||||
public function getCode(): string;
|
||||
|
||||
public function appliesTo(User $user): bool;
|
||||
|
||||
public function isSatisfied(User $user): bool;
|
||||
|
||||
public function getRouteName(): string;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Security\RequiredCheck;
|
||||
|
||||
use App\Entity\User;
|
||||
|
||||
class RequiredTeamerCheckRegistry
|
||||
{
|
||||
/**
|
||||
* @param iterable<RequiredTeamerCheckInterface> $checks
|
||||
*/
|
||||
public function __construct(private readonly iterable $checks)
|
||||
{
|
||||
}
|
||||
|
||||
public function getFirstUnresolvedCheck(User $user): ?RequiredTeamerCheckInterface
|
||||
{
|
||||
foreach ($this->checks as $check) {
|
||||
if (false === $check->appliesTo($user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false === $check->isSatisfied($user)) {
|
||||
return $check;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ class TeamerFilterHandler extends AbstractFilterHandler
|
||||
->setPickupId($data['pickup_id'])
|
||||
->setSkiLicense($data['ski_license'])
|
||||
->setSnowboardLicense($data['snowboard_license'])
|
||||
->setDriverLicenseVerified($data['driver_license_verified'])
|
||||
->setNoTrainings($data['no_trainings'])
|
||||
;
|
||||
|
||||
@@ -49,6 +50,7 @@ class TeamerFilterHandler extends AbstractFilterHandler
|
||||
'pickup_id' => $filterDto->getPickupId(),
|
||||
'ski_license' => $filterDto->hasSkiLicense(),
|
||||
'snowboard_license' => $filterDto->hasSnowboardLicense(),
|
||||
'driver_license_verified' => $filterDto->hasDriverLicenseVerified(),
|
||||
'no_trainings' => $filterDto->hasNoTrainings(),
|
||||
'job_profiles' => array_map(function (JobProfile $jobProfile) {
|
||||
return $jobProfile->getId();
|
||||
|
||||
Reference in New Issue
Block a user