feat: driver license check for teamers

closes #869bup9vf
This commit is contained in:
Björn Fromme
2026-03-15 12:42:28 +01:00
parent ebbefa0129
commit 20da6a0afc
32 changed files with 1095 additions and 6 deletions
+1
View File
@@ -197,6 +197,7 @@
<!--! Font Awesome Pro 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path d="M24 0C10.7 0 0 10.7 0 24S10.7 48 24 48h8V67c0 40.3 16 79 44.5 107.5L158.1 256 76.5 337.5C48 366 32 404.7 32 445v19H24c-13.3 0-24 10.7-24 24s10.7 24 24 24H360c13.3 0 24-10.7 24-24s-10.7-24-24-24h-8V445c0-40.3-16-79-44.5-107.5L225.9 256l81.5-81.5C336 146 352 107.3 352 67V48h8c13.3 0 24-10.7 24-24s-10.7-24-24-24H24zM192 289.9l81.5 81.5C293 391 304 417.4 304 445v19H80V445c0-27.6 11-54 30.5-73.5L192 289.9zm0-67.9l-81.5-81.5C91 121 80 94.6 80 67V48H304V67c0 27.6-11 54-30.5 73.5L192 222.1z"/>
</symbol>
<symbol id="icon-car" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><circle cx="64" cy="176" r="24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><circle cx="192" cy="176" r="24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><line x1="88" y1="176" x2="168" y2="176" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><path d="M216,176h24a8,8,0,0,0,8-8V128a8,8,0,0,0-8-8H208L162.34,74.34A8,8,0,0,0,156.69,72H44.28a8,8,0,0,0-6.65,3.56L8,120v48a8,8,0,0,0,8,8H40" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><line x1="208" y1="120" x2="8" y2="120" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></symbol>
<symbol id="icon-flag-a" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 480"><g fill-rule="evenodd"><path fill="#fff" d="M640 480H0V0h640z"/><path fill="#ed2939" d="M640 480H0V320h640zm0-319.9H0V.1h640z"/></g></symbol>
<symbol id="icon-flag-ch" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 480"><g fill-rule="evenodd" stroke-width="1pt"><path fill="#d52b1e" d="M0 0h640v480H0z"/><g fill="#fff"><path d="M170 195h300v90H170z"/><path d="M275 90h90v300h-90z"/></g></g></symbol>
<symbol id="icon-flag-d" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 480"><path fill="#ffce00" d="M0 320h640v160H0z"/><path d="M0 0h640v160H0z"/><path fill="#d00" d="M0 160h640v160H0z"/></symbol>

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 35 KiB

+6
View File
@@ -30,6 +30,12 @@ oneup_uploader:
namer: app.upload_namer
storage:
directory: '%kernel.project_dir%/uploads/document'
driver_license:
frontend: dropzone
use_orphanage: true
namer: app.upload_namer
storage:
directory: '%kernel.project_dir%/uploads/driver_license'
chunks:
maxage: 86400
storage:
+7
View File
@@ -160,6 +160,13 @@ services:
$datevEmailRecipient: '%env(DATEV_EMAIL_RECIPIENT)%'
$datevEmailSender: '%env(DATEV_EMAIL_SENDER)%'
App\Security\RequiredCheck\RequiredTeamerCheckRegistry:
arguments:
$checks: !tagged_iterator app.required_teamer_check
App\Security\RequiredCheck\DriverLicenseRequiredCheck:
tags: [ 'app.required_teamer_check' ]
app.upload_namer:
class: App\Service\Upload\UploadNamer
public: true
+33
View File
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20260227111223 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE teamer ADD driver_license_upload_id INT DEFAULT NULL, ADD driver_license_declaration TINYINT(1) DEFAULT NULL, ADD driver_license_verified TINYINT(1) NOT NULL DEFAULT 0, ADD driver_license_status VARCHAR(64) NOT NULL DEFAULT \'none\', ADD driver_license_review_comment LONGTEXT DEFAULT NULL, ADD driver_license_reviewed_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', ADD driver_license_reviewed_by VARCHAR(8) DEFAULT NULL');
$this->addSql('ALTER TABLE teamer ADD CONSTRAINT FK_15B751AE1C882DBD FOREIGN KEY (driver_license_upload_id) REFERENCES upload (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_15B751AE1C882DBD ON teamer (driver_license_upload_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE teamer DROP FOREIGN KEY FK_15B751AE1C882DBD');
$this->addSql('DROP INDEX UNIQ_15B751AE1C882DBD ON teamer');
$this->addSql('ALTER TABLE teamer DROP driver_license_upload_id, DROP driver_license_declaration, DROP driver_license_verified, DROP driver_license_status, DROP driver_license_review_comment, DROP driver_license_reviewed_at, DROP driver_license_reviewed_by');
}
}
+4
View File
@@ -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
View File
@@ -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
+2
View File
@@ -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())));
}
}
+43
View File
@@ -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,
]);
}
}
+49
View File
@@ -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)
;
}
}
+4
View File
@@ -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,
+48
View File
@@ -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;
}
}
+28
View File
@@ -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;
}
}
+13
View File
@@ -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;
+7
View File
@@ -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();
}
+11 -1
View File
@@ -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();
@@ -2,6 +2,11 @@
Lizenzen
</h3>
<ul class="pb-4 divide-y divide-gray-200">
{% if teamer.driverLicenseVerified %}
<li class="py-2">
Führerschein
</li>
{% endif %}
{% for license in teamer.licenses %}
<li class="py-2">
<div class="flex items-center justify-between">
@@ -18,9 +23,10 @@
</div>
</div>
</li>
{% else %}
{% endfor %}
{% if not teamer.driverLicenseVerified and teamer.licenses | length == 0 %}
<li class="py-2">
-
</li>
{% endfor %}
{% endif %}
</ul>
+31
View File
@@ -121,6 +121,37 @@
</div>
</div>
<div class="bg-gray-100 border border-gray-200 rounded-md px-4 py-2">
<h2 class="flex justify-between pb-2">
<span class="font-bold text-lg">Neue Führerscheine</span>
{% if newDriverLicensesCount > 0 %}
<span>{{ newDriverLicensesCount }} neu</span>
{% endif %}
</h2>
<div class="max-h-64 overflow-y-scroll overflow-x-hidden">
<ul class="divide-y divide-gray-200">
{% for document in newDriverLicenses %}
<li class="py-2 first:pt-0 last:pb-0">
<button type="button"
class="flex items-center space-x-1 truncate"
hx-get="{{ path('app_administrative_teamer_driver_license_check', { 'uuid': document.uuid }) }}"
hx-target="body"
hx-swap="beforeend">
{{ icon('download', 'w-4 h-4 shrink-0') }}
<span>{{ document.owner.teamer.fullName(true) }}</span>
{% include '_partials/_dot.html.twig' %}
<span class="whitespace-nowrap">{{ document.createdAt|date('d.m.y') }}</span>
</button>
</li>
{% else %}
<li class="py-2 first:pt-0 last:pb-0">
-
</li>
{% endfor %}
</ul>
</div>
</div>
<div class="bg-gray-100 border border-gray-200 rounded-md px-4 py-2">
<h2 class="font-bold text-lg pb-2">
Neue Einsätze
@@ -0,0 +1,25 @@
{% extends 'htmx_modal.html.twig' %}
{% block title %}Führerschein prüfen{% endblock %}
{% block content %}
{{ form_start(form, { 'attr': { 'hx-post': app.request.uri, 'hx-target': '#htmx-modal', 'hx-swap': 'outerHTML' } }) }}
<a href="{{ path('app_common_download', { 'uuid': document.uuid, 'inline': true }) }}"
target="_blank"
class="flex justify-between items-center pb-4"
title="Dokument öffnen">
<h2 class="font-bold text-lg">
Führerschein {{ teamer }} vom {{ document.createdAt|date('d.m.Y') }}
</h2>
{{ icon('eye') }}
</a>
<div class="flex flex-col space-y-4 pb-4">
{{ form_row(form.status) }}
{{ form_row(form.comment) }}
</div>
<button type="submit" class="btn">
Aktualisieren
</button>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
@@ -94,6 +94,9 @@
</td>
<td>
<div class="flex items-center space-x-1 justify-end">
{% if teamer.driverLicenseVerified %}
{{ icon('car', 'w-5 h-5 text-green-500') }}
{% endif %}
{% if not teamer.viewed %}
<button type="button"
hx-post="{{ path('app_administrative_teamer_viewed', { 'uuid': teamer.uuid }) }}"
@@ -11,6 +11,7 @@
{{ form_row(filterForm.pickupId) }}
{{ form_row(filterForm.skiLicense) }}
{{ form_row(filterForm.snowboardLicense) }}
{{ form_row(filterForm.driverLicenseVerified) }}
{{ form_row(filterForm.noTrainings) }}
</div>
<div class="flex items-center space-x-2">
@@ -0,0 +1,65 @@
{% extends 'teamer/layout.html.twig' %}
{% block title %}Führerschein-Check{% endblock %}
{% block content %}
{% set formAttr = stimulus_controller('form-upload-guard')|stimulus_action('form-upload-guard', 'guard', 'submit') %}
{{ form_start(form, { 'attr': formAttr.toArray() }) }}
<div class="max-w-2xl">
<h1 class="text-2xl font-bold pb-2">
Führerschein-Check
</h1>
<p class="pb-6">
Bitte gib an, ob du einen Führerschein besitzt. Wenn ja, lade bitte einmalig ein Foto oder PDF deines
Führerscheins hoch.
</p>
{% if not form.vars.valid %}
<div class="border border-red-500 rounded-md p-4 text-red-500 mb-6">
{% include '_partials/_form_errors.html.twig' with { 'form': form } %}
</div>
{% endif %}
{% if teamer.driverLicenseStatus == constant('App\\Entity\\Teamer::DRIVER_LICENSE_STATUS_DENIED') %}
<div class="border border-red-500 rounded-md p-4 text-red-500 mb-6">
Dein zuletzt hochgeladener Führerschein wurde abgelehnt.
{% if teamer.driverLicenseReviewComment %}
<br>
Begründung: {{ teamer.driverLicenseReviewComment }}
{% endif %}
</div>
{% endif %}
<div class="flex flex-col space-y-4 pb-6">
{{ form_row(form.hasDriverLicense) }}
{% if teamer.driverLicenseUpload %}
<div class="text-sm">
Aktuell hochgeladen:
<a href="{{ path('app_common_download', { 'uuid': teamer.driverLicenseUpload.uuid, 'inline': true }) }}" target="_blank" class="font-bold underline">
{{ teamer.driverLicenseUpload.originalFilename }}
</a>
</div>
{% endif %}
<div>
<label class="block font-bold pb-2">
Führerschein hochladen (JPG, PNG, PDF)
</label>
{% include '_partials/_upload_collection_form.html.twig' with {
'endpoint_upload': path('_uploader_upload_driver_license'),
'upload_session_params': form.vars.upload_session_params,
'accepted_files': 'image/jpg,image/jpeg,image/png,application/pdf',
} %}
</div>
</div>
<button type="submit" class="btn" {{ stimulus_target('form-upload-guard', 'submit') }}>
Speichern
</button>
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
+21
View File
@@ -127,6 +127,27 @@
{{ form_row(form.healthInsuranceCompany) }}
{{ form_row(form.language) }}
{{ form_row(form.size) }}
<div>
<div class="font-bold pb-2">Führerschein</div>
<div class="pb-2">
{% if teamer.driverLicenseDeclaration is same as(null) %}
noch nicht angegeben
{% elseif teamer.driverLicenseDeclaration %}
{% if teamer.driverLicenseVerified %}
bestätigt
{% elseif teamer.driverLicenseStatus == constant('App\\Entity\\Teamer::DRIVER_LICENSE_STATUS_DENIED') %}
abgelehnt
{% else %}
in Prüfung
{% endif %}
{% else %}
nicht vorhanden
{% endif %}
</div>
<a href="{{ path('app_teamer_check_driver_license') }}" class="btn btn--small btn--secondary">
Führerscheinstatus bearbeiten
</a>
</div>
<div {{ stimulus_controller('form-collection', { 'prototype': _self.collectionRow(form.pickups.vars.prototype)|json_encode }) }}>
<h4 class="font-bold pb-2">
Buszustiege
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace App\Tests\Security\RequiredCheck;
use App\Entity\Upload;
use App\Model\DriverLicenseCheckDto;
use PHPUnit\Framework\TestCase;
class DriverLicenseCheckDtoTest extends TestCase
{
public function testKeepsNewStatus(): void
{
$upload = (new Upload())
->setType(Upload::TYPE_DRIVER_LICENSE)
->setStatus(Upload::STATUS_NEW)
;
$dto = new DriverLicenseCheckDto($upload);
$this->assertSame(Upload::STATUS_NEW, $dto->getStatus());
}
}
@@ -0,0 +1,108 @@
<?php
declare(strict_types=1);
namespace App\Tests\Security\RequiredCheck;
use App\Entity\Teamer;
use App\Entity\Upload;
use App\Entity\User;
use App\Security\RequiredCheck\DriverLicenseRequiredCheck;
use PHPUnit\Framework\TestCase;
class DriverLicenseRequiredCheckTest extends TestCase
{
private DriverLicenseRequiredCheck $check;
protected function setUp(): void
{
$this->check = new DriverLicenseRequiredCheck();
}
public function testAppliesToMixedRoleUsersWithTeamerRole(): void
{
$user = $this->createTeamerUser();
$user->setRoles(['ROLE_ADMIN', 'ROLE_TEAMER']);
$this->assertTrue($this->check->appliesTo($user));
}
public function testIsNotSatisfiedWhenDeclarationIsMissing(): void
{
$user = $this->createTeamerUser();
$this->assertFalse($this->check->isSatisfied($user));
}
public function testIsSatisfiedWhenTeamerHasNoDriverLicense(): void
{
$user = $this->createTeamerUser();
$user->getTeamer()?->setDriverLicenseDeclaration(false);
$this->assertTrue($this->check->isSatisfied($user));
}
public function testIsNotSatisfiedWhenRejected(): void
{
$user = $this->createTeamerUser();
$teamer = $user->getTeamer();
$upload = (new Upload())
->setType(Upload::TYPE_DRIVER_LICENSE)
->setStatus(Upload::STATUS_REJECTED)
;
$teamer
?->setDriverLicenseDeclaration(true)
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_DENIED)
->setDriverLicenseUpload($upload)
;
$this->assertFalse($this->check->isSatisfied($user));
}
public function testIsSatisfiedWhenSubmittedForReview(): void
{
$user = $this->createTeamerUser();
$teamer = $user->getTeamer();
$upload = (new Upload())
->setType(Upload::TYPE_DRIVER_LICENSE)
->setStatus(Upload::STATUS_NEW)
;
$teamer
?->setDriverLicenseDeclaration(true)
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_PENDING_REVIEW)
->setDriverLicenseUpload($upload)
;
$this->assertTrue($this->check->isSatisfied($user));
}
public function testIsSatisfiedWhenApprovedWithoutUpload(): void
{
$user = $this->createTeamerUser();
$teamer = $user->getTeamer();
$teamer
?->setDriverLicenseDeclaration(true)
->setDriverLicenseVerified(true)
->setDriverLicenseStatus(Teamer::DRIVER_LICENSE_STATUS_APPROVED)
->setDriverLicenseUpload(null)
;
$this->assertTrue($this->check->isSatisfied($user));
}
private function createTeamerUser(): User
{
$teamer = new Teamer();
return (new User())
->setRoles(['ROLE_TEAMER'])
->setTeamer($teamer)
;
}
}
+1
View File
@@ -19,6 +19,7 @@ label:
contract: Honorarvertrag
certificate: Lizenznachweis
photo: Foto
driver_license: Führerschein
status:
new: neu
pending: in Bearbeitung