Fix: Add dedicated process for withdrawal of applications by teamer
This commit is contained in:
+4
-4
@@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DeleteController extends AbstractController
|
||||
class WithdrawController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
@@ -23,8 +23,8 @@ class DeleteController extends AbstractController
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/teamer/application/delete/{uuid}', name: 'app_teamer_application_delete')]
|
||||
#[IsGranted('DELETE', subject: 'application')]
|
||||
#[Route('/teamer/application/withdraw/{uuid}', name: 'app_teamer_application_withdraw')]
|
||||
#[IsGranted('WITHDRAW', subject: 'application')]
|
||||
public function index(Application $application, Request $request): Response
|
||||
{
|
||||
/** @var User $user */
|
||||
@@ -35,7 +35,7 @@ class DeleteController extends AbstractController
|
||||
$this->entityManager->remove($application);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->logger->info('Delete application', [
|
||||
$this->logger->info('Withdraw application', [
|
||||
'teamer_id' => $teamer->getId(),
|
||||
'teamer_name' => (string) $teamer,
|
||||
'application_id' => $application->getId(),
|
||||
@@ -11,6 +11,7 @@ class ApplicationVoter extends Voter
|
||||
{
|
||||
public const VIEW = 'VIEW';
|
||||
public const DELETE = 'DELETE';
|
||||
public const WITHDRAW = 'WITHDRAW';
|
||||
public const DISPOSE = 'DISPOSE';
|
||||
public const STATUS = 'STATUS';
|
||||
|
||||
@@ -20,7 +21,7 @@ class ApplicationVoter extends Voter
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($attribute, [static::VIEW, static::DELETE, static::DISPOSE, static::STATUS]);
|
||||
return in_array($attribute, [static::VIEW, static::WITHDRAW, static::DELETE, static::DISPOSE, static::STATUS]);
|
||||
}
|
||||
|
||||
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
|
||||
@@ -30,24 +31,30 @@ class ApplicationVoter extends Voter
|
||||
|
||||
/** @var Application $application */
|
||||
$application = $subject;
|
||||
$status = $application->getStatus();
|
||||
|
||||
if ($user->hasRole('ROLE_ADMINISTRATIVE')) {
|
||||
$adminAttributes = [static::VIEW, static::DELETE, static::DISPOSE, static::STATUS];
|
||||
$teamerAttributes = [static::VIEW, static::WITHDRAW, static::DELETE, static::STATUS];
|
||||
|
||||
if ($user->hasRole('ROLE_ADMINISTRATIVE') && in_array($attribute, $adminAttributes)) {
|
||||
$assignment = $application->getAssignment();
|
||||
return match ($attribute) {
|
||||
static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $application->getStatus(),
|
||||
static::DELETE => Application::STATUS_REJECTED === $application->getStatus(),
|
||||
static::DISPOSE => Application::STATUS_REJECTED !== $application->getStatus()
|
||||
static::VIEW, static::STATUS => Application::STATUS_REJECTED !== $status,
|
||||
static::DELETE => Application::STATUS_REJECTED === $status,
|
||||
static::DISPOSE => Application::STATUS_REJECTED !== $status
|
||||
&& $assignment->getAvailableDispositions() > $assignment->getDispositions()->count(),
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
if ($user->hasRole('ROLE_TEAMER')) {
|
||||
if ($user->hasRole('ROLE_TEAMER') && in_array($attribute, $teamerAttributes)) {
|
||||
$teamer = $user->getTeamer();
|
||||
return match ($attribute) {
|
||||
static::DELETE => $user->getTeamer() === $application->getTeamer()
|
||||
&& Application::STATUS_REJECTED === $application->getStatus(),
|
||||
static::VIEW => $user->getTeamer() === $application->getTeamer()
|
||||
&& Application::STATUS_REJECTED !== $application->getStatus(),
|
||||
static::WITHDRAW => $teamer === $application->getTeamer(),
|
||||
static::DELETE => $teamer === $application->getTeamer()
|
||||
&& Application::STATUS_REJECTED === $status,
|
||||
static::VIEW => $teamer === $application->getTeamer()
|
||||
&& Application::STATUS_REJECTED !== $status,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user