feat: driver license check for teamers
closes #869bup9vf
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user